98 lines
3.1 KiB
Go
98 lines
3.1 KiB
Go
package memory
|
|
|
|
import (
|
|
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
|
|
"joylink.club/bj-rtsts-server/ts/protos/state"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
"joylink.club/rtsssimulation/fi"
|
|
)
|
|
|
|
// 操作IBP按钮
|
|
func ChangeIBPButtonState(sim *VerifySimulation, mapId int32, stationId, btnCode string, pressDown bool) {
|
|
stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{})
|
|
if pressDown {
|
|
fi.PressDownButton(sim.World, stationUid+"_button_"+btnCode)
|
|
} else {
|
|
fi.PressUpButton(sim.World, stationUid+"_button_"+btnCode)
|
|
}
|
|
}
|
|
|
|
// 操作IBP按钮
|
|
func ChangeIBPKeyState(sim *VerifySimulation, mapId int32, stationId, keyCode string, gear int32) {
|
|
stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{})
|
|
fi.SwitchKeyGear(sim.World, stationUid+"_key_"+keyCode, gear)
|
|
}
|
|
|
|
// 获取仿真车站按钮状态,前端推送
|
|
func GetMapAllIBPState(sim *VerifySimulation, mapId int32, stationId, ibpMapCode string) *state.AllDevicesStatus {
|
|
status := &state.AllDevicesStatus{
|
|
ButtonState: []*state.ButtonState{},
|
|
LightState: []*state.LightState{},
|
|
AlarmState: []*state.AlarmState{},
|
|
KeyState: []*state.KeyState{},
|
|
}
|
|
stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{})
|
|
ibpStorage := getStorageIBPMapData(ibpMapCode)
|
|
for _, data := range ibpStorage.IbpButtons { // 按钮
|
|
entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_button_"+data.Code)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if entry.HasComponent(component.ButtonTag) {
|
|
status.ButtonState = append(status.ButtonState, getIBPButtonState(data.Common.Id, entry))
|
|
}
|
|
}
|
|
for _, data := range ibpStorage.IbpAlarms { // 报警器
|
|
entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_alarm_"+data.Code)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if entry.HasComponent(component.AlarmTag) {
|
|
status.AlarmState = append(status.AlarmState, &state.AlarmState{
|
|
Id: data.Common.Id,
|
|
Active: component.BitStateType.Get(entry).Val,
|
|
})
|
|
}
|
|
}
|
|
for _, data := range ibpStorage.IbpLights { // 指示灯
|
|
entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_light_"+data.Code)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if entry.HasComponent(component.LightTag) {
|
|
status.LightState = append(status.LightState, &state.LightState{
|
|
Id: data.Common.Id,
|
|
Active: component.BitStateType.Get(entry).Val,
|
|
})
|
|
}
|
|
}
|
|
for _, data := range ibpStorage.IbpKeys { // 钥匙
|
|
entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_key_"+data.Code)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if entry.HasComponent(component.KeyTag) {
|
|
status.KeyState = append(status.KeyState, &state.KeyState{
|
|
Id: data.Common.Id,
|
|
Gear: component.GearStateType.Get(entry).Val,
|
|
})
|
|
}
|
|
}
|
|
return status
|
|
}
|
|
|
|
// 获取IBP盘按钮状态
|
|
func getIBPButtonState(id string, entry *ecs.Entry) *state.ButtonState {
|
|
status := &state.ButtonState{Id: id}
|
|
bit := component.BitStateType.Get(entry)
|
|
status.Down = bit.Val
|
|
// 如果按钮包含灯
|
|
if entry.HasComponent(component.SingleLightType) {
|
|
lightComponent := component.SingleLightType.Get(entry)
|
|
status.Active = component.BitStateType.Get(lightComponent.Light).Val
|
|
}
|
|
return status
|
|
}
|