rts-sim-module/entity/signal_3xh4.go

55 lines
2.0 KiB
Go
Raw Permalink Normal View History

2023-10-08 18:03:07 +08:00
package entity
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/repository"
)
func loadSignal3xh4(w ecs.World, signal *repository.Signal, signalEntry *ecs.Entry, elecs []repository.IGroupedElectronicComponent, entityMap map[string]*ecs.Entry) error {
if len(elecs) == 4 { //3xh4组合类型包含4个继电器
signalEntry.AddComponent(component.Signal3XH4ElectronicType)
2023-10-12 16:13:56 +08:00
signalEntry.AddComponent(component.Signal3XH4LsqType)
signalEntry.AddComponent(component.Signal3XH4LscType)
2023-10-08 18:03:07 +08:00
//
elecState := &component.Signal3XH4Electronic{}
for _, elec := range elecs {
switch elec.Code() {
case consts.SIGNAL_DDJ:
elecState.Z3XH4_DDJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
case consts.SIGNAL_DJ:
elecState.Z3XH4_DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
case consts.SIGNAL_LXJ:
elecState.Z3XH4_LXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
case consts.SIGNAL_ZXJ:
elecState.Z3XH4_ZXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
default:
return fmt.Errorf("id=[%s]的信号机3xh4无效电子元器件名称[%s]", signal.Id(), elec.Code())
}
}
//
component.Signal3XH4ElectronicType.Set(signalEntry, elecState)
2023-10-12 16:13:56 +08:00
component.Signal3XH4LsqType.Set(signalEntry, &component.Signal3XH4Lsq{})
component.Signal3XH4LscType.Set(signalEntry, &component.Signal3XH4Lsc{})
2023-10-16 17:59:35 +08:00
//校验
if elecState.Z3XH4_DDJ == nil {
return fmt.Errorf("id=[%s]的信号机3xh4缺少元件DDJ", signal.Id())
}
if elecState.Z3XH4_DJ == nil {
return fmt.Errorf("id=[%s]的信号机3xh4缺少元件DJ", signal.Id())
}
if elecState.Z3XH4_LXJ == nil {
return fmt.Errorf("id=[%s]的信号机3xh4缺少元件LXJ", signal.Id())
}
if elecState.Z3XH4_ZXJ == nil {
return fmt.Errorf("id=[%s]的信号机3xh4缺少元件ZXJ", signal.Id())
}
2023-10-08 18:03:07 +08:00
} else {
return fmt.Errorf("id=[%s]的信号机3xh4电子元器件数量须为4", signal.Id())
}
return nil
}