2023-10-31 11:30:17 +08:00
|
|
|
|
package entity
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
2023-10-31 17:39:10 +08:00
|
|
|
|
"strings"
|
2023-10-31 11:30:17 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-10-31 15:55:16 +08:00
|
|
|
|
// LoadAxlePhysicalSections 加载计轴区段
|
|
|
|
|
func LoadAxlePhysicalSections(w ecs.World) error {
|
|
|
|
|
data := GetWorldData(w)
|
|
|
|
|
sections := data.Repo.PhysicalSectionList()
|
|
|
|
|
for _, section := range sections {
|
|
|
|
|
if is, se := section.IsAxleSection(); se == nil && is {
|
2023-10-31 17:39:10 +08:00
|
|
|
|
if len(strings.TrimSpace(section.CentralizedStation())) == 0 {
|
|
|
|
|
return fmt.Errorf("区段[%s]未设置所属集中站", section.Id())
|
|
|
|
|
}
|
|
|
|
|
fadcDeviceId := CreateFaDcAxleDeviceId(section.CentralizedStation())
|
2023-10-31 15:55:16 +08:00
|
|
|
|
fadcDeviceEntry, find := data.EntityMap[fadcDeviceId]
|
|
|
|
|
if !find {
|
|
|
|
|
fadcDeviceEntry = createFadcDeviceEntity(w, section, data)
|
|
|
|
|
data.EntityMap[fadcDeviceId] = fadcDeviceEntry
|
|
|
|
|
}
|
|
|
|
|
fadcDevice := component.FaDcAxleDeviceType.Get(fadcDeviceEntry)
|
|
|
|
|
counter := createAxleCounterEntity(w, section, data)
|
|
|
|
|
axleSec := createAxleSectionEntity(w, section, data)
|
|
|
|
|
fadcDevice.AddAxleSection(counter, axleSec)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 联锁集中站计轴管理设备实体
|
|
|
|
|
func createFadcDeviceEntity(w ecs.World, axleSection *repository.PhysicalSection, worldData *component.WorldData) *ecs.Entry {
|
2023-10-31 17:39:10 +08:00
|
|
|
|
uid := CreateFaDcAxleDeviceId(axleSection.CentralizedStation())
|
2023-10-31 11:30:17 +08:00
|
|
|
|
entry, ok := worldData.EntityMap[uid]
|
|
|
|
|
if !ok {
|
2023-10-31 15:55:16 +08:00
|
|
|
|
entry = w.Entry(w.Create(component.UidType, component.FaDcAxleDeviceType))
|
2023-10-31 11:30:17 +08:00
|
|
|
|
//
|
|
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
2023-10-31 15:55:16 +08:00
|
|
|
|
component.FaDcAxleDeviceType.Set(entry, &component.FaDcAxleDevice{CounterMap: make(map[string]*ecs.Entry)})
|
2023-10-31 11:30:17 +08:00
|
|
|
|
//
|
|
|
|
|
worldData.EntityMap[uid] = entry
|
|
|
|
|
}
|
|
|
|
|
return entry
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 15:55:16 +08:00
|
|
|
|
// 计轴区段实体
|
|
|
|
|
func createAxleSectionEntity(w ecs.World, axleSection *repository.PhysicalSection, worldData *component.WorldData) *ecs.Entry {
|
|
|
|
|
uid := axleSection.Id()
|
2023-10-31 11:30:17 +08:00
|
|
|
|
entry, ok := worldData.EntityMap[uid]
|
|
|
|
|
if !ok {
|
2023-10-31 15:55:16 +08:00
|
|
|
|
entry = w.Entry(w.Create(component.UidType, component.AxleSectionType, component.AxleSectionFaultType))
|
2023-10-31 11:30:17 +08:00
|
|
|
|
//
|
|
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
2023-10-31 15:55:16 +08:00
|
|
|
|
component.AxleSectionType.Set(entry, &component.AxleSection{Occ: false})
|
|
|
|
|
component.AxleSectionFaultType.Set(entry, &component.AxleSectionFault{SectionFault: false})
|
2023-10-31 11:30:17 +08:00
|
|
|
|
//
|
|
|
|
|
worldData.EntityMap[uid] = entry
|
|
|
|
|
}
|
|
|
|
|
return entry
|
|
|
|
|
}
|
2023-10-31 15:55:16 +08:00
|
|
|
|
|
|
|
|
|
// 计轴器实体
|
|
|
|
|
func createAxleCounterEntity(w ecs.World, axleSection *repository.PhysicalSection, worldData *component.WorldData) *ecs.Entry {
|
|
|
|
|
entry := w.Entry(w.Create(component.AxleCounterType, component.AxleCounterRuntimeType, component.AxleSectionFlag))
|
|
|
|
|
component.AxleCounterType.Set(entry, component.NewAxleCounter())
|
|
|
|
|
component.AxleCounterRuntimeType.Set(entry, &component.AxleCounterRuntime{Rac: false, Rjo: false, Rjt: false, Drst: false, Pdrst: false, DoingPdrst: false})
|
|
|
|
|
component.AxleSectionFlag.SetValue(entry, component.Uid{Id: axleSection.Id()})
|
|
|
|
|
return entry
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 17:39:10 +08:00
|
|
|
|
// CreateFaDcAxleDeviceId 设备集中站计轴管理设备id(通过联锁集中站centralizedStation来构建)
|
|
|
|
|
func CreateFaDcAxleDeviceId(centralizedStation string) string {
|
2023-10-31 15:55:16 +08:00
|
|
|
|
return fmt.Sprintf("fadc-axle-device-%s", centralizedStation)
|
2023-10-31 11:30:17 +08:00
|
|
|
|
}
|