public RoomTemplate()
 {
     m_templateName = "";
     m_navMeshTemplate = null;
     m_floor = null;
     m_walls = null;
     m_backgroundObjects = null;
     m_forgroundObjects = null;
 }
 public RoomTemplate()
 {
     m_templateName      = "";
     m_navMeshTemplate   = null;
     m_floor             = null;
     m_walls             = null;
     m_backgroundObjects = null;
     m_forgroundObjects  = null;
 }
    public static RoomTemplate ParseXML(string templateName, XmlNode roomTemplateXML)
    {
        RoomTemplate roomTemplate = new RoomTemplate();

        roomTemplate.m_templateName      = templateName;
        roomTemplate.m_floor             = TileGridTemplate.ParseXML(roomTemplateXML.SelectSingleNode(".//Floor"));
        roomTemplate.m_walls             = TileGridTemplate.ParseXML(roomTemplateXML.SelectSingleNode(".//Walls"));
        roomTemplate.m_backgroundObjects = TileGridTemplate.ParseXML(roomTemplateXML.SelectSingleNode(".//BackgroundObjects"));
        roomTemplate.m_navMeshTemplate   =
            AsyncRPGSharedLib.Navigation.NavMesh.FromNavMeshXML(roomTemplateXML.SelectSingleNode(".//NavMesh"));
        roomTemplate.m_forgroundObjects = TileGridTemplate.ParseXML(roomTemplateXML.SelectSingleNode(".//ForegroundObjects"));

        return(roomTemplate);
    }
    public static RoomTemplate ParseCompressedRoomTemplate(CompressedRoomTemplate compressedRoomTemplate)
    {
        RoomTemplate roomTemplate = new RoomTemplate();

        XmlDocument roomTemplateXML = new XmlDocument();

        roomTemplateXML.LoadXml(compressedRoomTemplate.xml);

        roomTemplate.m_templateName      = compressedRoomTemplate.templateName;
        roomTemplate.m_floor             = TileGridTemplate.ParseXML(roomTemplateXML.SelectSingleNode(".//Floor"));
        roomTemplate.m_walls             = TileGridTemplate.ParseXML(roomTemplateXML.SelectSingleNode(".//Walls"));
        roomTemplate.m_backgroundObjects = TileGridTemplate.ParseXML(roomTemplateXML.SelectSingleNode(".//BackgroundObjects"));
        roomTemplate.m_navMeshTemplate   =
            AsyncRPGSharedLib.Navigation.NavMesh.FromCompressedNavMeshData(
                compressedRoomTemplate.compressedNavCells,
                compressedRoomTemplate.compressedVisibility);
        roomTemplate.m_forgroundObjects = TileGridTemplate.ParseXML(roomTemplateXML.SelectSingleNode(".//ForegroundObjects"));

        return(roomTemplate);
    }
    public static TileGridTemplate ParseXML(XmlNode tileGridXML)
    {
        TileGridTemplate tileGridTemplate = new TileGridTemplate();

        tileGridTemplate.m_tileSetImage = tileGridXML.Attributes["tileset"].Value;

        {
            List <int> gridValues = new List <int>();
            string[]   gridRows   = tileGridXML.InnerText.Split(new char[] { '\n' });

            foreach (string rowString in gridRows)
            {
                string[] rowElements = rowString.Split(new char[] { ',' });

                foreach (string element in rowElements)
                {
                    gridValues.Add(int.Parse(element));
                }
            }

            tileGridTemplate.m_grid    = gridValues.ToArray();
            tileGridTemplate.m_rows    = (uint)gridRows.Length;
            tileGridTemplate.m_colomns = (uint)tileGridTemplate.m_grid.Length / tileGridTemplate.m_rows;
        }

        uint expectedSize = GameConstants.ROOM_X_TILES * GameConstants.ROOM_Y_TILES;

        if (tileGridTemplate.m_grid.Length != expectedSize)
        {
            throw new Exception(
                      "TileGridTemplate: Invalid tile grid size. Expected " +
                      expectedSize.ToString() +
                      " entries, got " +
                      tileGridTemplate.m_grid.Length.ToString());
        }

        return(tileGridTemplate);
    }
    public static TileGridTemplate ParseXML(XmlNode tileGridXML)
    {
        TileGridTemplate tileGridTemplate = new TileGridTemplate();

        tileGridTemplate.m_tileSetImage = tileGridXML.Attributes["tileset"].Value;

        {
            List<int> gridValues = new List<int>();
            string[] gridRows = tileGridXML.InnerText.Split(new char[] {'\n'});

            foreach (string rowString in gridRows)
            {
                string[] rowElements = rowString.Split(new char[] {','});

                foreach (string element in rowElements)
                {
                    gridValues.Add(int.Parse(element));
                }
            }

            tileGridTemplate.m_grid = gridValues.ToArray();
            tileGridTemplate.m_rows = (uint)gridRows.Length;
            tileGridTemplate.m_colomns = (uint)tileGridTemplate.m_grid.Length / tileGridTemplate.m_rows;
        }

        uint expectedSize = GameConstants.ROOM_X_TILES * GameConstants.ROOM_Y_TILES;
        if (tileGridTemplate.m_grid.Length != expectedSize)
        {
            throw new Exception(
                "TileGridTemplate: Invalid tile grid size. Expected "+
                expectedSize.ToString()+
                " entries, got "+
                tileGridTemplate.m_grid.Length.ToString());
        }

        return tileGridTemplate;
    }
Exemple #7
0
    public void RebuildRoom(RoomData room)
    {
        if (m_backgroundTiles == null)
        {
            m_backgroundTiles = new TileGridWidget(m_backgroundGroup, "BackgroundTiles", Screen.width, Screen.height, 3, 0.0f, 0.0f);
        }

        if (m_wallTiles == null)
        {
            m_wallTiles = new TileGridWidget(m_backgroundGroup, "WallTiles", Screen.width, Screen.height, 2, 0.0f, 0.0f);
        }

        if (m_backgroundObjectTiles == null)
        {
            m_backgroundObjectTiles = new TileGridWidget(m_backgroundGroup, "BackgroundObjects", Screen.width, Screen.height, 1, 0.0f, 0.0f);
        }

        if (m_foregroundObjectTiles == null)
        {
            m_foregroundObjectTiles = new TileGridWidget(m_foregroundGroup, "ForegroundObjects", Screen.width, Screen.height, 0, 0.0f, 0.0f);
        }

        // Covert the tile IDs over to sprite sheet indices
        RoomTemplate roomTemplate = room.StaticRoomData.RoomTemplate;

        TileGridTemplate floorGrid = roomTemplate.FloorGridTemplate;

        m_backgroundTiles.LoadMap(
            floorGrid.TileIndices,
            floorGrid.RowCount, floorGrid.ColomnCount,
            floorGrid.TileSetImageName, floorGrid.TileWidth, floorGrid.TileHeight);

        TileGridTemplate wallGrid = roomTemplate.WallGridTemplate;

        m_wallTiles.LoadMap(
            wallGrid.TileIndices,
            wallGrid.RowCount, wallGrid.ColomnCount,
            wallGrid.TileSetImageName, wallGrid.TileWidth, wallGrid.TileHeight);

        TileGridTemplate backgroundObjGrid = roomTemplate.BackgroundObjectsTemplate;

        m_backgroundObjectTiles.LoadMap(
            backgroundObjGrid.TileIndices,
            backgroundObjGrid.RowCount, backgroundObjGrid.ColomnCount,
            backgroundObjGrid.TileSetImageName, backgroundObjGrid.TileWidth, backgroundObjGrid.TileHeight);

        TileGridTemplate foregroundObjGroup = roomTemplate.BackgroundObjectsTemplate;

        m_foregroundObjectTiles.LoadMap(
            foregroundObjGroup.TileIndices,
            foregroundObjGroup.RowCount, foregroundObjGroup.ColomnCount,
            foregroundObjGroup.TileSetImageName, foregroundObjGroup.TileWidth, foregroundObjGroup.TileHeight);

        //TODO: rebuildRoom: Use animated tile entities from the room template

        /*var tileIdGrid:Array = room.staticRoomData.backgroundTileGrid;
         * var tileIndices:Array = new Array();
         * for (var listIndex:uint = 0; listIndex < tileIdGrid.length; listIndex++)
         * {
         *      var tileId:uint = tileIdGrid[listIndex];
         *      var tileDescriptor:TileDescriptor= currentTileSet.getTileDescriptorById(tileId);
         *      var sheetIndex:int = tileDescriptor.sheetIndex;
         *
         *      // Create an animated tile for any tile that has more than one frame
         *      if (tileDescriptor.frameCount > 1)
         *      {
         *              var tileColomn:uint = listIndex % room.staticRoomData.tileColomns;
         *              var tileRow:uint = uint(listIndex / room.staticRoomData.tileColomns);
         *              var tileX:Number = Number(tileColomn) * currentTileSet.TileWidth;
         *              var tileY:Number = Number(tileRow) * currentTileSet.TileHeight;
         *
         *              new AnimatedTileWidget(m_backgroundGroup, currentTileSet, tileDescriptor, tileX, tileY);
         *      }
         *
         *      tileIndices.push(sheetIndex);
         * }*/
    }