diff --git a/entity/light.go b/entity/light.go index 2220245..e6fd25c 100644 --- a/entity/light.go +++ b/entity/light.go @@ -56,6 +56,15 @@ func NewLights(w ecs.World, lightTags ...component.DsTag) []*ecs.Entry { return ls } +// NewLight 创建灯位,并打标 +func NewLight(w ecs.World, lightTags ...component.DsTag) *ecs.Entry { + lightEntry := NewLightEntity(w) + for _, lightTag := range lightTags { + lightEntry.AddComponent(lightTag) + } + return lightEntry +} + // IsLightFd 灯是否被封(如Signal 3xh3 红绿黄三显示封绿灯) func IsLightFd(lightEntry *ecs.Entry) bool { if lightEntry.HasComponent(component.LightDriveType) && lightEntry.HasComponent(component.BitStateType) { diff --git a/entity/signal.go b/entity/signal.go index 92c1fa5..55683e3 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/model/proto" "log/slog" ) @@ -14,9 +15,9 @@ func LoadSignals(w ecs.World) error { signals := data.Repo.SignalList() for _, signal := range signals { groups := signal.RelayGroups() - if len(groups) == 1 { + signalEntry := newSignalEntity(w, signal.Id(), data) + if len(groups) == 1 { //带电路的信号机,有且只有一个组合类型,组合类型与电路有关 group := groups[0] - signalEntry := newSignalEntity(w, signal.Id(), data) elecs := group.Components() // switch group.Code() { @@ -55,8 +56,9 @@ func LoadSignals(w ecs.World) error { default: slog.Warn(fmt.Sprintf("id=[%s]的信号机,无效组合类型[%s]", signal.Id(), group.Code())) } - } else { //信号机有且只有一个组合类型 - slog.Warn("id=[%s]的信号机须有且只有一个组合类型", signal.Id()) + } else { //不带电路的信号机 + signalEntry.AddComponent(component.SignalLightsType) + component.SignalLightsType.Set(signalEntry, newSignalLightsByModel(w, signal.Model())) } } return nil @@ -77,3 +79,23 @@ func newSignalEntity(w ecs.World, uid string, worldData *component.WorldData) *e func newSignalLights(w ecs.World, lightTags ...component.DsTag) *component.SignalLights { return &component.SignalLights{Lights: NewLights(w, lightTags...)} } + +// 新建灯位列表 +func newSignalLightsByModel(w ecs.World, sigMt proto.Signal_Model) *component.SignalLights { + switch sigMt { + case proto.Signal_HLU: + return newSignalLights(w, component.HdTag, component.LdTag, component.UdTag) + case proto.Signal_HL: + return newSignalLights(w, component.HdTag, component.LdTag) + case proto.Signal_HLU_FU: + return &component.SignalLights{Lights: []*ecs.Entry{NewLight(w, component.HdTag), NewLight(w, component.LdTag), NewLight(w, component.UdTag, component.FdTag)}} + case proto.Signal_HLU_FL: + return &component.SignalLights{Lights: []*ecs.Entry{NewLight(w, component.HdTag), NewLight(w, component.LdTag, component.FdTag), NewLight(w, component.UdTag)}} + case proto.Signal_AB: + return newSignalLights(w, component.AdTag, component.BdTag) + case proto.Signal_HBU: + return newSignalLights(w, component.HdTag, component.BdTag, component.UdTag) + default: + panic(fmt.Sprintf("根据信号机模型来创建灯位列表,暂不支持该信号机模型[%d]", sigMt)) + } +} diff --git a/repository/signal.go b/repository/signal.go index 6f3c04f..8ab2135 100644 --- a/repository/signal.go +++ b/repository/signal.go @@ -40,3 +40,6 @@ func (s *Signal) RelayGroups() []*ElectronicComponentGroup { func (s *Signal) Code() string { return s.code } +func (s *Signal) Model() proto.Signal_Model { + return s.model +}