2023-09-15 13:07:31 +08:00
|
|
|
package entities
|
|
|
|
|
|
|
|
import (
|
|
|
|
"joylink.club/ecs"
|
2023-10-09 11:17:25 +08:00
|
|
|
"joylink.club/rtsssimulation/deprecated/simulation"
|
|
|
|
"joylink.club/rtsssimulation/deprecated/system"
|
2023-09-25 10:34:21 +08:00
|
|
|
"joylink.club/rtsssimulation/repository"
|
2023-09-15 13:07:31 +08:00
|
|
|
)
|
|
|
|
|
2023-09-27 17:12:15 +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
|
|
|
|
}
|
2023-09-25 10:34:21 +08:00
|
|
|
|
|
|
|
func CreateRelayEntries(world ecs.World, relays []*repository.Relay) {
|
|
|
|
for _, relay := range relays {
|
|
|
|
CreateRelayEntity(world, relay.Id())
|
|
|
|
}
|
|
|
|
}
|
2023-09-27 17:12:15 +08:00
|
|
|
|
|
|
|
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}
|
|
|
|
}
|