コード例 #1
0
        public TiledImportData(TileViewer tileViewer, TiledMapReader map, TiledTilesetReader tileset)
        {
            mTileViewer = tileViewer;
            mMap        = map;
            mTileset    = tileset;
            mMapData    = mMap.MapDataArray;

            mMapWidth  = map.MapWidth;
            mMapHeight = map.MapHeight;
            uint temp;

            if (uint.TryParse(mTileset.TileWidth, out temp))
            {
                mTileWidth = temp;
            }
            else
            {
                MessageBox.Show("Cannot parse TileWidth in Tileset " + mMap.TilesetName);
                return;
            }

            if (uint.TryParse(mTileset.TileHeight, out temp))
            {
                mTileHeight = temp;
            }
            else
            {
                MessageBox.Show("Cannot parse TileHeight in Tileset " + mMap.TilesetName);
                return;
            }

            if (uint.TryParse(mTileset.TileCount, out temp))
            {
                mTileCount = temp;
            }
            else
            {
                MessageBox.Show("Cannot parse TileCount in Tileset " + mMap.TilesetName);
                return;
            }

            if (uint.TryParse(mTileset.Offset, out temp))
            {
                mOffset = temp;
            }
            else
            {
                MessageBox.Show("Cannot parse Offset in Tileset " + mMap.TilesetName);
                return;
            }

            if (uint.TryParse(mTileset.Columns, out temp))
            {
                mColumns = temp;
            }
            else
            {
                MessageBox.Show("Cannot parse Columns in Tileset " + mMap.TilesetName);
                return;
            }

            if (uint.TryParse(mTileset.Rotate, out temp))
            {
                mRotate = temp;
            }
            else
            {
                MessageBox.Show("Cannot parse Rotate in Tileset " + mMap.TilesetName);
                return;
            }
        }
コード例 #2
0
ファイル: TiledLoader.cs プロジェクト: sheng007/porno-graphic
        public TiledLoader(string fileName)
        {
            StreamReader reader = null;

            try
            {
                reader = new StreamReader(fileName);
                XmlSerializer MapLoader = new XmlSerializer(typeof(Classes.TiledMapReader));
                mMap = (Classes.TiledMapReader)MapLoader.Deserialize(reader);
            }
            catch
            {
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            if (mMap == null)
            {
                // TODO more meaningful error message
                MessageBox.Show("Map is null", "ERROR");
                return;
            }

            /*
             * //DEBUG
             * MessageBox.Show(
             *      "Height: " + Map.mapHeight + Environment.NewLine +
             *      "Width: " + Map.mapWidth + Environment.NewLine +
             *      "Tileset: " + Map.TilesetFilename + Environment.NewLine +
             *      "Map data: " + Map.MapDataRawString,
             *      "Map Info");
             * //END DEBUG
             */

            string TilesetPath = Path.GetDirectoryName(fileName) + "\\" + mMap.TilesetFilename;

            //MessageBox.Show(TilesetPath);

            reader = null;

            try
            {
                reader = new StreamReader(TilesetPath);
                XmlSerializer TilesetLoader = new XmlSerializer(typeof(Classes.TiledTilesetReader));
                mTileset = (Classes.TiledTilesetReader)TilesetLoader.Deserialize(reader);
            }
            catch
            {
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            if (mTileset == null)
            {
                // TODO more meaningful error message
                MessageBox.Show("Tileset is null", "ERROR");
                return;
            }
        }