91 lines
3.2 KiB
Go
91 lines
3.2 KiB
Go
package memory
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
|
"joylink.club/bj-rtsts-server/dto/request_proto"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
)
|
|
|
|
// 处理道岔操作
|
|
func HandlePointsOperation(simulation *VerifySimulation, req *request_proto.PointsOperationReq) error {
|
|
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.Turnout{})
|
|
var err error
|
|
// 道岔强制位置
|
|
err = setTurnoutForce(simulation.World, uid, req.Param.ForcePosition)
|
|
// switch req.Operation {
|
|
// case request_proto.Turnout_DC:
|
|
// err = fi.DriveTurnoutDCOn(simulation.World, uid)
|
|
// case request_proto.Turnout_CancelDC:
|
|
// err = fi.DriveTurnoutDCOff(simulation.World, uid)
|
|
// case request_proto.Turnout_FC:
|
|
// err = fi.DriveTurnoutFCOn(simulation.World, uid)
|
|
// case request_proto.Turnout_CancelFC:
|
|
// err = fi.DriveTurnoutFCOff(simulation.World, uid)
|
|
// case request_proto.Turnout_SetSB:
|
|
// err = fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_SB)
|
|
// case request_proto.Turnout_CancelSB:
|
|
// err = fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_SB)
|
|
// case request_proto.Turnout_SetJC:
|
|
// err = fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
|
|
// case request_proto.Turnout_CancelJC:
|
|
// err = fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
|
|
// case request_proto.Turnout_ForceDw:
|
|
// err = fi.ForceTurnoutDw(simulation.World, uid)
|
|
// case request_proto.Turnout_ForceFw:
|
|
// err = fi.ForceTurnoutFw(simulation.World, uid)
|
|
// case request_proto.Turnout_CancelForce:
|
|
// err = fi.CancelTurnoutForce(simulation.World, uid)
|
|
// default:
|
|
// panic(fmt.Sprintf("未知的道岔操作:%s", req.Operation))
|
|
// }
|
|
return err
|
|
}
|
|
|
|
func setTurnoutForce(w ecs.World, uid string, force request_proto.Points_Force) error {
|
|
return handleEntityState(w, uid, func(e *ecs.Entry) error {
|
|
if e.HasComponent(component.Zdj9TwoElectronicType) { // ZDJ9双机牵引道岔
|
|
zdj92 := component.Zdj9TwoElectronicType.Get(e)
|
|
switch force {
|
|
case request_proto.Points_FP_DW:
|
|
setRelayForce(zdj92.TDC_ZFBJ, false)
|
|
setRelayForce(zdj92.TDC_ZDBJ, true)
|
|
case request_proto.Points_FP_FW:
|
|
setRelayForce(zdj92.TDC_ZDBJ, false)
|
|
setRelayForce(zdj92.TDC_ZFBJ, true)
|
|
case request_proto.Points_FP_SB:
|
|
setRelayForce(zdj92.TDC_ZDBJ, false)
|
|
setRelayForce(zdj92.TDC_ZFBJ, false)
|
|
case request_proto.Points_FP_NONE:
|
|
cancelRelayForce(zdj92.TDC_ZDBJ)
|
|
cancelRelayForce(zdj92.TDC_ZFBJ)
|
|
default:
|
|
return fmt.Errorf("未知的道岔强制位置参数:%s", force)
|
|
}
|
|
} else {
|
|
return fmt.Errorf("未知的道岔牵引类型,无法设置强制位置")
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func handleEntityState(w ecs.World, uid string, handler func(e *ecs.Entry) error) error {
|
|
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
|
wd := entity.GetWorldData(w)
|
|
entry, ok := wd.EntityMap[uid]
|
|
if ok {
|
|
err := handler(entry)
|
|
if err != nil {
|
|
return ecs.NewErrResult(err)
|
|
}
|
|
} else {
|
|
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的实体", uid))
|
|
}
|
|
return ecs.NewOkEmptyResult()
|
|
})
|
|
return result.Err
|
|
}
|