diff --git a/entities/switch_entity.go b/entities/switch_entity.go index f83c6d2..3b20f99 100644 --- a/entities/switch_entity.go +++ b/entities/switch_entity.go @@ -8,6 +8,14 @@ import ( "joylink.club/rtsssimulation/system" ) +type Position int + +const ( + SK Position = iota //四开(不会起名字) + D //定位 + F //反位 +) + // CreateSwitch2jzdj9Entity 双机zdj9 // 默认定位 func CreateSwitch2jzdj9Entity(w ecs.World, switchId string) *ecs.Entry { @@ -59,3 +67,16 @@ func TurnToReverse(worldId ecs.WorldId, turnoutId string) { state.YCJ = true state.FCJ = true } + +func GetState(worldId ecs.WorldId, turnoutId string) Position { + sim := simulation.FindSimulation(worldId) + turnoutEntry := system.FindEntityById(sim.World(), turnoutId) + state := system.Switch2jZdj9StateComponent.Get(turnoutEntry) + if state.ZDBJ { + return D + } else if state.ZFBJ { + return F + } else { + return SK + } +} diff --git a/repository/repository_manager.go b/repository/repository_manager.go index 6df99b3..8a4a9a1 100644 --- a/repository/repository_manager.go +++ b/repository/repository_manager.go @@ -259,7 +259,10 @@ func buildTurnoutRelationShip(source *proto.Repository, repo *Repository) error for _, group := range protoData.RelayGroups { var relays []*Relay for _, id := range group.RelayIds { - relays = append(relays, repo.relayMap[id]) + relay := repo.relayMap[id] + if relay != nil { + relays = append(relays, relay) + } } turnout.relayGroups = append(turnout.relayGroups, &RelayGroup{ code: group.Code,