rts-sim-module/entity/signal_jdxh.go

55 lines
2.0 KiB
Go
Raw Normal View History

2023-10-09 11:09:29 +08:00
package entity
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/repository"
)
func loadSignalJdxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Entry, elecs []repository.IGroupedElectronicComponent, entityMap map[string]*ecs.Entry) error {
if len(elecs) == 4 { //jdxh组合类型包含3个继电器
signalEntry.AddComponent(component.SignalJDXHElectronicType)
2023-10-13 09:31:49 +08:00
signalEntry.AddComponent(component.SignalJDXHLsqType)
signalEntry.AddComponent(component.SignalJDXHLscType)
2023-10-09 11:09:29 +08:00
//
elecState := &component.SignalJDXHElectronic{}
for _, elec := range elecs {
switch elec.Code() {
case consts.SIGNAL_DJ:
elecState.JDXH_DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
case consts.SIGNAL_2DJ:
elecState.JDXH_2DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
case consts.SIGNAL_LXJ:
elecState.JDXH_LXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
case consts.SIGNAL_YXJ:
elecState.JDXH_YXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
default:
return fmt.Errorf("id=[%s]的信号机jdxh无效电子元器件名称[%s]", signal.Id(), elec.Code())
}
}
//
component.SignalJDXHElectronicType.Set(signalEntry, elecState)
2023-10-13 09:31:49 +08:00
component.SignalJDXHLsqType.Set(signalEntry, &component.SignalJDXHLsq{})
component.SignalJDXHLscType.Set(signalEntry, &component.SignalJDXHLsc{})
2023-10-16 17:59:35 +08:00
//校验
if elecState.JDXH_DJ == nil {
return fmt.Errorf("id=[%s]的信号机JDXH缺少元件DJ", signal.Id())
}
if elecState.JDXH_2DJ == nil {
return fmt.Errorf("id=[%s]的信号机JDXH缺少元件2DJ", signal.Id())
}
if elecState.JDXH_LXJ == nil {
return fmt.Errorf("id=[%s]的信号机JDXH缺少元件LXJ", signal.Id())
}
if elecState.JDXH_YXJ == nil {
return fmt.Errorf("id=[%s]的信号机JDXH缺少元件YXJ", signal.Id())
}
2023-10-09 11:09:29 +08:00
} else {
return fmt.Errorf("id=[%s]的信号机jdxh电子元器件数量须为4", signal.Id())
}
return nil
}