2023-10-09 10:30:44 +08:00
|
|
|
|
package entity
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
|
"joylink.club/rtsssimulation/consts"
|
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func loadSignalJckxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Entry, elecs []repository.IGroupedElectronicComponent, entityMap map[string]*ecs.Entry) error {
|
|
|
|
|
|
|
|
|
|
if len(elecs) == 3 { //jckxh组合类型包含3个继电器
|
|
|
|
|
signalEntry.AddComponent(component.SignalJCKXHElectronicType)
|
2023-10-12 17:33:20 +08:00
|
|
|
|
signalEntry.AddComponent(component.SignalJCKXHLsqType)
|
|
|
|
|
signalEntry.AddComponent(component.SignalJCKXHLscType)
|
2023-10-09 10:30:44 +08:00
|
|
|
|
//
|
|
|
|
|
elecState := &component.SignalJCKXHElectronic{}
|
|
|
|
|
for _, elec := range elecs {
|
|
|
|
|
switch elec.Code() {
|
|
|
|
|
case consts.SIGNAL_DJ:
|
|
|
|
|
elecState.JCKXH_DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
|
|
|
|
case consts.SIGNAL_DXJ:
|
|
|
|
|
elecState.JCKXH_DXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
|
|
|
|
case consts.SIGNAL_LXJ:
|
|
|
|
|
elecState.JCKXH_LXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机jckxh,无效电子元器件名称[%s]", signal.Id(), elec.Code())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
component.SignalJCKXHElectronicType.Set(signalEntry, elecState)
|
2023-10-12 17:33:20 +08:00
|
|
|
|
component.SignalJCKXHLsqType.Set(signalEntry, &component.SignalJCKXHLsq{})
|
|
|
|
|
component.SignalJCKXHLscType.Set(signalEntry, &component.SignalJCKXHLsc{})
|
2023-10-16 17:59:35 +08:00
|
|
|
|
//校验
|
|
|
|
|
if elecState.JCKXH_DJ == nil {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机JCKXH,缺少元件DJ", signal.Id())
|
|
|
|
|
}
|
|
|
|
|
if elecState.JCKXH_DXJ == nil {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机JCKXH,缺少元件DXJ", signal.Id())
|
|
|
|
|
}
|
|
|
|
|
if elecState.JCKXH_LXJ == nil {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机JCKXH,缺少元件LXJ", signal.Id())
|
|
|
|
|
}
|
2023-10-09 10:30:44 +08:00
|
|
|
|
} else {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机jckxh,电子元器件数量须为3", signal.Id())
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|