2023-10-08 16:48:10 +08:00
|
|
|
|
package entity
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
|
"joylink.club/rtsssimulation/consts"
|
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func loadSignal3xh2(w ecs.World, signal *repository.Signal, signalEntry *ecs.Entry, elecs []repository.IGroupedElectronicComponent, entityMap map[string]*ecs.Entry) error {
|
|
|
|
|
|
|
|
|
|
if len(elecs) == 5 { //3xh2组合类型包含5个继电器
|
|
|
|
|
signalEntry.AddComponent(component.Signal3XH2ElectronicType)
|
2023-10-12 14:19:00 +08:00
|
|
|
|
signalEntry.AddComponent(component.Signal3XH2LsqType)
|
|
|
|
|
signalEntry.AddComponent(component.Signal3XH2LscType)
|
2023-10-08 16:48:10 +08:00
|
|
|
|
//
|
2023-10-12 14:19:00 +08:00
|
|
|
|
elecState := &component.Signal3XH2Electronic{}
|
2023-10-08 16:48:10 +08:00
|
|
|
|
for _, elec := range elecs {
|
|
|
|
|
switch elec.Code() {
|
|
|
|
|
case consts.SIGNAL_DDJ:
|
|
|
|
|
elecState.Z3XH2_DDJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
|
|
|
|
case consts.SIGNAL_2DJ:
|
|
|
|
|
elecState.Z3XH2_2DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
|
|
|
|
case consts.SIGNAL_DJ:
|
|
|
|
|
elecState.Z3XH2_DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
|
|
|
|
case consts.SIGNAL_LXJ:
|
|
|
|
|
elecState.Z3XH2_LXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
|
|
|
|
case consts.SIGNAL_YXJ:
|
|
|
|
|
elecState.Z3XH2_YXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机3xh2,无效电子元器件名称[%s]", signal.Id(), elec.Code())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
component.Signal3XH2ElectronicType.Set(signalEntry, elecState)
|
2023-10-12 14:19:00 +08:00
|
|
|
|
component.Signal3XH2LsqType.Set(signalEntry, &component.Signal3XH2Lsq{})
|
|
|
|
|
component.Signal3XH2LscType.Set(signalEntry, &component.Signal3XH2Lsc{})
|
2023-10-16 17:59:35 +08:00
|
|
|
|
//校验
|
|
|
|
|
if elecState.Z3XH2_DDJ == nil {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机3xh2,缺少元件DDJ", signal.Id())
|
|
|
|
|
}
|
|
|
|
|
if elecState.Z3XH2_2DJ == nil {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机3xh2,缺少元件2DJ", signal.Id())
|
|
|
|
|
}
|
|
|
|
|
if elecState.Z3XH2_DJ == nil {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机3xh2,缺少元件DJ", signal.Id())
|
|
|
|
|
}
|
|
|
|
|
if elecState.Z3XH2_LXJ == nil {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机3xh2,缺少元件LXJ", signal.Id())
|
|
|
|
|
}
|
|
|
|
|
if elecState.Z3XH2_YXJ == nil {
|
|
|
|
|
return fmt.Errorf("id=[%s]的信号机3xh2,缺少元件YXJ", signal.Id())
|
|
|
|
|
}
|
2023-10-08 16:48:10 +08:00
|
|
|
|
} else {
|
2023-10-08 18:03:07 +08:00
|
|
|
|
return fmt.Errorf("id=[%s]的信号机3xh2,电子元器件数量须为5", signal.Id())
|
2023-10-08 16:48:10 +08:00
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|