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

83 lines
2.8 KiB
Go

package memory
import (
"fmt"
"joylink.club/bj-rtsts-server/sys_error"
"joylink.club/bj-rtsts-server/dto/data_proto"
"joylink.club/rtsssimulation/fi"
)
// 操作IBP按钮
func ChangeIBPButtonState(sim *VerifySimulation, mapId int32, ibpId, btnId uint32, pressDown bool) error {
storage := QueryGiData[*data_proto.RtssGraphicStorage](mapId)
var ibp *data_proto.IbpBox
for _, box := range storage.IbpBoxs {
if box.Common.Id == ibpId {
ibp = box
}
}
if ibp == nil {
return sys_error.New(fmt.Sprintf("没有找到[id:%d]IBP元素", ibpId))
}
ibpMapId, _ := QueryGiDataByName[*data_proto.IBPGraphicStorage](ibp.RefIbpMapCode)
ibpUidMap := QueryUidStructure[*IBPUidStructure](ibpMapId)
if ibpUidMap == nil {
return fmt.Errorf("没有找到IBP对应的数据")
}
if ibpUidMap.IbpButtonIds[btnId] == nil {
return fmt.Errorf("ibp【%d】按钮【%d】UID不存在", ibpId, btnId)
}
ibpUid := QueryUidByMidAndComId(mapId, ibp.Common.Id, &data_proto.IbpBox{})
if pressDown {
return fi.PressDownButton(sim.World, ibpUid+"_"+ibpUidMap.IbpButtonIds[btnId].Uid)
} else {
return fi.PressUpButton(sim.World, ibpUid+"_"+ibpUidMap.IbpButtonIds[btnId].Uid)
}
}
// 操作IBP按钮
func ChangeIBPKeyState(sim *VerifySimulation, mapId int32, ibpId, keyId uint32, gear int32) error {
storage := QueryGiData[*data_proto.RtssGraphicStorage](mapId)
var ibpBox *data_proto.IbpBox
for _, box := range storage.IbpBoxs {
if box.Common.Id == ibpId {
ibpBox = box
}
}
if ibpBox == nil {
return sys_error.New(fmt.Sprintf("没有找到[id:%d]IBP元素", ibpId))
}
ibpMapId, _ := QueryGiDataByName[*data_proto.IBPGraphicStorage](ibpBox.RefIbpMapCode)
ibpUidMap := QueryUidStructure[*IBPUidStructure](ibpMapId)
if ibpUidMap == nil {
return fmt.Errorf("没有找到IBP对应的数据")
}
if ibpUidMap.IbpKeyIds[keyId] == nil {
return fmt.Errorf("车站【%d】钥匙【%d】UID不存在", ibpId, keyId)
}
ibpUid := QueryUidByMidAndComId(mapId, ibpBox.Common.Id, &data_proto.IbpBox{})
return fi.SwitchKeyGear(sim.World, ibpUid+"_"+ibpUidMap.IbpKeyIds[keyId].Uid, gear)
}
//// 根据平面布置图ID、列车ID获取IbpUid信息
//func getIbpUidByMapIdAndIbpId(mapId int32, ibpId uint32) (*IBPUidStructure, error) {
// giData := QueryGiData[*data_proto.RtssGraphicStorage](mapId)
// var station *data_proto.Station
// for _, s := range giData.Stations {
// if GetMapElementId(s.Common) == ibpId {
// station = s
// break
// }
// }
// if station == nil {
// return nil, fmt.Errorf("地图【%d】车站【%d】不存在", mapId, ibpId)
// }
//
// if station.RefIbpMapCode == "" {
// return nil, fmt.Errorf("车站【%s】未关联IBP地图", station.StationName)
// }
// ibpMapId, _ := QueryGiDataByName[*data_proto.IBPGraphicStorage](station.RefIbpMapCode)
// return QueryUidStructure[*IBPUidStructure](ibpMapId), nil
//}