package device_sys import ( "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/consts" ) type AsdSys struct { query *ecs.Query } func NewAsdSys() *AsdSys { return &AsdSys{ query: ecs.NewQuery(filter.Contains(component.AsdMotorStateType, component.TwoPositionTransformType)), } } func (s *AsdSys) Update(world ecs.World) { var speed int32 = consts.TwoPosMax / 4 s.query.Each(world, func(entry *ecs.Entry) { //设置两位置转换速度 psdMotorState := component.AsdMotorStateType.Get(entry) twoPosition := component.TwoPositionTransformType.Get(entry) asdState := component.AsdStateType.Get(entry) pos := twoPosition.Pos if entry.HasComponent(component.AsdCannotOpenTag) { pos = consts.TwoPosMin speed = 0 psdMotorState.TD = false } else if entry.HasComponent(component.AsdCannotCloseTag) { pos = consts.TwoPosMax speed = 0 psdMotorState.TD = false } else if psdMotorState.TD { if psdMotorState.KM { if pos == consts.TwoPosMax { psdMotorState.TD = false twoPosition.Speed = 0 } else { twoPosition.Speed = speed } } else { if pos == consts.TwoPosMin { //关门到位后断电 psdMotorState.TD = false twoPosition.Speed = 0 } else { twoPosition.Speed = -speed } } } //门关继电器状态 psdMotorState.MG = pos == consts.TwoPosMin asdState.Mgj = psdMotorState.MG //滑动门状态 if pos == consts.TwoPosMax { asdState.Kmdw = true asdState.Gmdw = false } else if pos == consts.TwoPosMin { asdState.Kmdw = false asdState.Gmdw = true } else { asdState.Kmdw = false asdState.Gmdw = false } }) }