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

83 lines
2.8 KiB
Go
Raw Normal View History

2023-10-18 13:53:17 +08:00
package memory
import (
2023-12-07 10:17:48 +08:00
"fmt"
"joylink.club/bj-rtsts-server/sys_error"
2023-12-07 10:17:48 +08:00
"joylink.club/bj-rtsts-server/dto/data_proto"
2023-10-18 13:53:17 +08:00
"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对应的数据")
2023-12-07 10:17:48 +08:00
}
if ibpUidMap.IbpButtonIds[btnId] == nil {
return fmt.Errorf("ibp【%d】按钮【%d】UID不存在", ibpId, btnId)
2023-12-07 10:17:48 +08:00
}
ibpUid := QueryUidByMidAndComId(mapId, ibp.Common.Id, &data_proto.IbpBox{})
2023-10-18 13:53:17 +08:00
if pressDown {
return fi.PressDownButton(sim.World, ibpUid+"_"+ibpUidMap.IbpButtonIds[btnId].Uid)
2023-10-18 13:53:17 +08:00
} else {
return fi.PressUpButton(sim.World, ibpUid+"_"+ibpUidMap.IbpButtonIds[btnId].Uid)
2023-10-18 13:53:17 +08:00
}
}
2023-10-20 13:50:22 +08:00
// 操作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
2023-12-07 10:17:48 +08:00
}
}
if ibpBox == nil {
return sys_error.New(fmt.Sprintf("没有找到[id:%d]IBP元素", ibpId))
2023-12-07 10:17:48 +08:00
}
ibpMapId, _ := QueryGiDataByName[*data_proto.IBPGraphicStorage](ibpBox.RefIbpMapCode)
ibpUidMap := QueryUidStructure[*IBPUidStructure](ibpMapId)
if ibpUidMap == nil {
return fmt.Errorf("没有找到IBP对应的数据")
2023-12-07 10:17:48 +08:00
}
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)
2023-10-20 13:50:22 +08:00
}
//// 根据平面布置图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
//}