package device_sys import ( "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/component/component_proto" ) // 道岔位置更新系统 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) setTurnoutBs(entry, tp, zdbj.Val, 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) setTurnoutBs(entry, tp, dbj.Val, fbj.Val) } else { setTurnoutBs(entry, tp, dw, fw) } }) } // 设置道岔定表 func setTurnoutBs(entry *ecs.Entry, tp *component_proto.TurnoutPosition, db bool, fb bool) { tp.Db = db && !entry.HasComponent(component.TurnoutFaultSbType) && !entry.HasComponent(component.TurnoutFaultDwsbType) tp.Fb = fb && !entry.HasComponent(component.TurnoutFaultSbType) && !entry.HasComponent(component.TurnoutFaultFwsbType) }