rts-sim-module/entity/station.go

47 lines
1.1 KiB
Go
Raw Normal View History

2023-10-17 15:05:13 +08:00
package entity
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
func LoadStations(w ecs.World) error {
data := GetWorldData(w)
stations := data.Repo.StationList()
// 加载零散组合继电器
2023-10-17 15:05:13 +08:00
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
}
2023-10-17 15:05:13 +08:00
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
}