public void LoadStructures() { string path = Util.GetStructuresFolder(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var structuresPath = new DirectoryInfo(path); Structures.Clear(); foreach (FileInfo file in structuresPath.GetFiles()) { if (file.Extension.ToLower() == ".sps") { using (var stream = new FileStream(file.FullName, FileMode.Open)) { var formatter = new BinaryFormatter(); object thing = formatter.Deserialize(stream); var structure = thing as Structure; Structures.Add(file.Name.Substring(0, file.Name.Length - 5), structure); } } } }
private void ClearStructureAction(object data) { if (MessageBox.Show("Do you want delete whole structure?", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { Structures.Clear(); } }
/// <summary> /// Loads the content from the directory and SE objects, creating object models. /// </summary> private void LoadSectorDetail() { Structures.Clear(); ConnectedTopBlockCache.Clear(); SpaceEngineersCore.ManageDeleteVoxelList.Clear(); ThePlayerCharacter = null; _customColors = null; if (ActiveWorld.SectorData != null && ActiveWorld.Checkpoint != null) { foreach (var entityBase in ActiveWorld.SectorData.SectorObjects) { var structure = StructureBaseModel.Create(entityBase, ActiveWorld.Savepath); if (structure is StructureCharacterModel) { var character = structure as StructureCharacterModel; if (ActiveWorld.Checkpoint != null && character.EntityId == ActiveWorld.Checkpoint.ControlledObject) { character.IsPlayer = true; ThePlayerCharacter = character; } } else if (structure is StructureCubeGridModel) { var cubeGrid = structure as StructureCubeGridModel; var list = cubeGrid.GetActiveCockpits(); foreach (var cockpit in list) { cubeGrid.Pilots++; // theoretically with the Hierarchy structure, there could be more than one character attached to a single cube. // thus, more than 1 pilot. var pilots = cockpit.GetHierarchyCharacters(); var character = (StructureCharacterModel)StructureBaseModel.Create(pilots.First(), null); character.IsPilot = true; if (ActiveWorld.Checkpoint != null && cockpit.EntityId == ActiveWorld.Checkpoint.ControlledObject) { ThePlayerCharacter = character; ThePlayerCharacter.IsPlayer = true; } Structures.Add(character); } } Structures.Add(structure); } CalcDistances(); } RaisePropertyChanged(() => Structures); }
/// <summary> /// Loads the content from the directory and SE objects, creating object models. /// </summary> private void LoadSectorDetail() { Structures.Clear(); SpaceEngineersCore.ManageDeleteVoxelList.Clear(); ThePlayerCharacter = null; _customColors = null; if (ActiveWorld.SectorData != null && ActiveWorld.Checkpoint != null) { foreach (var entityBase in ActiveWorld.SectorData.SectorObjects) { var structure = StructureBaseModel.Create(entityBase, ActiveWorld.Savepath); if (structure is StructureCharacterModel) { var character = structure as StructureCharacterModel; if (ActiveWorld.Checkpoint != null && character.EntityId == ActiveWorld.Checkpoint.ControlledObject) { character.IsPlayer = true; ThePlayerCharacter = character; } } else if (structure is StructureCubeGridModel) { var cubeGrid = structure as StructureCubeGridModel; var list = cubeGrid.GetActiveCockpits(); foreach (var cockpit in list) { cubeGrid.Pilots++; var character = (StructureCharacterModel)StructureBaseModel.Create(cockpit.Pilot, null); character.IsPilot = true; if (ActiveWorld.Checkpoint != null && cockpit.EntityId == ActiveWorld.Checkpoint.ControlledObject) { ThePlayerCharacter = character; ThePlayerCharacter.IsPlayer = true; } Structures.Add(character); } } Structures.Add(structure); } CalcDistances(); } RaisePropertyChanged(() => Structures); }
private void EmptyStructureList() { Structures.Clear(); }