rts-sim-testing-service/ts/simulation/wayside/memory/wayside_memory_ibp.go
2023-12-07 10:17:48 +08:00

59 lines
1.9 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 string, pressDown bool) error {
uidMap, err := getIbpUidByMapIdAndStationId(mapId, stationId)
if err != nil {
return err
}
if uidMap.IbpButtonIds[btnId] == nil {
return fmt.Errorf("车站【%s】按钮【%s】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 string, gear int32) error {
uidMap, err := getIbpUidByMapIdAndStationId(mapId, stationId)
if err != nil {
return err
}
if uidMap.IbpKeyIds[keyId] == nil {
return fmt.Errorf("车站【%s】钥匙【%s】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 string) (*IBPUidStructure, error) {
giData := QueryGiData[*graphicData.RtssGraphicStorage](mapId)
var station *graphicData.Station
for _, s := range giData.Stations {
if s.Common.Id == stationId {
station = s
break
}
}
if station == nil {
return nil, fmt.Errorf("地图【%d】车站【%s】不存在", mapId, stationId)
}
if station.RefIbpMapCode == "" {
return nil, fmt.Errorf("车站【%s】未关联IBP地图", station.StationName)
}
return QueryUidStructure[*IBPUidStructure](QueryGiId(station.RefIbpMapCode)), nil
}