2023-10-17 15:05:13 +08:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
2023-12-07 10:54:55 +08:00
|
|
|
"fmt"
|
|
|
|
|
2023-10-17 15:05:13 +08:00
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
)
|
|
|
|
|
|
|
|
func LoadStations(w ecs.World) error {
|
|
|
|
data := GetWorldData(w)
|
|
|
|
stations := data.Repo.StationList()
|
2023-11-06 17:32:34 +08:00
|
|
|
// 加载零散组合继电器
|
2023-10-17 15:05:13 +08:00
|
|
|
for _, station := range stations {
|
2023-11-09 14:26:08 +08:00
|
|
|
err := NewSFAEntity(w, station)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-11-06 17:32:34 +08:00
|
|
|
}
|
2023-11-09 14:26:08 +08:00
|
|
|
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)
|
2023-12-06 16:43:29 +08:00
|
|
|
err = LoadSPKEntity(w, entry, station.SpksComponents(), data) // 人员防护
|
|
|
|
if err != nil {
|
2023-12-07 10:54:55 +08:00
|
|
|
return fmt.Errorf("车站【%s】人员防护error:%s", station.Id(), err.Error())
|
2023-10-17 15:05:13 +08:00
|
|
|
}
|
2023-12-06 16:43:29 +08:00
|
|
|
err = LoadEMPEntity(w, entry, station.EmpGroups(), data) // 紧急停车
|
|
|
|
if err != nil {
|
2023-12-07 10:54:55 +08:00
|
|
|
return fmt.Errorf("车站【%s】紧急停车error:%s", station.Id(), err.Error())
|
2023-10-17 15:05:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|