package entity import ( "joylink.club/ecs" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/repository" ) func LoadPsd(w ecs.World) error { data := GetWorldData(w) psds := data.Repo.PsdList() for _, psd := range psds { entry := NewPsdEntry(w, psd, data) loadPsdCircuit(w, entry, psd, data.EntityMap) } return nil } func loadPsdCircuit(world ecs.World, entry *ecs.Entry, psd *repository.Psd, entryMap map[string]*ecs.Entry) { if len(psd.ComponentGroups()) == 0 { return } circuit := &component.PsdCircuit{} for _, group := range psd.ComponentGroups() { for _, ec := range group.Components() { relay := ec.(*repository.Relay) switch ec.Code() { case "XGMJ", "SGMJ": circuit.GMJ = NewRelayEntity(world, relay, entryMap) case "4XKMJ", "4SKMJ": circuit.KMJ4 = NewRelayEntity(world, relay, entryMap) case "8XKMJ", "8SKMJ": circuit.KMJ8 = NewRelayEntity(world, relay, entryMap) case "XMGJ", "SMGJ": circuit.MGJ = NewRelayEntity(world, relay, entryMap) case "XMPLJ", "SMPLJ": circuit.MPLJ = NewRelayEntity(world, relay, entryMap) } } } component.PsdCircuitType.Set(entry, circuit) } func NewPsdEntry(world ecs.World, psd *repository.Psd, worldData *component.WorldData) *ecs.Entry { entry, ok := worldData.EntityMap[psd.Id()] if !ok { entry = world.Entry(world.Create(component.PsdTag, component.UidType, component.PsdStateType, component.PsdDriveCircuitType, component.PsdCollectionCircuitType, component.AsdListType)) component.UidType.SetValue(entry, component.Uid{Id: psd.Id()}) worldData.EntityMap[psd.Id()] = entry } return entry }