Esempio n. 1
0
        public static GbProject LoadFromFile(String pFilename)
        {
            GbProject vResult = new GbProject();

            using (FileStream vFS = new FileStream(pFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                using (StreamReader vSR = new StreamReader(vFS)) {
                    XmlDocument vDoc = new XmlDocument();
                    vDoc.LoadXml(vSR.ReadToEnd());

                    //First, load the library and its tiles
                    foreach (XmlNode vNode in vDoc.DocumentElement.SelectNodes("/gbProject/libraries/library")) {
                        Library vLib = new Library(vNode.Attributes["name"].Value);

                        foreach (XmlNode vNodeTile in vNode.SelectNodes("./tile")) {
                            Tile vS = Tile.LoadFromXml(vNodeTile);
                            vLib.AddTile(vS);
                        }

                        vResult.mLibraries.Add(vLib);
                    }

                    //Second, load the maps
                    foreach (XmlNode vNode in vDoc.DocumentElement.SelectNodes("/gbProject/maps/map")) {
                        Map vMap = new Map(
                            Convert.ToInt32(vNode.Attributes["width"].Value),
                            Convert.ToInt32(vNode.Attributes["height"].Value)
                            );
                        vMap.Name = vNode.Attributes["name"].Value;

                        foreach (XmlNode vNodeCell in vNode.SelectNodes("./cell")) {
                            Guid vG = new Guid(vNodeCell.Attributes["tileID"].Value);
                            Tile vT = null;

                            foreach (Library vL in vResult.mLibraries) {
                                vT = vL.GetTileByID(vG);
                                if (vT != null)
                                    break;
                            }

                            if (vT != null) {
                                vMap.SetTile(
                                    vT,
                                    Convert.ToInt32(vNodeCell.Attributes["x"].Value),
                                    Convert.ToInt32(vNodeCell.Attributes["y"].Value)
                                );
                            }
                        }

                        vResult.AddMap(vMap);
                    }
                }
            }

            return vResult;
        }
Esempio n. 2
0
        public static GbProject LoadFromFile(String pFilename)
        {
            GbProject vResult = new GbProject();

            using (FileStream vFS = new FileStream(pFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                using (StreamReader vSR = new StreamReader(vFS)) {
                    XmlDocument vDoc = new XmlDocument();
                    vDoc.LoadXml(vSR.ReadToEnd());

                    //pick the palette
                    XmlNode vPalet = vDoc.DocumentElement.SelectSingleNode("/gbProject/palette");
                    if (vPalet != null && Palette.WellknownPalettes.ContainsKey(vPalet.Attributes["name"].Value))
                    {
                        vResult.mPalette = Palette.WellknownPalettes[vPalet.Attributes["name"].Value];
                    }
                    else
                    {
                        vResult.mPalette = Palette.DEFAULT_PALETTE;
                    }

                    //First, load the library and its tiles
                    foreach (XmlNode vNode in vDoc.DocumentElement.SelectNodes("/gbProject/libraries/library"))
                    {
                        Library vLib = new Library(vNode.Attributes["name"].Value);

                        foreach (XmlNode vNodeTile in vNode.SelectNodes("./tile"))
                        {
                            Tile vS = Tile.LoadFromXml(vNodeTile, vResult.Palette);
                            vLib.AddTile(vS);
                        }

                        vResult.mLibraries.Add(vLib);
                    }

                    //Second, load the maps
                    foreach (XmlNode vNode in vDoc.DocumentElement.SelectNodes("/gbProject/maps/map"))
                    {
                        Map vMap = new Map(
                            Convert.ToInt32(vNode.Attributes["width"].Value),
                            Convert.ToInt32(vNode.Attributes["height"].Value)
                            );
                        vMap.Name = vNode.Attributes["name"].Value;

                        foreach (XmlNode vNodeCell in vNode.SelectNodes("./cell"))
                        {
                            Guid vG = new Guid(vNodeCell.Attributes["tileID"].Value);
                            Tile vT = null;

                            foreach (Library vL in vResult.mLibraries)
                            {
                                vT = vL.GetTileByID(vG);
                                if (vT != null)
                                {
                                    break;
                                }
                            }

                            if (vT != null)
                            {
                                vMap.SetTile(
                                    vT,
                                    Convert.ToInt32(vNodeCell.Attributes["x"].Value),
                                    Convert.ToInt32(vNodeCell.Attributes["y"].Value)
                                    );
                            }
                        }

                        vResult.AddMap(vMap);
                    }
                }
            }

            return(vResult);
        }
Esempio n. 3
0
        /// <summary>
        /// Loads a GB project
        /// </summary>
        private void LoadGbProject(string pFilename)
        {
            SetStatus("Loading project " + pFilename + " ...");
            try {
                //StartEmptyNewProject();
                this.mCurrentProject = GbProject.LoadFromFile(pFilename);
                this.mCurrentProject.LatestKnownFilename = pFilename;
            }
            catch (Exception) {
                StartEmptyNewProject();
            }

            ucLibView.SetLibrary(mCurrentProject.mLibraries[0]);
            foreach (Map vM in this.mCurrentProject.mMaps) {

                TabPage vTP = new TabPage(vM.Name);
                UcMapEditor vME = new UcMapEditor();
                vME.CurrentMap = vM;
                vME.CurrentTile = ucLibView.SelectedTile;
                vTP.Controls.Add(vME);
                vME.Dock = DockStyle.Fill;
                tabMaps.TabPages.Add(vTP);
                tabMaps.SelectedTab = vTP;

                vME.NewMap += new EventHandler(MapEditor_NewMap);
            }

            SetStatus("Loading project " + pFilename + " completed.");
        }