rts-sim-testing-service/ts/simulation/wayside/memory/wayside_memory_transponder.go

33 lines
1.0 KiB
Go
Raw Normal View History

package memory
import (
"fmt"
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/sys_error"
"joylink.club/bj-rtsts-server/ts"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/component_proto"
"joylink.club/rtsssimulation/entity"
)
func TransponderMove(req *dto.TransponderMoveReqDto) error {
simulation := ts.GetSimulation(req.SimulationId)
worldData := entity.GetWorldData(simulation.World)
link := worldData.Repo.FindLink(simulation.uidMap[req.LinkId].Uid)
if link == nil {
panic(sys_error.New(fmt.Sprintf("未找到[id:%s]的Link", link.Id())))
}
if req.Offset > link.Length() {
panic(sys_error.New(fmt.Sprintf("偏移量[%d]超出Link长度", req.Offset)))
}
te, ok := entity.GetEntityByUid(simulation.World, req.TransponderId)
if !ok {
panic(sys_error.New(fmt.Sprintf("没有[id:%s]的应答器", req.TransponderId)))
}
component.LinkPositionType.SetValue(te, component_proto.LinkPosition{
LinkId: req.LinkId,
Offset: req.Offset,
})
return nil
}