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: if le := loadSignal2xh1(w, signal, signalEntry, elecs, data.EntityMap); le != nil { return le } case consts.SIGNAL_3XH1: if le := loadSignal3xh1(w, signal, signalEntry, elecs, data.EntityMap); le != nil { return le } case consts.SIGNAL_3XH2: if le := loadSignal3xh2(w, signal, signalEntry, elecs, data.EntityMap); le != nil { return le } case consts.SIGNAL_3XH3: if le := loadSignal3xh3(w, signal, signalEntry, elecs, data.EntityMap); le != nil { return le } case consts.SIGNAL_3XH4: if le := loadSignal3xh4(w, signal, signalEntry, elecs, data.EntityMap); le != nil { return le } 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 }