Beispiel #1
0
        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;
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 public CubeGrid loadCGFragment(string xml,bool displace = false)
 {
     //have to jump through some hoops here to load our fragment
     NameTable nt = new NameTable();
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
     nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
     XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
     XmlReaderSettings xset = new XmlReaderSettings();
     xset.ConformanceLevel = ConformanceLevel.Fragment;
     XmlReader rd = XmlReader.Create(new StringReader(xml), xset, context);
     XmlDocument NewDoc = new XmlDocument();
     NewDoc.Load(rd);
     CubeGrid new_cg = new CubeGrid(this);
     new_cg.loadFromXML(NewDoc.SelectSingleNode("MyObjectBuilder_EntityBase"),this.quick_loaded);
     new_cg.new_id();
     if (displace == true)
     {
         new_cg.PositionAndOrientation.position.Y += 50;
     }
     return new_cg;
 }
Beispiel #4
0
 public void merge(CubeGrid newGrid)
 {
     this.dirty = true;
     foreach (CubeBlock cb in newGrid.CubeBlocks)
     {
         if (!cb.isAnchor())
             this.CubeBlocks.Add(cb);
     }
 }