package system import ( "fmt" "github.com/yohamta/donburi/filter" "joylink.club/ecs" "joylink.club/rtsssimulation/components" ) // 调试时显示一些信息 type DebugSystem struct { } func NewDebugSystem() *DebugSystem { return &DebugSystem{} } // world 执行 func (me *DebugSystem) Update(w ecs.World) { debugPsd(w) } // 屏蔽门状态 func debugPsd(w ecs.World) { psdQuery = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent)) psdQuery.Each(w, func(e *ecs.Entry) { psdId := components.DeviceIdentityComponent.Get(e).Id psdState := components.PsdStateComponent.Get(e) psdTag := components.EntityTagHandlerComponent.Get(e).Tag fmt.Printf("屏蔽门[%s] ,全关=%t ,全开=%t ,互锁解除=%t > ", psdId, psdState.AllClosed, psdState.AllOpened, psdState.InterlockReleased) // psdCellQuery := ecs.NewQuery(filter.Contains(psdTag, components.PsdCellStateComponent)) psdCellQuery.Each(w, func(e *ecs.Entry) { psdCellId := components.DeviceIdentityComponent.Get(e).Id psdCellState := components.PsdCellStateComponent.Get(e) // fmt.Printf("|| cell[%s] ,closeRate=%d ", psdCellId, psdCellState.CloseRate) if e.HasComponent(components.PsdCellOperatingComponent) { psdCellOpt := components.PsdCellOperatingComponent.Get(e) if psdCellOpt.CloseOperate { fmt.Printf("== 关门操作中,剩余移动距离=%d", psdCellOpt.RemainingDistance) } else { fmt.Printf("== 开门操作中,剩余移动距离=%d", psdCellOpt.RemainingDistance) } } }) // fmt.Println() }) } // 显示信号机状态 func debugSignal(w ecs.World) { siganlQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SignalStateComponent)) siganlQuery.Each(w, func(e *ecs.Entry) { id := components.DeviceIdentityComponent.Get(e).Id state := components.SignalStateComponent.Get(e) fmt.Printf("==>>信号机[%s],显示=%d\n", id, state.Display) }) } // 显示道岔状态 func debugSwitch(w ecs.World) { switchesQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchStateComponent)) switchesQuery.Each(w, func(e *ecs.Entry) { id := components.DeviceIdentityComponent.Get(e).Id state := components.SwitchStateComponent.Get(e) fmt.Printf("==>>道岔[%s] ,定操Relay=%t ,反操Relay=%t ,定表Relay=%t ,反表Relay=%t ,", id, state.NormalRelay, state.ReverseRelay, state.NormalTable, state.ReverseTable) if e.HasComponent(components.SwitchNRRelayOperatingComponent) { nrOperation := components.SwitchNRRelayOperatingComponent.Get(e) if nrOperation.Normal { fmt.Printf("定操动作Start=%t ,剩余时间=%d ,吸合动作=%t ,", nrOperation.Start, nrOperation.OperateTime, nrOperation.Close) } else { fmt.Printf("反操动作Start=%t ,剩余时间=%d ,吸合动作=%t ,", nrOperation.Start, nrOperation.OperateTime, nrOperation.Close) } } if e.HasComponent(components.SwitchTurnOperatingComponent) { turnOperation := components.SwitchTurnOperatingComponent.Get(e) fmt.Printf("转动操作Start=%t ,转动到定位=%t ,剩余时间=%d", turnOperation.Start, turnOperation.TurnNormal, turnOperation.OperateTime) } fmt.Println() }) }