2023-10-09 10:06:01 +08:00
|
|
|
|
package entity
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
|
"joylink.club/rtsssimulation/consts"
|
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func loadSignalDcxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Entry, elecs []repository.IGroupedElectronicComponent, entityMap map[string]*ecs.Entry) error {
|
|
|
|
|
|
|
|
|
|
if len(elecs) == 2 { //dcxh组合类型包含2个继电器
|
|
|
|
|
signalEntry.AddComponent(component.SignalDCXHElectronicType)
|
2023-10-12 16:59:08 +08:00
|
|
|
|
signalEntry.AddComponent(component.SignalDCXHLsqType)
|
|
|
|
|
signalEntry.AddComponent(component.SignalDCXHLscType)
|
2023-10-09 10:06:01 +08:00
|
|
|
|
//
|
|
|
|
|
elecState := &component.SignalDCXHElectronic{}
|
|
|
|
|
for _, elec := range elecs {
|
|
|
|
|
switch elec.Code() {
|
|
|
|
|
case consts.SIGNAL_DJ:
|
|
|
|
|
elecState.DCXH_DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
|
|
|
|
case consts.SIGNAL_DXJ:
|
|
|
|
|
elecState.DCXH_DXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机dcxh,无效电子元器件名称[%s]", signal.Id(), elec.Code())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
component.SignalDCXHElectronicType.Set(signalEntry, elecState)
|
2023-10-12 16:59:08 +08:00
|
|
|
|
component.SignalDCXHLsqType.Set(signalEntry, &component.SignalDCXHLsq{})
|
|
|
|
|
component.SignalDCXHLscType.Set(signalEntry, &component.SignalDCXHLsc{})
|
2023-10-16 17:59:35 +08:00
|
|
|
|
//校验
|
|
|
|
|
if elecState.DCXH_DJ == nil {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机DCXH,缺少元件DJ", signal.Id())
|
|
|
|
|
}
|
|
|
|
|
if elecState.DCXH_DXJ == nil {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机DCXH,缺少元件DXJ", signal.Id())
|
|
|
|
|
}
|
2023-10-09 10:06:01 +08:00
|
|
|
|
} else {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机dcxh,电子元器件数量须为2", signal.Id())
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|