rts-sim-module/deprecated/entities/relay_entity.go
walker 0bba8f0934 删除donburi包引用
修改filter导入为从ecs项目导入
整理包结构,将弃用的包放入deprecated文件中
2023-10-09 11:17:25 +08:00

38 lines
998 B
Go

package entities
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/deprecated/simulation"
"joylink.club/rtsssimulation/deprecated/system"
"joylink.club/rtsssimulation/repository"
)
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}
}