172f65b14c
【调整消息服务代码】 【删除多余代码】 【调整方法、结构体名称】
69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
package memory
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/component/component_proto"
|
|
"joylink.club/rtsssimulation/entity"
|
|
"joylink.club/rtsssimulation/fi"
|
|
|
|
"joylink.club/bj-rtsts-server/dto/request_proto"
|
|
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
|
|
"joylink.club/bj-rtsts-server/ts/protos/state"
|
|
)
|
|
|
|
// 处理道岔操作
|
|
func HandleTurnoutOperation(simulation *VerifySimulation, req *request_proto.TurnoutOperationReq) {
|
|
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &graphicData.Turnout{})
|
|
switch req.Operation {
|
|
case request_proto.Turnout_DC:
|
|
fi.DriveTurnoutDCOn(simulation.World, uid)
|
|
case request_proto.Turnout_CancelDC:
|
|
fi.DriveTurnoutDCOff(simulation.World, uid)
|
|
case request_proto.Turnout_FC:
|
|
fi.DriveTurnoutFCOn(simulation.World, uid)
|
|
case request_proto.Turnout_CancelFC:
|
|
fi.DriveTurnoutFCOff(simulation.World, uid)
|
|
case request_proto.Turnout_SetSB:
|
|
fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_SB)
|
|
case request_proto.Turnout_CancelSB:
|
|
fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_SB)
|
|
case request_proto.Turnout_SetJC:
|
|
fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
|
|
case request_proto.Turnout_CancelJC:
|
|
fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
|
|
default:
|
|
panic(fmt.Sprintf("未知的道岔操作:%s", req.Operation))
|
|
}
|
|
}
|
|
|
|
// 获取全部的道岔状态,动力学使用
|
|
func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
|
|
var switchArr []*state.SwitchState
|
|
turnoutList := sim.Repo.TurnoutList()
|
|
for _, o := range turnoutList {
|
|
s := handlerTurnoutState(sim.World, o.Id())
|
|
if s == nil {
|
|
continue
|
|
}
|
|
s.Id = sim.GetComIdByUid(o.Id())
|
|
switchArr = append(switchArr, s)
|
|
}
|
|
return switchArr
|
|
}
|
|
|
|
func handlerTurnoutState(w ecs.World, uid string) *state.SwitchState {
|
|
entry, ok := entity.GetEntityByUid(w, uid)
|
|
if !ok {
|
|
fmt.Printf("id=%s的道岔不存在", uid)
|
|
return nil
|
|
}
|
|
if !entry.HasComponent(component.TurnoutPositionType) {
|
|
return nil
|
|
}
|
|
pos := component.TurnoutPositionType.Get(entry)
|
|
return &state.SwitchState{Normal: pos.Db, Reverse: pos.Fb, Dw: pos.Dw, Fw: pos.Fw}
|
|
}
|