public String loadFromXML(string filename,bool loggingEnabled = false, bool quick_load = false) { String log = ""; this.quick_loaded = quick_load; this.main_form.update_status("Loading"); log += "Loading Sector from " + filename + "\r\n"; doc.Load(filename); try { XmlNode SectorPosition = doc.DocumentElement.SelectSingleNode("/MyObjectBuilder_Sector/Position"); this.Position.loadFromXML(SectorPosition); log += "Got Sector Position\r\n"; XmlNodeList SectorObjects = doc.DocumentElement.SelectNodes("/MyObjectBuilder_Sector/SectorObjects/MyObjectBuilder_EntityBase"); log += "Got Sector Objects\r\n"; foreach(XmlNode entity in SectorObjects){ string entity_type = entity.Attributes["xsi:type"].Value; switch (entity_type) { case "MyObjectBuilder_VoxelMap": VoxelMap vm = new VoxelMap(this); log += "Loading VoxelMap\r\n"; try { vm.loadFromXML(entity); log += "VoxelMap " + vm.Filename + " Loaded\r\n"; this.VoxelMaps.Add(vm); } catch (Exception err) { log += "Exception loading VoxelMap "+ err.Message +"\r\n"; } break; case "MyObjectBuilder_CubeGrid": CubeGrid cg = new CubeGrid(this); log += "Loading CubeGrid\r\n"; try { cg.loadFromXML(entity,quick_load); log += cg.displayType + " with " + cg.CubeBlocks.Count() + "Blocks Loaded\r\n"; if (cg.hasPilot == true) { this.character = cg.Pilot; Console.WriteLine("Sector found pilot"); log += "found Pilot\r\n"; } this.CubeGrids.Add(cg); } catch (Exception err) { log += "Exception loading CubeGrid " + err.Message + "\r\n"; } break; case "MyObjectBuilder_Character": log += "Loading Character\r\n"; try { this.character = new Character(this); character.loadFromXML(entity, "sector"); log += "Character Loaded\r\n"; } catch (Exception err) { log += "Exception loading Character " + err.Message + "\r\n"; } break; default: entity_misc em = new entity_misc(this); em.loadFromXML(entity); this.EntityMiscs.Add(em); break; } } } catch (Exception err) { log += "Exception! " + err.Message+" "+err.Source+"\r\n"; log += "StackTrace " + err.StackTrace+"\r\n"; } if (character == null || character.parent == "") { this.CubeGrids.Clear(); this.VoxelMaps.Clear(); this.EntityMiscs.Clear(); log += "No Character / Pilot found!!\r\n"; MessageBox.Show("Unable to load world, Are you currently piloting a ship?"); } this.main_form.update_status(""); return log; }
public String loadFromXML(string filename, bool loggingEnabled = false, bool quick_load = false) { String log = ""; this.quick_loaded = quick_load; this.main_form.update_status("Loading"); log += "Loading Sector from " + filename + "\r\n"; doc.Load(filename); try { XmlNode SectorPosition = doc.DocumentElement.SelectSingleNode("/MyObjectBuilder_Sector/Position"); this.Position.loadFromXML(SectorPosition); log += "Got Sector Position\r\n"; XmlNodeList SectorObjects = doc.DocumentElement.SelectNodes("/MyObjectBuilder_Sector/SectorObjects/MyObjectBuilder_EntityBase"); log += "Got Sector Objects\r\n"; foreach (XmlNode entity in SectorObjects) { string entity_type = entity.Attributes["xsi:type"].Value; switch (entity_type) { case "MyObjectBuilder_VoxelMap": VoxelMap vm = new VoxelMap(this); log += "Loading VoxelMap\r\n"; try { vm.loadFromXML(entity); log += "VoxelMap " + vm.Filename + " Loaded\r\n"; this.VoxelMaps.Add(vm); } catch (Exception err) { log += "Exception loading VoxelMap " + err.Message + "\r\n"; } break; case "MyObjectBuilder_CubeGrid": CubeGrid cg = new CubeGrid(this); log += "Loading CubeGrid\r\n"; try { cg.loadFromXML(entity, quick_load); log += cg.displayType + " with " + cg.CubeBlocks.Count() + "Blocks Loaded\r\n"; if (cg.hasPilot == true) { this.character = cg.Pilot; Console.WriteLine("Sector found pilot"); log += "found Pilot\r\n"; } this.CubeGrids.Add(cg); } catch (Exception err) { log += "Exception loading CubeGrid " + err.Message + "\r\n"; } break; case "MyObjectBuilder_Character": log += "Loading Character\r\n"; try { this.character = new Character(this); character.loadFromXML(entity, "sector"); log += "Character Loaded\r\n"; } catch (Exception err) { log += "Exception loading Character " + err.Message + "\r\n"; } break; default: entity_misc em = new entity_misc(this); em.loadFromXML(entity); this.EntityMiscs.Add(em); break; } } } catch (Exception err) { log += "Exception! " + err.Message + " " + err.Source + "\r\n"; log += "StackTrace " + err.StackTrace + "\r\n"; } if (character == null || character.parent == "") { this.CubeGrids.Clear(); this.VoxelMaps.Clear(); this.EntityMiscs.Clear(); log += "No Character / Pilot found!!\r\n"; MessageBox.Show("Unable to load world, Are you currently piloting a ship?"); } this.main_form.update_status(""); return(log); }