rts-sim-module/entity/axle_section.go

35 lines
1.1 KiB
Go
Raw Normal View History

2023-10-31 11:30:17 +08:00
package entity
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
"unsafe"
2023-10-31 11:30:17 +08:00
)
var AxleSectionBaseComponentTypes = []ecs.IComponentType{component.UidType, component.AxleSectionTag, component.AxleManagerType}
2023-11-06 14:35:32 +08:00
2023-10-31 15:55:16 +08:00
// LoadAxlePhysicalSections 加载计轴区段
func LoadAxlePhysicalSections(w ecs.World) error {
wd := GetWorldData(w)
sections := wd.Repo.PhysicalSectionList()
2023-10-31 15:55:16 +08:00
for _, section := range sections {
if is, err := section.IsAxleSection(); err == nil && is {
entry := w.Entry(w.Create(AxleSectionBaseComponentTypes...))
component.UidType.SetValue(entry, component.Uid{Id: section.Id()})
for _, group := range section.ComponentGroups() {
for _, ec := range group.Components() {
if ec.Code() == "GJ" {
relay := ec.(*repository.Relay)
gjEntry := NewRelayEntity(w, relay, wd.EntityMap)
circuit := &component.AxleSectionCircuit{GJ: gjEntry}
entry.AddComponent(component.AxleSectionCircuitType, unsafe.Pointer(circuit))
}
}
}
wd.EntityMap[section.Id()] = entry
}
2023-10-31 11:30:17 +08:00
}
return nil
2023-10-31 11:30:17 +08:00
}