2023-10-08 13:11:34 +08:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/consts"
|
|
|
|
)
|
|
|
|
|
|
|
|
// LoadSignals 加载信号机实体
|
|
|
|
func LoadSignals(w ecs.World) error {
|
|
|
|
data := GetWorldData(w)
|
|
|
|
signals := data.Repo.SignalList()
|
|
|
|
for _, signal := range signals {
|
|
|
|
groups := signal.RelayGroups()
|
|
|
|
if len(groups) == 1 {
|
|
|
|
group := groups[0]
|
|
|
|
signalEntry := newSignalEntity(w, signal.Id(), data)
|
|
|
|
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:
|
|
|
|
case consts.SIGNAL_JDXH:
|
|
|
|
case consts.SIGNAL_DCXH:
|
|
|
|
case consts.SIGNAL_JCKXH:
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("id=[%s]的信号机,无效组合类型[%s]", signal.Id(), group.Code())
|
|
|
|
}
|
|
|
|
} else { //信号机有且只有一个组合类型
|
|
|
|
return fmt.Errorf("id=[%s]的信号机须有且只有一个组合类型", signal.Id())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// 新建信号机实体
|
|
|
|
func newSignalEntity(w ecs.World, uid string, worldData *component.WorldData) *ecs.Entry {
|
|
|
|
entry, ok := worldData.EntityMap[uid]
|
|
|
|
if !ok {
|
|
|
|
entry = w.Create(component.UidType)
|
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
|
|
|
worldData.EntityMap[uid] = entry
|
|
|
|
}
|
|
|
|
return entry
|
|
|
|
}
|