rts-sim-module/sys/device_sys/turnout.go

39 lines
800 B
Go

package device_sys
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
// 道岔位置更新系统
type TurnoutSys struct {
query *ecs.Query
}
func NewTurnoutSys() *TurnoutSys {
return &TurnoutSys{
query: ecs.NewQuery(filter.Contains(component.TurnoutPositionType, component.TurnoutZzjType)),
}
}
func (s *TurnoutSys) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
zzjs := component.TurnoutZzjType.Get(entry)
tp := component.TurnoutPositionType.Get(entry)
dw := true
fw := true
for _, zzj := range zzjs.ZzjList {
state := component.ZzjStateType.Get(zzj)
if !(!state.JD12 && !state.JD34) {
dw = false
}
if !(state.JD12 && state.JD34) {
fw = false
}
}
tp.Dw = dw
tp.Fw = fw
})
}