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

57 lines
1.3 KiB
Go

package device_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"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
// 表示
if entry.HasComponent(component.Zdj9TwoElectronicType) {
zdj9 := component.Zdj9TwoElectronicType.Get(entry)
zdbj := component.BitStateType.Get(zdj9.TDC_ZDBJ)
zfbj := component.BitStateType.Get(zdj9.TDC_ZFBJ)
tp.Db = zdbj.Val
tp.Fb = zfbj.Val
} else if entry.HasComponent(component.Zdj9OneElectronicType) {
zdj9 := component.Zdj9OneElectronicType.Get(entry)
dbj := component.BitStateType.Get(zdj9.TDFJ_DBJ)
fbj := component.BitStateType.Get(zdj9.TDFJ_FBJ)
tp.Db = dbj.Val
tp.Fb = fbj.Val
} else {
tp.Db = dw
tp.Fb = fw
}
})
}