57 lines
2.2 KiB
Go
57 lines
2.2 KiB
Go
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.SignalJDXHLsqType)
|
||
signalEntry.AddComponent(component.SignalJDXHLscType)
|
||
signalEntry.AddComponent(component.SignalLightsType)
|
||
//
|
||
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.SignalJDXHLsqType.Set(signalEntry, &component.SignalJDXHLsq{})
|
||
component.SignalJDXHLscType.Set(signalEntry, &component.SignalJDXHLsc{})
|
||
component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag))
|
||
//校验
|
||
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())
|
||
}
|
||
} else {
|
||
return fmt.Errorf("id=[%s]的信号机jdxh,电子元器件数量须为4", signal.Id())
|
||
}
|
||
return nil
|
||
}
|