public static ConcealedSector Load(String worldName, Vector3D sectorPos) { String fileName = GenFileName(worldName, sectorPos); // Load main state object Log.Info("Attempting to load from " + fileName, "Load"); ConcealedSector loaded = GardenGateway.Files. ReadXML<ConcealedSector>(fileName); if (loaded == null) { Log.Error("Failed to deserialize XML", "Load"); return null; } //loaded.FileName = fileName; //loaded.BuildersFileName = gridBuildersFileName; //loaded.WorldName = worldName; //loaded.SectorPosition = sectorPos; // Load grid dictionary from serialized list loaded.Grids = loaded.ConcealedGrids. ToDictionary(x => x.EntityId, x => x); // Load concealed grid builders Log.Trace("Loading concealed grid builders", "Load"); loaded.ConcealedGridBuilders = GardenGateway.Files. ReadXML<List<MyObjectBuilder_CubeGrid>>(loaded.BuildersFileName); if (loaded.ConcealedGridBuilders == null) { Log.Error("Failed to load grid builders from file!", "Load"); return null; } // load builders into grids foreach (MyObjectBuilder_CubeGrid builder in loaded.ConcealedGridBuilders) { if (!loaded.Grids.ContainsKey(builder.EntityId)) { Log.Error("Found builder with missing conceal grid " + builder.EntityId, "Load"); return null; } loaded.Grids[builder.EntityId].Builder = builder; } // ensure every grid has a builder foreach (ConcealedGrid grid in loaded.Grids.Values) { if (grid.Builder == null) { Log.Error("Found grid with missing builder " + grid.EntityId, "Load"); return null; } } Log.Trace("Loading AABB Tree", "LoadState"); foreach (ConcealedGrid grid in loaded.ConcealedGrids) { loaded.GridTree.Add(grid); } Log.Trace("Finished Loading AABB Tree", "LoadState"); loaded.NeedsSave = true; Log.Trace("Concealed Sector State successfully loaded", "LoadState"); return loaded; }
public void Initialize() { Log.Trace("Initializing ConcealmentManager", "Initialize"); WorldName = MyAPIGateway.Session.Name; SectorPosition = MyAPIGateway.Session.GetWorld().Sector.Position; Concealed = ConcealedSector.LoadOrNew(WorldName, SectorPosition); Revealed = new RevealedSector(); ControllableEntity.ControllableEntityAdded += Revealed.ControllableEntityAdded; ControllableEntity.ControllableEntityMoved += Revealed.ControllableEntityMoved; ControllableEntity.ControllableEntityRemoved += Revealed.ControllableEntityRemoved; ControllableEntity.ControllableEntityControlled += Revealed.ControllableEntityControlled; ControllableEntity.ControllableEntityReleased += Revealed.ControllableEntityReleased; RevealedEntity.RevealedEntityAdded += Revealed.RevealedEntityAdded; RevealedEntity.RevealedEntityRemoved += Revealed.RevealedEntityRemoved; if (Concealed != null) Loaded = true; Log.Trace("Done Initializing ConcealmentManager", "Initialize"); }