2023-10-08 13:11:34 +08:00
|
|
|
|
package entity
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
|
"joylink.club/rtsssimulation/consts"
|
2023-10-20 10:55:03 +08:00
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
2023-10-20 10:21:35 +08:00
|
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
2023-10-16 17:59:35 +08:00
|
|
|
|
"log/slog"
|
2023-10-08 13:11:34 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// LoadSignals 加载信号机实体
|
|
|
|
|
func LoadSignals(w ecs.World) error {
|
|
|
|
|
data := GetWorldData(w)
|
|
|
|
|
signals := data.Repo.SignalList()
|
|
|
|
|
for _, signal := range signals {
|
|
|
|
|
groups := signal.RelayGroups()
|
2023-10-20 10:55:03 +08:00
|
|
|
|
signalEntry := newSignalEntity(w, signal, data)
|
2023-10-20 10:21:35 +08:00
|
|
|
|
if len(groups) == 1 { //带电路的信号机,有且只有一个组合类型,组合类型与电路有关
|
2023-10-08 13:11:34 +08:00
|
|
|
|
group := groups[0]
|
|
|
|
|
elecs := group.Components()
|
|
|
|
|
//
|
|
|
|
|
switch group.Code() {
|
|
|
|
|
case consts.SIGNAL_2XH1:
|
2023-10-08 16:00:05 +08:00
|
|
|
|
if le := loadSignal2xh1(w, signal, signalEntry, elecs, data.EntityMap); le != nil {
|
|
|
|
|
return le
|
|
|
|
|
}
|
2023-10-08 13:11:34 +08:00
|
|
|
|
case consts.SIGNAL_3XH1:
|
2023-10-08 16:00:05 +08:00
|
|
|
|
if le := loadSignal3xh1(w, signal, signalEntry, elecs, data.EntityMap); le != nil {
|
|
|
|
|
return le
|
|
|
|
|
}
|
2023-10-08 13:11:34 +08:00
|
|
|
|
case consts.SIGNAL_3XH2:
|
2023-10-08 16:48:10 +08:00
|
|
|
|
if le := loadSignal3xh2(w, signal, signalEntry, elecs, data.EntityMap); le != nil {
|
|
|
|
|
return le
|
|
|
|
|
}
|
2023-10-08 13:11:34 +08:00
|
|
|
|
case consts.SIGNAL_3XH3:
|
2023-10-08 17:19:50 +08:00
|
|
|
|
if le := loadSignal3xh3(w, signal, signalEntry, elecs, data.EntityMap); le != nil {
|
|
|
|
|
return le
|
|
|
|
|
}
|
2023-10-08 13:11:34 +08:00
|
|
|
|
case consts.SIGNAL_3XH4:
|
2023-10-08 18:03:07 +08:00
|
|
|
|
if le := loadSignal3xh4(w, signal, signalEntry, elecs, data.EntityMap); le != nil {
|
|
|
|
|
return le
|
|
|
|
|
}
|
2023-10-08 13:11:34 +08:00
|
|
|
|
case consts.SIGNAL_JDXH:
|
2023-10-09 11:09:29 +08:00
|
|
|
|
if le := loadSignalJdxh(w, signal, signalEntry, elecs, data.EntityMap); le != nil {
|
|
|
|
|
return le
|
|
|
|
|
}
|
2023-10-08 13:11:34 +08:00
|
|
|
|
case consts.SIGNAL_DCXH:
|
2023-10-09 10:06:01 +08:00
|
|
|
|
if le := loadSignalDcxh(w, signal, signalEntry, elecs, data.EntityMap); le != nil {
|
|
|
|
|
return le
|
|
|
|
|
}
|
2023-10-08 13:11:34 +08:00
|
|
|
|
case consts.SIGNAL_JCKXH:
|
2023-10-09 10:30:44 +08:00
|
|
|
|
if le := loadSignalJckxh(w, signal, signalEntry, elecs, data.EntityMap); le != nil {
|
|
|
|
|
return le
|
|
|
|
|
}
|
2023-10-08 13:11:34 +08:00
|
|
|
|
default:
|
2023-10-16 17:59:35 +08:00
|
|
|
|
slog.Warn(fmt.Sprintf("id=[%s]的信号机,无效组合类型[%s]", signal.Id(), group.Code()))
|
2023-10-08 13:11:34 +08:00
|
|
|
|
}
|
2023-10-20 10:55:03 +08:00
|
|
|
|
} else {
|
|
|
|
|
slog.Debug(fmt.Sprintf("id=[%s]的信号机,没有组合类型或组合类型个数不为1", signal.Id()))
|
2023-10-08 13:11:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 新建信号机实体
|
2023-10-20 10:55:03 +08:00
|
|
|
|
func newSignalEntity(w ecs.World, signal *repository.Signal, worldData *component.WorldData) *ecs.Entry {
|
|
|
|
|
uid := signal.Id()
|
2023-10-08 13:11:34 +08:00
|
|
|
|
entry, ok := worldData.EntityMap[uid]
|
|
|
|
|
if !ok {
|
2023-10-20 10:55:03 +08:00
|
|
|
|
entry = w.Entry(w.Create(component.UidType, component.SignalTag, component.SignalLightsType))
|
2023-10-08 13:11:34 +08:00
|
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
2023-10-20 10:55:03 +08:00
|
|
|
|
component.SignalLightsType.Set(entry, newSignalLightsByModel(w, signal.Model()))
|
2023-10-08 13:11:34 +08:00
|
|
|
|
worldData.EntityMap[uid] = entry
|
|
|
|
|
}
|
|
|
|
|
return entry
|
|
|
|
|
}
|
2023-10-12 11:00:56 +08:00
|
|
|
|
|
|
|
|
|
// 新建灯位列表
|
2023-10-12 11:06:20 +08:00
|
|
|
|
func newSignalLights(w ecs.World, lightTags ...component.DsTag) *component.SignalLights {
|
2023-10-12 11:00:56 +08:00
|
|
|
|
return &component.SignalLights{Lights: NewLights(w, lightTags...)}
|
|
|
|
|
}
|
2023-10-20 10:21:35 +08:00
|
|
|
|
|
2023-11-16 17:21:03 +08:00
|
|
|
|
/*
|
|
|
|
|
enum Model{
|
|
|
|
|
HL = 0; //2XH-1 红绿
|
|
|
|
|
HLU_FU = 1; //2XH-1 红绿黄,封黄灯,无引导
|
|
|
|
|
HLU_DU_YY = 2; //3XH-1 红绿黄,不封灯,有单黄,带引导
|
|
|
|
|
HLU_YY = 3; //3XH-2或JDXH 红绿黄,不封灯,无单黄,带引导
|
|
|
|
|
HLU_FL_DU_YY = 4;//3XH-3 红绿黄,封绿灯,有单黄,带引导
|
|
|
|
|
HLU_DU = 5; //3XH-4 红绿黄,不封灯,有单黄,无引导
|
|
|
|
|
AB = 6; //DXCH 蓝白
|
|
|
|
|
HBU_DU = 7; //JCKXH 红白黄,不封灯,有单黄,无引导
|
|
|
|
|
}
|
|
|
|
|
*/
|
2023-10-20 10:21:35 +08:00
|
|
|
|
// 新建灯位列表
|
|
|
|
|
func newSignalLightsByModel(w ecs.World, sigMt proto.Signal_Model) *component.SignalLights {
|
|
|
|
|
switch sigMt {
|
|
|
|
|
case proto.Signal_HL:
|
|
|
|
|
return newSignalLights(w, component.HdTag, component.LdTag)
|
|
|
|
|
case proto.Signal_HLU_FU:
|
|
|
|
|
return &component.SignalLights{Lights: []*ecs.Entry{NewLight(w, component.HdTag), NewLight(w, component.LdTag), NewLight(w, component.UdTag, component.FdTag)}}
|
2023-11-16 17:21:03 +08:00
|
|
|
|
case proto.Signal_HLU_FL_DU_YY:
|
2023-10-20 10:21:35 +08:00
|
|
|
|
return &component.SignalLights{Lights: []*ecs.Entry{NewLight(w, component.HdTag), NewLight(w, component.LdTag, component.FdTag), NewLight(w, component.UdTag)}}
|
2023-11-16 17:21:03 +08:00
|
|
|
|
case proto.Signal_HLU_DU_YY:
|
|
|
|
|
fallthrough
|
|
|
|
|
case proto.Signal_HLU_YY:
|
|
|
|
|
fallthrough
|
|
|
|
|
case proto.Signal_HLU_DU:
|
|
|
|
|
return newSignalLights(w, component.HdTag, component.LdTag, component.UdTag)
|
2023-10-20 10:21:35 +08:00
|
|
|
|
case proto.Signal_AB:
|
|
|
|
|
return newSignalLights(w, component.AdTag, component.BdTag)
|
2023-11-16 17:21:03 +08:00
|
|
|
|
case proto.Signal_HBU_DU:
|
2023-10-20 10:21:35 +08:00
|
|
|
|
return newSignalLights(w, component.HdTag, component.BdTag, component.UdTag)
|
|
|
|
|
default:
|
|
|
|
|
panic(fmt.Sprintf("根据信号机模型来创建灯位列表,暂不支持该信号机模型[%d]", sigMt))
|
|
|
|
|
}
|
|
|
|
|
}
|