Пример #1
0
        // Read all tile sets from ROM.
        private void ReadTileSets(Rom rom)
        {
            int addresPC = TileSet.TileSetsAddresPC;

            TileSets.Clear();
            for (int n = 0; n < TileSet.Count; n++)
            {
                TileSets.Add(new TileSet());
                TileSets [n].ReadFromROM(rom, addresPC);
                addresPC += TileSet.DefaultSize;
            }
        }
Пример #2
0
        public void loadTMXFile(string path, bool bind)
        {
            XmlDocument xml = new XmlDocument();

            xml.LoadXml(File.ReadAllText(path));
            XmlNode mapNode = xml["map"];

            //get basic info
            int mapWidth   = int.Parse(mapNode.Attributes["width"].InnerText);
            int mapHeight  = int.Parse(mapNode.Attributes["height"].InnerText);
            int tileWidth  = int.Parse(mapNode.Attributes["tilewidth"].InnerText);
            int tileHeight = int.Parse(mapNode.Attributes["tileheight"].InnerText);

            //load world (assumes same sized tiles throughout layers)
            foreach (XmlNode subNode in mapNode)
            {
                if (subNode.Name.EqualsIgnoreCase("tileset"))
                {
                    string imageAtlasFile = subNode["image"].Attributes["source"].InnerText;
                    string imageAtlasPath = Path.Combine(Path.GetDirectoryName(path), imageAtlasFile);
                    int    startIndex     = int.Parse(subNode.Attributes["firstgid"].InnerText);
                    TileSets.Add(TileSet <Tile> .fromImageAtlas(imageAtlasPath, startIndex, tileWidth, tileHeight));
                    rebuildTileLut(); //(future proofing) do now incase layers ever need to inspect the tiles
                }
                else if (subNode.Name.EqualsIgnoreCase("layer"))
                {
                    string layerFormat = subNode["data"].Attributes["encoding"].InnerText;
                    if (layerFormat.EqualsIgnoreCase("csv"))
                    {
                        //get all numbers from the csv [LIKE A BOSS]
                        //int[] indicies = subNode["data"].InnerText.Split(',').Select(n => int.Parse(n.Trim())).ToArray();
                        int[] indicies = subNode["data"].InnerText.ParseAllIntegers();
                        Panes.Add(new TiledPane(mapWidth, mapHeight, indicies, this));
                    }
                    else
                    {
                        WDAppLog.logError(ErrorLevel.Error, "Unsuported layer format", path);
                    }
                }
                else if (subNode.Name.EqualsIgnoreCase("objectgroup"))
                {
                }
                else if (subNode.Name.EqualsIgnoreCase("imagelayer"))
                {
                    string imageFile = subNode["image"].Attributes["source"].InnerText.Trim();
                    string imagePath = Path.Combine(Path.GetDirectoryName(path), imageFile);
                    Bitmap b         = new Bitmap(imagePath);
                    Panes.Add(new ImagePane(b));
                }
            }
        }