38 lines
976 B
Go
38 lines
976 B
Go
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)
|
|
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}
|
|
}
|