48 lines
2.0 KiB
Go
48 lines
2.0 KiB
Go
package entity
|
||
|
||
import (
|
||
"fmt"
|
||
"joylink.club/ecs"
|
||
"joylink.club/rtsssimulation/component"
|
||
"joylink.club/rtsssimulation/consts"
|
||
"joylink.club/rtsssimulation/repository"
|
||
)
|
||
|
||
func loadSignal3xh3(w ecs.World, signal *repository.Signal, signalEntry *ecs.Entry, elecs []repository.IGroupedElectronicComponent, entityMap map[string]*ecs.Entry) error {
|
||
|
||
if len(elecs) == 5 { //3xh3组合类型包含5个继电器
|
||
signalEntry.AddComponent(component.Signal3XH3ElectronicType)
|
||
signalEntry.AddComponent(component.Signal3XH3LsqType)
|
||
signalEntry.AddComponent(component.Signal3XH3LscType)
|
||
signalEntry.AddComponent(component.SignalLightsType)
|
||
//
|
||
elecState := &component.Signal3XH3Electronic{}
|
||
for _, elec := range elecs {
|
||
switch elec.Code() {
|
||
case consts.SIGNAL_DDJ:
|
||
elecState.Z3XH3_DDJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||
case consts.SIGNAL_2DJ:
|
||
elecState.Z3XH3_2DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||
case consts.SIGNAL_DJ:
|
||
elecState.Z3XH3_DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||
case consts.SIGNAL_LXJ:
|
||
elecState.Z3XH3_LXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||
case consts.SIGNAL_YXJ:
|
||
elecState.Z3XH3_YXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||
default:
|
||
return fmt.Errorf("id=[%s]的信号机3xh3,无效电子元器件名称[%s]", signal.Id(), elec.Code())
|
||
}
|
||
}
|
||
//
|
||
component.Signal3XH3ElectronicType.Set(signalEntry, elecState)
|
||
component.Signal3XH3LsqType.Set(signalEntry, &component.Signal3XH3Lsq{})
|
||
component.Signal3XH3LscType.Set(signalEntry, &component.Signal3XH3Lsc{})
|
||
component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag))
|
||
//封绿灯,即有绿灯但绿被封
|
||
component.SignalLightsType.Get(signalEntry).GetLightByTag(component.LdTag).AddComponent(component.FdTag)
|
||
} else {
|
||
return fmt.Errorf("id=[%s]的信号机3xh3,电子元器件数量须为5", signal.Id())
|
||
}
|
||
return nil
|
||
}
|