rts-sim-module/system/device_sys/relay.go

34 lines
862 B
Go

package device_sys
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
type RelaySys struct {
query *ecs.Query
}
func NewRelaySys() *RelaySys {
return &RelaySys{
query: ecs.NewQuery(filter.Contains(component.RelayTag, component.RelayActionRequestType, component.BitStateType)),
}
}
func (rs *RelaySys) Update(w ecs.World) {
rs.query.Each(w, func(entry *ecs.Entry) {
// 查询实体是哪种继电器类型,根据继电器类型处理继电器吸起落下逻辑(暂时先简化直接处理)
req := component.RelayActionRequestType.Get(entry)
state := component.BitStateType.Get(entry)
if req.Xq {
state.Val = true
} else {
state.Val = false
}
if req.Xq == state.Val { // 执行完毕,删除请求组件
entry.RemoveComponent(component.RelayActionRequestType)
}
})
}