rts-sim-module/entity/signal_jdxh.go
2023-10-16 17:59:35 +08:00

57 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}