不带电路的信号机

This commit is contained in:
xzb 2023-10-20 10:21:35 +08:00
parent 80bcb33db6
commit 7e05997668
3 changed files with 38 additions and 4 deletions

View File

@ -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) {

View File

@ -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 {
group := groups[0]
signalEntry := newSignalEntity(w, signal.Id(), data)
if len(groups) == 1 { //带电路的信号机,有且只有一个组合类型,组合类型与电路有关
group := groups[0]
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))
}
}

View File

@ -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
}