rts-sim-module/entity/signal_3xh2.go
2023-10-12 14:19:00 +08:00

46 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
signalEntry.AddComponent(component.Signal3XH2LsqType)
signalEntry.AddComponent(component.Signal3XH2LscType)
signalEntry.AddComponent(component.SignalLightsType)
//
elecState := &component.Signal3XH2Electronic{}
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)
component.Signal3XH2LsqType.Set(signalEntry, &component.Signal3XH2Lsq{})
component.Signal3XH2LscType.Set(signalEntry, &component.Signal3XH2Lsc{})
component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag))
} else {
return fmt.Errorf("id=[%s]的信号机3xh2电子元器件数量须为5", signal.Id())
}
return nil
}