65 lines
2.5 KiB
Go
65 lines
2.5 KiB
Go
package entity
|
||
|
||
import (
|
||
"fmt"
|
||
"joylink.club/ecs"
|
||
"joylink.club/rtsssimulation/component"
|
||
"joylink.club/rtsssimulation/consts"
|
||
"joylink.club/rtsssimulation/repository"
|
||
)
|
||
|
||
func loadSignal3xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Entry, elecs []repository.IGroupedElectronicComponent, entityMap map[string]*ecs.Entry) error {
|
||
|
||
if len(elecs) == 6 { //3xh1组合类型包含6个继电器
|
||
signalEntry.AddComponent(component.Signal3XH1ElectronicType)
|
||
signalEntry.AddComponent(component.Signal3XH1LsqType)
|
||
signalEntry.AddComponent(component.Signal3XH1LscType)
|
||
//
|
||
elecState := &component.Signal3XH1Electronic{}
|
||
for _, elec := range elecs {
|
||
switch elec.Code() {
|
||
case consts.SIGNAL_DDJ:
|
||
elecState.Z3XH1_DDJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||
case consts.SIGNAL_2DJ:
|
||
elecState.Z3XH1_2DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||
case consts.SIGNAL_DJ:
|
||
elecState.Z3XH1_DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||
case consts.SIGNAL_LXJ:
|
||
elecState.Z3XH1_LXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||
case consts.SIGNAL_YXJ:
|
||
elecState.Z3XH1_YXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||
case consts.SIGNAL_ZXJ:
|
||
elecState.Z3XH1_ZXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||
default:
|
||
return fmt.Errorf("id=[%s]的信号机3xh1,无效电子元器件名称[%s]", signal.Id(), elec.Code())
|
||
}
|
||
}
|
||
//
|
||
component.Signal3XH1ElectronicType.Set(signalEntry, elecState)
|
||
component.Signal3XH1LsqType.Set(signalEntry, &component.Signal3XH1Lsq{})
|
||
component.Signal3XH1LscType.Set(signalEntry, &component.Signal3XH1Lsc{})
|
||
//校验
|
||
if elecState.Z3XH1_DDJ == nil {
|
||
return fmt.Errorf("id=[%s]的信号机3xh1,缺少元件DDJ", signal.Id())
|
||
}
|
||
if elecState.Z3XH1_2DJ == nil {
|
||
return fmt.Errorf("id=[%s]的信号机3xh1,缺少元件2DJ", signal.Id())
|
||
}
|
||
if elecState.Z3XH1_DJ == nil {
|
||
return fmt.Errorf("id=[%s]的信号机3xh1,缺少元件DJ", signal.Id())
|
||
}
|
||
if elecState.Z3XH1_LXJ == nil {
|
||
return fmt.Errorf("id=[%s]的信号机3xh1,缺少元件LXJ", signal.Id())
|
||
}
|
||
if elecState.Z3XH1_YXJ == nil {
|
||
return fmt.Errorf("id=[%s]的信号机3xh1,缺少元件YXJ", signal.Id())
|
||
}
|
||
if elecState.Z3XH1_ZXJ == nil {
|
||
return fmt.Errorf("id=[%s]的信号机3xh1,缺少元件ZXJ", signal.Id())
|
||
}
|
||
} else {
|
||
return fmt.Errorf("id=[%s]的信号机3xh1,电子元器件数量须为6", signal.Id())
|
||
}
|
||
return nil
|
||
}
|