125 lines
4.2 KiB
Go
125 lines
4.2 KiB
Go
package fi
|
||
|
||
import (
|
||
"fmt"
|
||
"joylink.club/ecs"
|
||
"joylink.club/rtsssimulation/component"
|
||
"joylink.club/rtsssimulation/entity"
|
||
)
|
||
|
||
// AxleSectionDrstDrive 计轴直接复位操作
|
||
//
|
||
// set : true-设置,false-取消
|
||
func AxleSectionDrstDrive(w ecs.World, sectionId string, set bool) error {
|
||
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||
wd := entity.GetWorldData(w)
|
||
sectionModel := wd.Repo.FindPhysicalSection(sectionId)
|
||
if sectionModel == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("区段模型[%s]不存实体", sectionId))
|
||
}
|
||
//
|
||
faDcAxleDeviceEntry := entity.FindAxleManageDevice(wd, sectionModel.CentralizedStation())
|
||
|
||
if faDcAxleDeviceEntry == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]实体不存在", sectionModel.CentralizedStation()))
|
||
}
|
||
faDcAxleDevice := component.AxleManageDeviceType.Get(faDcAxleDeviceEntry)
|
||
axleRuntime := faDcAxleDevice.FindAdr(sectionId)
|
||
if axleRuntime == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]中不存在区段[%s]的计轴设备", sectionModel.CentralizedStation(), sectionId))
|
||
}
|
||
axleRuntime.Drst = set
|
||
//
|
||
return ecs.NewOkEmptyResult()
|
||
})
|
||
return r.Err
|
||
}
|
||
|
||
// AxleSectionPdrstDrive 计轴预复位操作
|
||
//
|
||
// set : true-设置,false-取消
|
||
func AxleSectionPdrstDrive(w ecs.World, sectionId string, set bool) error {
|
||
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||
wd := entity.GetWorldData(w)
|
||
sectionModel := wd.Repo.FindPhysicalSection(sectionId)
|
||
if sectionModel == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("区段模型[%s]不存实体", sectionId))
|
||
}
|
||
//
|
||
faDcAxleDeviceEntry := entity.FindAxleManageDevice(wd, sectionModel.CentralizedStation())
|
||
|
||
if faDcAxleDeviceEntry == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]实体不存在", sectionModel.CentralizedStation()))
|
||
}
|
||
faDcAxleDevice := component.AxleManageDeviceType.Get(faDcAxleDeviceEntry)
|
||
axleRuntime, ok := faDcAxleDevice.Adrs[sectionId]
|
||
if !ok {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]中不存在区段[%s]的计轴设备", sectionModel.CentralizedStation(), sectionId))
|
||
}
|
||
axleRuntime.Pdrst = set
|
||
//
|
||
return ecs.NewOkEmptyResult()
|
||
})
|
||
return r.Err
|
||
}
|
||
|
||
// AxleSectionFaultOccDrive 区段故障占用设置
|
||
//
|
||
// set : true - 设置故障占用;false - 取消故障占用
|
||
func AxleSectionFaultOccDrive(w ecs.World, sectionId string, set bool) error {
|
||
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||
wd := entity.GetWorldData(w)
|
||
sectionModel := wd.Repo.FindPhysicalSection(sectionId)
|
||
if sectionModel == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("区段模型[%s]不存实体", sectionId))
|
||
}
|
||
//
|
||
sectionEntry := wd.EntityMap[sectionId]
|
||
if sectionEntry == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("区段[%s]实体不存在", sectionId))
|
||
}
|
||
axleDevice := component.AxlePhysicalSectionType.Get(sectionEntry)
|
||
if set { //计轴故障设置
|
||
if !sectionEntry.HasComponent(component.AxleSectionFaultTag) {
|
||
sectionEntry.AddComponent(component.AxleSectionFaultTag)
|
||
}
|
||
axleDevice.UpdateCount(1)
|
||
} else { //计轴故障取消
|
||
if sectionEntry.HasComponent(component.AxleSectionFaultTag) {
|
||
sectionEntry.RemoveComponent(component.AxleSectionFaultTag)
|
||
}
|
||
axleDevice.UpdateCount(0)
|
||
}
|
||
//
|
||
return ecs.NewOkEmptyResult()
|
||
})
|
||
return r.Err
|
||
}
|
||
|
||
// AxleSectionTrainDrive 计轴区段内车进入出清设置
|
||
//
|
||
// trainIn : true - 计轴区段内有车;false-计轴区段出清
|
||
func AxleSectionTrainDrive(w ecs.World, sectionId string, trainIn bool) error {
|
||
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||
wd := entity.GetWorldData(w)
|
||
sectionModel := wd.Repo.FindPhysicalSection(sectionId)
|
||
if sectionModel == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("区段模型[%s]不存实体", sectionId))
|
||
}
|
||
//
|
||
sectionEntry := wd.EntityMap[sectionId]
|
||
if sectionEntry == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("区段[%s]实体不存在", sectionId))
|
||
}
|
||
axleDevice := component.AxlePhysicalSectionType.Get(sectionEntry)
|
||
if trainIn {
|
||
axleDevice.UpdateCount(1)
|
||
} else {
|
||
axleDevice.UpdateCount(0)
|
||
}
|
||
//
|
||
return ecs.NewOkEmptyResult()
|
||
})
|
||
return r.Err
|
||
}
|