rts-sim-module/entity/signal_jdxh.go

40 lines
1.5 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)
signalEntry.AddComponent(component.SignalJDXHFilamentType)
//
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)
component.SignalJDXHFilamentType.Set(signalEntry, &component.SignalJDXHFilament{Uf: true, Lf: true, Hf: true, U: false, L: false, H: false})
} else {
return fmt.Errorf("id=[%s]的信号机jdxh电子元器件数量须为4", signal.Id())
}
return nil
}