rts-sim-module/entity/station.go

42 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"
"joylink.club/rtsssimulation/repository"
2023-10-17 15:05:13 +08:00
)
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 {
for _, ecg := range station.ComponentGroups() {
if ecg.Code() == "LS" {
for _, ele := range ecg.Components() {
NewRelayEntity(w, ele.(*repository.Relay), data.EntityMap)
}
}
}
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
}