rts-sim-module/deprecated/entities/relay_entity.go

38 lines
998 B
Go
Raw Normal View History

2023-09-15 13:07:31 +08:00
package entities
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/deprecated/simulation"
"joylink.club/rtsssimulation/deprecated/system"
"joylink.club/rtsssimulation/repository"
2023-09-15 13:07:31 +08:00
)
type RelayState struct {
Id string
Xh bool
}
2023-09-15 13:50:15 +08:00
// CreateRelayEntity 创建继电器实体
2023-09-15 13:07:31 +08:00
func CreateRelayEntity(w ecs.World, relayId string) *ecs.Entry {
e := w.Create(system.EntityIdentityComponent, system.RelayStateComponent)
system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: relayId})
system.RelayStateComponent.Set(e, system.NewRelayState())
return e
}
func CreateRelayEntries(world ecs.World, relays []*repository.Relay) {
for _, relay := range relays {
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}
}