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 } }) }