diff --git a/entities/relay_entity.go b/entities/relay_entity.go index ae114b2..9791aa5 100644 --- a/entities/relay_entity.go +++ b/entities/relay_entity.go @@ -3,9 +3,15 @@ package entities import ( "joylink.club/ecs" "joylink.club/rtsssimulation/repository" + "joylink.club/rtsssimulation/simulation" "joylink.club/rtsssimulation/system" ) +type RelayState struct { + Id string + Xh bool +} + // CreateRelayEntity 创建继电器实体 func CreateRelayEntity(w ecs.World, relayId string) *ecs.Entry { e := w.Create(system.EntityIdentityComponent, system.RelayStateComponent) @@ -19,3 +25,13 @@ func CreateRelayEntries(world ecs.World, relays []*repository.Relay) { CreateRelayEntity(world, relay.Id()) } } + +func GetRelayState(worldId ecs.WorldId, relayId string) *RelayState { + sim := simulation.FindSimulation(worldId) + entry := sim.GetEntry(relayId) + if entry == nil { + return nil + } + state := system.RelayStateComponent.Get(entry) + return &RelayState{Id: relayId, Xh: state.Xh} +} diff --git a/entities/switch_entity.go b/entities/switch_entity.go index dd9c5b7..ce95a6c 100644 --- a/entities/switch_entity.go +++ b/entities/switch_entity.go @@ -76,7 +76,7 @@ func TurnToReverse(worldId ecs.WorldId, turnoutId string) { }() } -func GetState(worldId ecs.WorldId, turnoutId string) *TurnoutState { +func GetTurnoutState(worldId ecs.WorldId, turnoutId string) *TurnoutState { sim := simulation.FindSimulation(worldId) entry := sim.GetEntry(turnoutId) if entry == nil {