rts-sim-module/sys/common_sys/counterdown.go
walker c56feb3bdf 道岔电路驱动系统实现
仿真单例组件定义(暂定)
仿真道岔相关实体构建(未完)
2023-09-27 18:39:18 +08:00

33 lines
579 B
Go

package common_sys
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
type CounterDownSys struct {
query *ecs.Query
}
func NewCounterDownSys() *CounterDownSys {
return &CounterDownSys{
query: ecs.NewQuery(filter.Contains(component.CounterDownType)),
}
}
// 更新
func (c *CounterDownSys) Update(w ecs.World) {
c.query.Each(w, func(entry *ecs.Entry) {
cd := component.CounterDownType.Get(entry)
if cd.Val > 0 {
v := cd.Val - cd.Step
if v < 0 {
cd.Val = 0
} else {
cd.Val = v
}
}
})
}