rts-sim-module/entity/station.go

42 lines
1.1 KiB
Go

package entity
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
)
func LoadStations(w ecs.World) error {
data := GetWorldData(w)
stations := data.Repo.StationList()
// 加载零散组合继电器
for _, station := range stations {
for _, ecg := range station.ComponentGroups() {
if ecg.Code() == "LS" {
for _, ele := range ecg.Components() {
NewRelayEntity(w, ele.(*repository.Relay), data.EntityMap)
}
}
}
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
}