From 41a7f7a585b0c739e8c855d0d98e1f946f9bb9f2 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Fri, 20 Oct 2023 10:55:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=B8=A6=E7=94=B5=E8=B7=AF=E7=9A=84?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entity/signal.go | 14 ++++++++------ entity/signal_2xh1.go | 2 -- entity/signal_3xh1.go | 2 -- entity/signal_3xh2.go | 2 -- entity/signal_3xh3.go | 2 -- entity/signal_3xh4.go | 2 -- entity/signal_dcxh.go | 2 -- entity/signal_jckxh.go | 2 -- entity/signal_jdxh.go | 2 -- 9 files changed, 8 insertions(+), 22 deletions(-) diff --git a/entity/signal.go b/entity/signal.go index 55683e3..8ac6d80 100644 --- a/entity/signal.go +++ b/entity/signal.go @@ -5,6 +5,7 @@ import ( "joylink.club/ecs" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/consts" + "joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository/model/proto" "log/slog" ) @@ -15,7 +16,7 @@ func LoadSignals(w ecs.World) error { signals := data.Repo.SignalList() for _, signal := range signals { groups := signal.RelayGroups() - signalEntry := newSignalEntity(w, signal.Id(), data) + signalEntry := newSignalEntity(w, signal, data) if len(groups) == 1 { //带电路的信号机,有且只有一个组合类型,组合类型与电路有关 group := groups[0] elecs := group.Components() @@ -56,20 +57,21 @@ func LoadSignals(w ecs.World) error { default: slog.Warn(fmt.Sprintf("id=[%s]的信号机,无效组合类型[%s]", signal.Id(), group.Code())) } - } else { //不带电路的信号机 - signalEntry.AddComponent(component.SignalLightsType) - component.SignalLightsType.Set(signalEntry, newSignalLightsByModel(w, signal.Model())) + } else { + slog.Debug(fmt.Sprintf("id=[%s]的信号机,没有组合类型或组合类型个数不为1", signal.Id())) } } return nil } // 新建信号机实体 -func newSignalEntity(w ecs.World, uid string, worldData *component.WorldData) *ecs.Entry { +func newSignalEntity(w ecs.World, signal *repository.Signal, worldData *component.WorldData) *ecs.Entry { + uid := signal.Id() entry, ok := worldData.EntityMap[uid] if !ok { - entry = w.Entry(w.Create(component.UidType, component.SignalTag)) + entry = w.Entry(w.Create(component.UidType, component.SignalTag, component.SignalLightsType)) component.UidType.SetValue(entry, component.Uid{Id: uid}) + component.SignalLightsType.Set(entry, newSignalLightsByModel(w, signal.Model())) worldData.EntityMap[uid] = entry } return entry diff --git a/entity/signal_2xh1.go b/entity/signal_2xh1.go index 37c57c4..19899a3 100644 --- a/entity/signal_2xh1.go +++ b/entity/signal_2xh1.go @@ -14,7 +14,6 @@ func loadSignal2xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent signalEntry.AddComponent(component.Signal2XH1ElectronicType) signalEntry.AddComponent(component.Signal2XH1LsqType) signalEntry.AddComponent(component.Signal2XH1LscType) - signalEntry.AddComponent(component.SignalLightsType) // elecState := &component.Signal2XH1Electronic{} for _, elec := range elecs { @@ -33,7 +32,6 @@ func loadSignal2xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent component.Signal2XH1ElectronicType.Set(signalEntry, elecState) component.Signal2XH1LsqType.Set(signalEntry, &component.Signal2XH1Lsq{}) component.Signal2XH1LscType.Set(signalEntry, &component.Signal2XH1Lsc{}) - component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag)) //校验 if elecState.Z2XH1_DDJ == nil { return fmt.Errorf("id=[%s]的信号机2xh1,缺少元件DDJ", signal.Id()) diff --git a/entity/signal_3xh1.go b/entity/signal_3xh1.go index ce4fb0c..b7c8c7a 100644 --- a/entity/signal_3xh1.go +++ b/entity/signal_3xh1.go @@ -14,7 +14,6 @@ func loadSignal3xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent signalEntry.AddComponent(component.Signal3XH1ElectronicType) signalEntry.AddComponent(component.Signal3XH1LsqType) signalEntry.AddComponent(component.Signal3XH1LscType) - signalEntry.AddComponent(component.SignalLightsType) // elecState := &component.Signal3XH1Electronic{} for _, elec := range elecs { @@ -39,7 +38,6 @@ func loadSignal3xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent component.Signal3XH1ElectronicType.Set(signalEntry, elecState) component.Signal3XH1LsqType.Set(signalEntry, &component.Signal3XH1Lsq{}) component.Signal3XH1LscType.Set(signalEntry, &component.Signal3XH1Lsc{}) - component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag)) //校验 if elecState.Z3XH1_DDJ == nil { return fmt.Errorf("id=[%s]的信号机3xh1,缺少元件DDJ", signal.Id()) diff --git a/entity/signal_3xh2.go b/entity/signal_3xh2.go index 23cafb9..8f8ce1e 100644 --- a/entity/signal_3xh2.go +++ b/entity/signal_3xh2.go @@ -14,7 +14,6 @@ func loadSignal3xh2(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent signalEntry.AddComponent(component.Signal3XH2ElectronicType) signalEntry.AddComponent(component.Signal3XH2LsqType) signalEntry.AddComponent(component.Signal3XH2LscType) - signalEntry.AddComponent(component.SignalLightsType) // elecState := &component.Signal3XH2Electronic{} for _, elec := range elecs { @@ -37,7 +36,6 @@ func loadSignal3xh2(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent component.Signal3XH2ElectronicType.Set(signalEntry, elecState) component.Signal3XH2LsqType.Set(signalEntry, &component.Signal3XH2Lsq{}) component.Signal3XH2LscType.Set(signalEntry, &component.Signal3XH2Lsc{}) - component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag)) //校验 if elecState.Z3XH2_DDJ == nil { return fmt.Errorf("id=[%s]的信号机3xh2,缺少元件DDJ", signal.Id()) diff --git a/entity/signal_3xh3.go b/entity/signal_3xh3.go index 3f28f69..1268412 100644 --- a/entity/signal_3xh3.go +++ b/entity/signal_3xh3.go @@ -14,7 +14,6 @@ func loadSignal3xh3(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent signalEntry.AddComponent(component.Signal3XH3ElectronicType) signalEntry.AddComponent(component.Signal3XH3LsqType) signalEntry.AddComponent(component.Signal3XH3LscType) - signalEntry.AddComponent(component.SignalLightsType) // elecState := &component.Signal3XH3Electronic{} for _, elec := range elecs { @@ -37,7 +36,6 @@ func loadSignal3xh3(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent component.Signal3XH3ElectronicType.Set(signalEntry, elecState) component.Signal3XH3LsqType.Set(signalEntry, &component.Signal3XH3Lsq{}) component.Signal3XH3LscType.Set(signalEntry, &component.Signal3XH3Lsc{}) - component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag)) //校验 if elecState.Z3XH3_DDJ == nil { return fmt.Errorf("id=[%s]的信号机3xh3,缺少元件DDJ", signal.Id()) diff --git a/entity/signal_3xh4.go b/entity/signal_3xh4.go index 64481a1..b3f4408 100644 --- a/entity/signal_3xh4.go +++ b/entity/signal_3xh4.go @@ -14,7 +14,6 @@ func loadSignal3xh4(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent signalEntry.AddComponent(component.Signal3XH4ElectronicType) signalEntry.AddComponent(component.Signal3XH4LsqType) signalEntry.AddComponent(component.Signal3XH4LscType) - signalEntry.AddComponent(component.SignalLightsType) // elecState := &component.Signal3XH4Electronic{} for _, elec := range elecs { @@ -35,7 +34,6 @@ func loadSignal3xh4(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent component.Signal3XH4ElectronicType.Set(signalEntry, elecState) component.Signal3XH4LsqType.Set(signalEntry, &component.Signal3XH4Lsq{}) component.Signal3XH4LscType.Set(signalEntry, &component.Signal3XH4Lsc{}) - component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag)) //校验 if elecState.Z3XH4_DDJ == nil { return fmt.Errorf("id=[%s]的信号机3xh4,缺少元件DDJ", signal.Id()) diff --git a/entity/signal_dcxh.go b/entity/signal_dcxh.go index c668cb3..30d9d53 100644 --- a/entity/signal_dcxh.go +++ b/entity/signal_dcxh.go @@ -14,7 +14,6 @@ func loadSignalDcxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent signalEntry.AddComponent(component.SignalDCXHElectronicType) signalEntry.AddComponent(component.SignalDCXHLsqType) signalEntry.AddComponent(component.SignalDCXHLscType) - signalEntry.AddComponent(component.SignalLightsType) // elecState := &component.SignalDCXHElectronic{} for _, elec := range elecs { @@ -31,7 +30,6 @@ func loadSignalDcxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent component.SignalDCXHElectronicType.Set(signalEntry, elecState) component.SignalDCXHLsqType.Set(signalEntry, &component.SignalDCXHLsq{}) component.SignalDCXHLscType.Set(signalEntry, &component.SignalDCXHLsc{}) - component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.AdTag, component.BdTag)) //校验 if elecState.DCXH_DJ == nil { return fmt.Errorf("id=[%s]的信号机DCXH,缺少元件DJ", signal.Id()) diff --git a/entity/signal_jckxh.go b/entity/signal_jckxh.go index 98f5899..9628ccc 100644 --- a/entity/signal_jckxh.go +++ b/entity/signal_jckxh.go @@ -14,7 +14,6 @@ func loadSignalJckxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.En signalEntry.AddComponent(component.SignalJCKXHElectronicType) signalEntry.AddComponent(component.SignalJCKXHLsqType) signalEntry.AddComponent(component.SignalJCKXHLscType) - signalEntry.AddComponent(component.SignalLightsType) // elecState := &component.SignalJCKXHElectronic{} for _, elec := range elecs { @@ -33,7 +32,6 @@ func loadSignalJckxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.En component.SignalJCKXHElectronicType.Set(signalEntry, elecState) component.SignalJCKXHLsqType.Set(signalEntry, &component.SignalJCKXHLsq{}) component.SignalJCKXHLscType.Set(signalEntry, &component.SignalJCKXHLsc{}) - component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.BdTag, component.UdTag)) //校验 if elecState.JCKXH_DJ == nil { return fmt.Errorf("id=[%s]的信号机JCKXH,缺少元件DJ", signal.Id()) diff --git a/entity/signal_jdxh.go b/entity/signal_jdxh.go index 429434c..3c7222f 100644 --- a/entity/signal_jdxh.go +++ b/entity/signal_jdxh.go @@ -14,7 +14,6 @@ func loadSignalJdxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent signalEntry.AddComponent(component.SignalJDXHElectronicType) signalEntry.AddComponent(component.SignalJDXHLsqType) signalEntry.AddComponent(component.SignalJDXHLscType) - signalEntry.AddComponent(component.SignalLightsType) // elecState := &component.SignalJDXHElectronic{} for _, elec := range elecs { @@ -35,7 +34,6 @@ func loadSignalJdxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent component.SignalJDXHElectronicType.Set(signalEntry, elecState) component.SignalJDXHLsqType.Set(signalEntry, &component.SignalJDXHLsq{}) component.SignalJDXHLscType.Set(signalEntry, &component.SignalJDXHLsc{}) - component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag)) //校验 if elecState.JDXH_DJ == nil { return fmt.Errorf("id=[%s]的信号机JDXH,缺少元件DJ", signal.Id())