31 lines
898 B
Go
31 lines
898 B
Go
package message_server
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"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(fmt.Sprintf("仿真[%s]状态", vs.SimulationId), func() {
|
|
ecs.WorldStateChangeEvent.Subscribe(vs.World, func(_ ecs.World, e ecs.WorldStateChange) {
|
|
s := &state.SimulationStatus{SimulationId: vs.SimulationId}
|
|
switch e.NewState {
|
|
case ecs.WorldClosed:
|
|
s.State = state.SimulationStatus_DESTROY
|
|
case ecs.WorldError:
|
|
s.State = state.SimulationStatus_ERROR
|
|
case ecs.WorldPause:
|
|
s.State = state.SimulationStatus_PAUSE
|
|
default:
|
|
return
|
|
}
|
|
mqtt.GetMsgClient().PubSimulationState(vs.SimulationId, s)
|
|
})
|
|
})
|
|
}
|