rts-sim-module/entity/station.go

53 lines
1.2 KiB
Go

package entity
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
func LoadStations(w ecs.World) error {
data := GetWorldData(w)
stations := data.Repo.StationList()
for _, station := range stations {
err := NewSFAEntity(w, station)
if err != nil {
return err
}
err = NewDLQEntity(w, station)
if err != nil {
return err
}
err = NewDYPEntity(w, station)
if err != nil {
return err
}
err = NewLsEntity(w, station)
if err != nil {
return err
}
entry := NewStationEntity(w, station.Id(), data)
err = LoadSPKEntity(w, entry, station.SpksComponents(), data) // 人员防护
if err != nil {
return fmt.Errorf("车站【%s】人员防护error:%s", station.Id(), err.Error())
}
err = LoadEMPEntity(w, entry, station.EmpGroups(), data) // 紧急停车
if err != nil {
return fmt.Errorf("车站【%s】紧急停车error:%s", station.Id(), err.Error())
}
}
return nil
}
// 新建车站实体
func NewStationEntity(w ecs.World, uid string, worldData *component.WorldData) *ecs.Entry {
entry, ok := worldData.EntityMap[uid]
if !ok {
entry = w.Entry(w.Create(component.UidType))
component.UidType.SetValue(entry, component.Uid{Id: uid})
worldData.EntityMap[uid] = entry
}
return entry
}