33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
|
package entity
|
||
|
|
||
|
import (
|
||
|
"joylink.club/ecs"
|
||
|
"joylink.club/rtsssimulation/component"
|
||
|
"joylink.club/rtsssimulation/repository"
|
||
|
)
|
||
|
|
||
|
// LoadAxleSections 加载计轴区段
|
||
|
func LoadAxleSections(w ecs.World) error {
|
||
|
data := GetWorldData(w)
|
||
|
sections := data.Repo.PhysicalSectionList()
|
||
|
for _, section := range sections {
|
||
|
if is, se := section.IsAxleSection(); se == nil && is {
|
||
|
newAxleSectionEntity(w, section, data)
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
func newAxleSectionEntity(w ecs.World, axleSection *repository.PhysicalSection, worldData *component.WorldData) *ecs.Entry {
|
||
|
uid := axleSection.Id()
|
||
|
entry, ok := worldData.EntityMap[uid]
|
||
|
if !ok {
|
||
|
entry = w.Entry(w.Create(component.UidType, component.AxleSectionTag, component.AxleSectionStateType, component.AxleSectionDeviceType, component.AxleSectionRuntimeType))
|
||
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
||
|
component.AxleSectionStateType.Set(entry, component.NewAxleSectionState())
|
||
|
component.AxleSectionDeviceType.Set(entry, component.NewAxleSectionDevice())
|
||
|
component.AxleSectionRuntimeType.Set(entry, component.NewAxleSectionRuntime())
|
||
|
worldData.EntityMap[uid] = entry
|
||
|
}
|
||
|
return entry
|
||
|
}
|