rts-sim-module/entity/signal_2xh1.go

50 lines
1.8 KiB
Go
Raw Normal View History

2023-10-08 13:11:34 +08:00
package entity
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/repository"
)
func loadSignal2xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Entry, elecs []repository.IGroupedElectronicComponent, entityMap map[string]*ecs.Entry) error {
if len(elecs) == 3 { //2xh1组合类型包含3个继电器
signalEntry.AddComponent(component.Signal2XH1ElectronicType)
2023-10-12 10:07:40 +08:00
signalEntry.AddComponent(component.Signal2XH1LsqType)
signalEntry.AddComponent(component.Signal2XH1LscType)
2023-10-08 13:11:34 +08:00
//
2023-10-12 11:00:56 +08:00
elecState := &component.Signal2XH1Electronic{}
2023-10-08 13:11:34 +08:00
for _, elec := range elecs {
switch elec.Code() {
case consts.SIGNAL_DDJ:
elecState.Z2XH1_DDJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
case consts.SIGNAL_DJ:
elecState.Z2XH1_DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
case consts.SIGNAL_LXJ:
elecState.Z2XH1_LXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
default:
return fmt.Errorf("id=[%s]的信号机2xh1无效电子元器件名称[%s]", signal.Id(), elec.Code())
}
}
//
component.Signal2XH1ElectronicType.Set(signalEntry, elecState)
2023-10-12 10:07:40 +08:00
component.Signal2XH1LsqType.Set(signalEntry, &component.Signal2XH1Lsq{})
component.Signal2XH1LscType.Set(signalEntry, &component.Signal2XH1Lsc{})
2023-10-16 17:59:35 +08:00
//校验
if elecState.Z2XH1_DDJ == nil {
return fmt.Errorf("id=[%s]的信号机2xh1缺少元件DDJ", signal.Id())
}
if elecState.Z2XH1_DJ == nil {
return fmt.Errorf("id=[%s]的信号机2xh1缺少元件DJ", signal.Id())
}
if elecState.Z2XH1_LXJ == nil {
return fmt.Errorf("id=[%s]的信号机2xh1缺少元件LXJ", signal.Id())
}
2023-10-08 13:11:34 +08:00
} else {
return fmt.Errorf("id=[%s]的信号机2xh1电子元器件数量须为3", signal.Id())
}
return nil
}