rts-sim-module/entity/station.go

47 lines
1.1 KiB
Go

package entity
import (
"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
}
entry := NewStationEntity(w, station.Id(), data)
if station.GetIbpSpk() != nil { // 人员防护
LoadSPKEntity(w, entry, station.GetIbpSpk(), data)
}
if station.GetIbpEmp() != nil { // 紧急停车
LoadEMPEntity(w, entry, station.GetIbpEmp(), data)
}
}
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
}