【创建车站实体】
This commit is contained in:
parent
3d3d7dabe7
commit
8d9ea2a084
@ -9,13 +9,6 @@ import (
|
||||
"joylink.club/rtsssimulation/repository/model/proto"
|
||||
)
|
||||
|
||||
// 创建IBP实体
|
||||
func NewIBPEntity(w ecs.World, ibp *repository.IBP, entityMap map[string]*ecs.Entry) {
|
||||
entry := w.Entry(w.Create(component.IBP))
|
||||
loadSPKEntity(w, entry, ibp.Spk, entityMap)
|
||||
loadEMPEntity(w, entry, ibp.Emp, entityMap)
|
||||
}
|
||||
|
||||
// 创建按钮实体
|
||||
func NewButtonEntity(w ecs.World, data *repository.Button, entityMap map[string]*ecs.Entry) *ecs.Entry {
|
||||
uid := data.Id()
|
||||
@ -56,7 +49,8 @@ func NewAlarmEntity(w ecs.World, alarm *repository.Alarm, entityMap map[string]*
|
||||
}
|
||||
|
||||
// 构建人员防护实体
|
||||
func loadSPKEntity(w ecs.World, entry *ecs.Entry, spkData *repository.IBPRefMap, entityMap map[string]*ecs.Entry) error {
|
||||
func LoadSPKEntity(w ecs.World, entry *ecs.Entry, spkData *repository.IBPRefMap, worldData *component.WorldData) error {
|
||||
entityMap := worldData.EntityMap
|
||||
spk := &component.SpkElectronic{}
|
||||
// 按钮组
|
||||
for _, btn := range spkData.Buttons() {
|
||||
@ -118,7 +112,8 @@ func setSpkDefault(spk *component.SpkElectronic) {
|
||||
}
|
||||
|
||||
// 构建紧急关闭实体
|
||||
func loadEMPEntity(w ecs.World, entry *ecs.Entry, spkData *repository.IBPRefMap, entityMap map[string]*ecs.Entry) error {
|
||||
func LoadEMPEntity(w ecs.World, entry *ecs.Entry, spkData *repository.IBPRefMap, worldData *component.WorldData) error {
|
||||
entityMap := worldData.EntityMap
|
||||
emp := &component.EmpElectronic{}
|
||||
// 按钮组
|
||||
for _, btn := range spkData.Buttons() {
|
||||
|
@ -24,5 +24,10 @@ func Load(w ecs.World, repo *repository.Repository) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 加载车站实体
|
||||
err = LoadStations(w)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
32
entity/station.go
Normal file
32
entity/station.go
Normal file
@ -0,0 +1,32 @@
|
||||
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 {
|
||||
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
|
||||
}
|
@ -5,7 +5,7 @@ type IBP struct {
|
||||
Emp *IBPRefMap
|
||||
}
|
||||
|
||||
func NewIBP(id string) *IBP {
|
||||
func NewIBP() *IBP {
|
||||
return &IBP{
|
||||
Spk: &IBPRefMap{
|
||||
buttonMap: make(map[string]*Button),
|
||||
|
@ -1,7 +1,6 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"joylink.club/rtsssimulation/repository/model/proto"
|
||||
@ -152,6 +151,14 @@ func (repo *Repository) PsdList() []*Psd {
|
||||
return list
|
||||
}
|
||||
|
||||
func (repo *Repository) StationList() []*Station {
|
||||
var list []*Station
|
||||
for _, model := range repo.stationMap {
|
||||
list = append(list, model)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func (repo *Repository) FindModel(deviceId string, deviceType proto.DeviceType) (Identity, error) {
|
||||
switch deviceType {
|
||||
case proto.DeviceType_DeviceType_PhysicalSection:
|
||||
@ -171,7 +178,7 @@ func (repo *Repository) FindModel(deviceId string, deviceType proto.DeviceType)
|
||||
case proto.DeviceType_DeviceType_Link:
|
||||
return repo.linkMap[deviceId], nil
|
||||
default:
|
||||
return nil, errors.New(fmt.Sprintf("仓库中不存在[%s]类型的模型", deviceType))
|
||||
return nil, fmt.Errorf("仓库中不存在[%s]类型的模型", deviceType)
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,7 +230,7 @@ func (repo *Repository) addKilometerConvert(kc *proto.KilometerConvert) {
|
||||
func (repo *Repository) getKilometerConvert(cs1, cs2 string) (*proto.KilometerConvert, error) {
|
||||
convert := repo.kilometerConvertMap[buildKilometerConvertKey(cs1, cs2)]
|
||||
if convert == nil {
|
||||
return nil, errors.New(fmt.Sprintf("没有[%s-%s]的公里标转换数据", cs1, cs2))
|
||||
return nil, fmt.Errorf("没有[%s-%s]的公里标转换数据", cs1, cs2)
|
||||
}
|
||||
return convert, nil
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package repository
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
@ -94,6 +95,18 @@ func buildModels(source *proto.Repository, repository *Repository) {
|
||||
m := newPsd(protoData.Id)
|
||||
repository.psdMap[m.Id()] = m
|
||||
}
|
||||
for _, protoData := range source.Lights {
|
||||
m := NewLight(protoData.Id, protoData.Code)
|
||||
repository.lightMap[m.Id()] = m
|
||||
}
|
||||
for _, protoData := range source.Alarms {
|
||||
m := NewAlarm(protoData.Id, protoData.Code)
|
||||
repository.alarmMap[m.Id()] = m
|
||||
}
|
||||
for _, protoData := range source.Stations {
|
||||
m := NewStation(protoData.Id, protoData.Code)
|
||||
repository.stationMap[m.Id()] = m
|
||||
}
|
||||
}
|
||||
|
||||
func buildModelRelationship(source *proto.Repository, repository *Repository) error {
|
||||
@ -121,6 +134,10 @@ func buildModelRelationship(source *proto.Repository, repository *Repository) er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = buildStationRelationShip(source, repository)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -760,3 +777,42 @@ func sectionalCurvatureRelateLink(repo *Repository) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildStationRelationShip(source *proto.Repository, repo *Repository) error {
|
||||
for _, protoData := range source.Stations {
|
||||
station, ok := repo.stationMap[protoData.Id]
|
||||
if !ok {
|
||||
return fmt.Errorf("缺失车站[%s]", protoData.Id)
|
||||
}
|
||||
if len(protoData.ElectronicGroup) == 0 {
|
||||
continue
|
||||
}
|
||||
for _, ref := range protoData.ElectronicGroup {
|
||||
switch ref.Code {
|
||||
case "EMP":
|
||||
bindIbpDevice(repo, ref.Components, station.GetIbpEmp())
|
||||
case "SPKS":
|
||||
bindIbpDevice(repo, ref.Components, station.GetIbpSpk())
|
||||
default:
|
||||
slog.Warn("车站实体未实现【%s】绑定逻辑", ref.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 将设备绑入IBP
|
||||
func bindIbpDevice(repo *Repository, comps []*proto.ElectronicComponent, refMap *IBPRefMap) {
|
||||
for _, data := range comps {
|
||||
switch data.DeviceType {
|
||||
case proto.DeviceType_DeviceType_Alarm:
|
||||
refMap.AddAlarm(repo.alarmMap[data.Id])
|
||||
case proto.DeviceType_DeviceType_Button:
|
||||
refMap.AddButton(repo.buttonMap[data.Id])
|
||||
case proto.DeviceType_DeviceType_Relay:
|
||||
refMap.AddRelay(repo.relayMap[data.Id])
|
||||
default:
|
||||
slog.Warn("IBP未绑定【%s】类型设备", data.DeviceType.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,22 @@ import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
type Station struct {
|
||||
Identity
|
||||
code string
|
||||
componentGroups []*ElectronicComponentGroup
|
||||
code string
|
||||
ibp *IBP
|
||||
}
|
||||
|
||||
func NewStation(id, code string) *Station {
|
||||
return &Station{
|
||||
Identity: identity{id, proto.DeviceType_DeviceType_Station},
|
||||
code: code,
|
||||
ibp: NewIBP(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Station) GetIbpEmp() *IBPRefMap {
|
||||
return s.ibp.Emp
|
||||
}
|
||||
|
||||
func (s *Station) GetIbpSpk() *IBPRefMap {
|
||||
return s.ibp.Spk
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user