public void loadFromXML(XmlNode node) { base.loadFromXML(node); this.SubTypeName = node.SelectSingleNode("SubtypeName").InnerText; //Console.WriteLine("loaded " + this.SubTypeName); this.Min.loadFromXML(node.SelectSingleNode("Min")); this.Max.loadFromXML(node.SelectSingleNode("Max")); this.Orientation.loadFromXML(node.SelectSingleNode("Orientation")); XmlNode myPilot = node.SelectSingleNode("Pilot"); if (myPilot != null) { this.hasPilot = true; Console.WriteLine("Got pilot"); Pilot = new Character(this.parent_sector); Pilot.loadFromXML(myPilot,this.EntityId); } this.displayType = this.SubTypeName; }
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 void loadFromXML(XmlNode node, bool quick = false) { base.loadFromXML(node); this.GridSizeEnum = node.SelectSingleNode("GridSizeEnum").InnerText; this.quick_loaded = quick; XmlNodeList blocks = node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock"); if (quick == false) { Console.WriteLine("Loading blocks..."); foreach (XmlNode block in blocks) { CubeBlock new_block = new CubeBlock(this.parent_sector); new_block.loadFromXML(block); if (new_block.SubTypeName == "LargeBlockCockpit" || new_block.SubTypeName == "SmallBlockCockpit") { this.cockpit = new_block; if (new_block.hasPilot == true) { Console.WriteLine("Grid has pilot"); this.hasPilot = true; new_block.Pilot.parent = this.EntityId; this.Pilot = new_block.Pilot; } } CubeBlocks.Add(new_block); } } else { this.raw = node.SelectSingleNode("CubeBlocks").OuterXml; Console.WriteLine("Quick loaded"); this.quick_count = blocks.Count; } try { IsStatic = node.SelectSingleNode("IsStatic").InnerText; LinearVelocity.loadFromXML(node.SelectSingleNode("LinearVelocity")); AngularVelocity.loadFromXML(node.SelectSingleNode("AngularVelocity")); } catch (NullReferenceException) { } if (this.GridSizeEnum == "Large") if (this.IsStatic == "true") this.displayType = "Station"; else this.displayType = "Large Ship"; if (this.GridSizeEnum == "Small") this.displayType = "Small Ship"; if (this.hasPilot == true) { this.displayType = "[*] " + this.displayType; } this.actualType = "Ship"; Console.WriteLine("Loaded"); //Console.WriteLine("Loaded "+displayType+" with "+CubeBlocks.Count +" blocks"); }