rts-sim-testing-service/ts/simulation/wayside/memory/wayside_memory_ibp.go

60 lines
2.0 KiB
Go

package memory
import (
"fmt"
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
"joylink.club/rtsssimulation/fi"
)
// 操作IBP按钮
func ChangeIBPButtonState(sim *VerifySimulation, mapId int32, stationId, btnId uint32, pressDown bool) error {
uidMap, err := getIbpUidByMapIdAndStationId(mapId, stationId)
if err != nil {
return err
}
if uidMap.IbpButtonIds[btnId] == nil {
return fmt.Errorf("车站【%d】按钮【%d】UID不存在", stationId, btnId)
}
stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{})
if pressDown {
return fi.PressDownButton(sim.World, stationUid+"_"+uidMap.IbpButtonIds[btnId].Uid)
} else {
return fi.PressUpButton(sim.World, stationUid+"_"+uidMap.IbpButtonIds[btnId].Uid)
}
}
// 操作IBP按钮
func ChangeIBPKeyState(sim *VerifySimulation, mapId int32, stationId, keyId uint32, gear int32) error {
uidMap, err := getIbpUidByMapIdAndStationId(mapId, stationId)
if err != nil {
return err
}
if uidMap.IbpKeyIds[keyId] == nil {
return fmt.Errorf("车站【%d】钥匙【%d】UID不存在", stationId, keyId)
}
stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{})
return fi.SwitchKeyGear(sim.World, stationUid+"_"+uidMap.IbpKeyIds[keyId].Uid, gear)
}
// 根据平面布置图ID、列车ID获取IbpUid信息
func getIbpUidByMapIdAndStationId(mapId int32, stationId uint32) (*IBPUidStructure, error) {
giData := QueryGiData[*graphicData.RtssGraphicStorage](mapId)
var station *graphicData.Station
for _, s := range giData.Stations {
if GetMapElementId(s.Common) == stationId {
station = s
break
}
}
if station == nil {
return nil, fmt.Errorf("地图【%d】车站【%d】不存在", mapId, stationId)
}
if station.RefIbpMapCode == "" {
return nil, fmt.Errorf("车站【%s】未关联IBP地图", station.StationName)
}
ibpMapId, _ := QueryGiDataByName[*graphicData.IBPGraphicStorage](station.RefIbpMapCode)
return QueryUidStructure[*IBPUidStructure](ibpMapId), nil
}