signal
This commit is contained in:
parent
b2d079d737
commit
9a7ecd5763
@ -2,6 +2,8 @@ package memory
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"joylink.club/rtsssimulation/component"
|
||||
"joylink.club/rtsssimulation/entity"
|
||||
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/state"
|
||||
@ -126,3 +128,48 @@ func changeSignal2XH1State(w ecs.World, signalUid string, toAspect state.Signal_
|
||||
fi.DriveSignal2XH1Non(w, signalUid)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取仿真地图的信号机状态,用于推送给前端
|
||||
func GetMapAllSignalState(sim *VerifySimulation, mapId int32) []*state.SignalState {
|
||||
uidMap := QueryMapUidMapByType(mapId, &graphicData.Signal{})
|
||||
var signalArr []*state.SignalState
|
||||
for _, u := range uidMap {
|
||||
s := handlerSignalState(sim.World, u.Uid)
|
||||
if s == nil {
|
||||
continue
|
||||
}
|
||||
s.Id = u.CommonId
|
||||
signalArr = append(signalArr, s)
|
||||
}
|
||||
return signalArr
|
||||
}
|
||||
func handlerSignalState(w ecs.World, uid string) *state.SignalState {
|
||||
entry, ok := entity.GetEntityByUid(w, uid)
|
||||
if !ok {
|
||||
fmt.Printf("id=%s的道岔不存在", uid)
|
||||
return nil
|
||||
}
|
||||
if !entry.HasComponent(component.SignalLightsType) { //信号机灯列表
|
||||
return nil
|
||||
}
|
||||
signalState := &state.SignalState{}
|
||||
lights := component.SignalLightsType.Get(entry)
|
||||
for _, light := range lights.Lights {
|
||||
lightAspect := &state.Signal_Light{}
|
||||
switch {
|
||||
case light.HasComponent(component.LdTag):
|
||||
lightAspect.Color = state.Signal_L
|
||||
case light.HasComponent(component.HdTag):
|
||||
lightAspect.Color = state.Signal_H
|
||||
case light.HasComponent(component.UdTag):
|
||||
lightAspect.Color = state.Signal_U
|
||||
case light.HasComponent(component.BdTag):
|
||||
lightAspect.Color = state.Signal_B
|
||||
case light.HasComponent(component.AdTag):
|
||||
lightAspect.Color = state.Signal_A
|
||||
}
|
||||
lightAspect.Display = component.BitStateType.Get(light).Val
|
||||
signalState.Light = append(signalState.Light, lightAspect)
|
||||
}
|
||||
return signalState
|
||||
}
|
||||
|
@ -64,21 +64,6 @@ func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
|
||||
return switchArr
|
||||
}
|
||||
|
||||
// 获取仿真地图的信号机状态,用于推送给前端
|
||||
func GetMapAllSignalState(sim *VerifySimulation, mapId int32) []*state.SignalState {
|
||||
uidMap := QueryMapUidMapByType(mapId, &graphicData.Signal{})
|
||||
var signalArr []*state.SignalState
|
||||
for _, u := range uidMap {
|
||||
s := handlerSignalState(sim.World, u.Uid)
|
||||
if s == nil {
|
||||
continue
|
||||
}
|
||||
s.Id = u.CommonId
|
||||
signalArr = append(signalArr, s)
|
||||
}
|
||||
return signalArr
|
||||
}
|
||||
|
||||
// 获取仿真地图的道岔状态,前端推送
|
||||
func GetMapAllTurnoutState(sim *VerifySimulation, mapId int32) []*state.SwitchState {
|
||||
// 获取本地图下的道岔信息
|
||||
@ -107,33 +92,3 @@ func handlerTurnoutState(w ecs.World, uid string) *state.SwitchState {
|
||||
pos := component.TurnoutPositionType.Get(entry)
|
||||
return &state.SwitchState{Normal: pos.Db, Reverse: pos.Fb, Dw: pos.Dw, Fw: pos.Fw}
|
||||
}
|
||||
func handlerSignalState(w ecs.World, uid string) *state.SignalState {
|
||||
entry, ok := entity.GetEntityByUid(w, uid)
|
||||
if !ok {
|
||||
fmt.Printf("id=%s的道岔不存在", uid)
|
||||
return nil
|
||||
}
|
||||
if !entry.HasComponent(component.SignalLightsType) { //信号机灯列表
|
||||
return nil
|
||||
}
|
||||
signalState := &state.SignalState{}
|
||||
lights := component.SignalLightsType.Get(entry)
|
||||
for _, light := range lights.Lights {
|
||||
lightAspect := &state.Signal_Light{}
|
||||
switch {
|
||||
case light.HasComponent(component.LdTag):
|
||||
lightAspect.Color = state.Signal_L
|
||||
case light.HasComponent(component.HdTag):
|
||||
lightAspect.Color = state.Signal_H
|
||||
case light.HasComponent(component.UdTag):
|
||||
lightAspect.Color = state.Signal_U
|
||||
case light.HasComponent(component.BdTag):
|
||||
lightAspect.Color = state.Signal_B
|
||||
case light.HasComponent(component.AdTag):
|
||||
lightAspect.Color = state.Signal_A
|
||||
}
|
||||
lightAspect.Display = component.BitStateType.Get(light).Val
|
||||
signalState.Light = append(signalState.Light, lightAspect)
|
||||
}
|
||||
return signalState
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user