package memory import ( "fmt" "joylink.club/bj-rtsts-server/dto/data_proto" "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, &data_proto.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, &data_proto.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[*data_proto.RtssGraphicStorage](mapId) var station *data_proto.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[*data_proto.IBPGraphicStorage](station.RefIbpMapCode) return QueryUidStructure[*IBPUidStructure](ibpMapId), nil }