34 lines
1.0 KiB
Go
34 lines
1.0 KiB
Go
package message_server
|
|
|
|
import (
|
|
"joylink.club/bj-rtsts-server/message_server/ms_api"
|
|
"joylink.club/bj-rtsts-server/mqtt"
|
|
"joylink.club/bj-rtsts-server/ts/protos/state"
|
|
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
|
|
"joylink.club/ecs"
|
|
)
|
|
|
|
func NewStateMs(vs *memory.VerifySimulation) ms_api.MsgTask {
|
|
return ms_api.NewMonitorTask("仿真状态", func() {
|
|
ecs.WorldStateChangeEvent.Subscribe(vs.World, func(_ ecs.World, e ecs.WorldStateChange) {
|
|
switch e.NewState {
|
|
case ecs.WorldClose:
|
|
mqtt.PubSimulationState(vs.SimulationId, &state.SimulationStatus{
|
|
SimulationId: vs.SimulationId,
|
|
State: state.SimulationStatus_DESTROY,
|
|
})
|
|
case ecs.WorldError:
|
|
mqtt.PubSimulationState(vs.SimulationId, &state.SimulationStatus{
|
|
SimulationId: vs.SimulationId,
|
|
State: state.SimulationStatus_ERROR,
|
|
})
|
|
case ecs.WorldPause:
|
|
mqtt.PubSimulationState(vs.SimulationId, &state.SimulationStatus{
|
|
SimulationId: vs.SimulationId,
|
|
State: state.SimulationStatus_PAUSE,
|
|
})
|
|
}
|
|
})
|
|
})
|
|
}
|