示例#1
0
        private static void GenerateObjectLayer(RoomScene room, Dictionary <string, Dictionary <string, ArrayList> > layer)
        {
            // Loop through YData within the Layer Provided:
            foreach (KeyValuePair <string, Dictionary <string, ArrayList> > yData in layer)
            {
                short gridY = short.Parse(yData.Key);

                // Loop through XData
                foreach (KeyValuePair <string, ArrayList> xData in yData.Value)
                {
                    short gridX = short.Parse(xData.Key);

                    if (xData.Value.Count == 2)
                    {
                        RoomGenerate.AddObjectToScene(room, gridX, gridY, Convert.ToByte(xData.Value[0]), Convert.ToByte(xData.Value[1]));
                    }
                    else if (xData.Value.Count > 2)
                    {
                        // ERRORS HERE MEAN: The json data saved a string instead of a short; e.g. {"Suit", "WhiteNinja"} instead of {"Suit", 2}
                        // To fix it, we need to run LevelConvert updates that make the appropriate changes.
                        Dictionary <string, short> paramList = JsonConvert.DeserializeObject <Dictionary <string, short> >(xData.Value[2].ToString());
                        RoomGenerate.AddObjectToScene(room, gridX, gridY, Convert.ToByte(xData.Value[0]), Convert.ToByte(xData.Value[1]), paramList);
                    }
                }
            }
        }
示例#2
0
        private static void GenerateTileLayer(RoomScene room, Dictionary <string, Dictionary <string, ArrayList> > layer, LayerEnum layerEnum)
        {
            var TileDict = Systems.mapper.TileDict;

            // Loop through YData within the Layer Provided:
            foreach (KeyValuePair <string, Dictionary <string, ArrayList> > yData in layer)
            {
                short gridY = short.Parse(yData.Key);

                // Loop through XData
                foreach (KeyValuePair <string, ArrayList> xData in yData.Value)
                {
                    short gridX = short.Parse(xData.Key);

                    byte tileId  = Convert.ToByte(xData.Value[0]);
                    byte subType = Convert.ToByte(xData.Value[1]);
                    Dictionary <string, short> paramList = null;

                    if (xData.Value.Count > 2)
                    {
                        // ERRORS HERE MEAN: The json data saved a string instead of a short; e.g. {"Suit", "WhiteNinja"} instead of {"Suit", 2}
                        // To fix it, we need to run LevelConvert updates that make the appropriate changes.
                        paramList = JsonConvert.DeserializeObject <Dictionary <string, short> >(xData.Value[2].ToString());
                    }

                    // Check the TileDict to identify setup requirements. If it does, run it's setup process.
                    TileObject tile = TileDict[tileId];

                    // If the tile is considered "Pre-Setup Only" - only run its pre-setup method; don't add it to the scene.
                    if (tile.setupRules == SetupRules.PreSetupOnly)
                    {
                        (tile as dynamic).PreSetup(room, (short)(gridX + (byte)TilemapEnum.GapLeft), (short)(gridY + (byte)TilemapEnum.GapUp), tileId, subType, paramList);
                        continue;
                    }

                    RoomGenerate.AddTileToScene(room, layerEnum, gridX, gridY, tileId, subType, paramList);

                    // Post Setup
                    if (tile.setupRules >= SetupRules.SetupTile)
                    {
                        (tile as dynamic).SetupTile(room, (short)(gridX + (byte)TilemapEnum.GapLeft), (short)(gridY + (byte)TilemapEnum.GapUp));
                    }
                }
            }
        }
示例#3
0
        public static void GenerateRoom(RoomScene room, LevelContent levelContent, byte roomId)
        {
            // NOTE: If room properties are NULL, the LevelFormat probably broke and it needs to be updated (or level data was invalid structure).
            RoomFormat roomData = levelContent.data.rooms[roomId];

            if (roomData.bg != null)
            {
                RoomGenerate.GenerateTileLayer(room, roomData.bg, LayerEnum.bg);
            }
            if (roomData.main != null)
            {
                RoomGenerate.GenerateTileLayer(room, roomData.main, LayerEnum.main);
            }
            if (roomData.obj != null)
            {
                RoomGenerate.GenerateObjectLayer(room, roomData.obj);
            }
            if (roomData.fg != null)
            {
                RoomGenerate.GenerateTileLayer(room, roomData.fg, LayerEnum.fg);
            }

            // Build "Barrier Wall" around Level. Designed to protect against objects crossing tile path.
            short maxX = (short)(room.tilemap.XCount + (byte)TilemapEnum.GapLeft + (byte)TilemapEnum.GapRight - 1);
            short maxY = (short)(room.tilemap.YCount + (byte)TilemapEnum.GapUp + (byte)TilemapEnum.GapDown - 1);

            for (short y = 0; y <= maxY; y++)
            {
                room.tilemap.SetMainTile(0, y, (byte)TileEnum.BarrierWall, 0);
                room.tilemap.SetMainTile(maxX, y, (byte)TileEnum.BarrierWall, 0);
            }

            for (short x = 0; x <= maxX; x++)
            {
                room.tilemap.SetMainTile(x, 0, (byte)TileEnum.BarrierWall, 0);
                room.tilemap.SetMainTile(x, maxY, (byte)TileEnum.BarrierWall, 0);
            }
        }
示例#4
0
        public static void DetectRoomSize(RoomFormat roomData, out short xCount, out short yCount)
        {
            // Prepare Minimum Width and Height for Level
            xCount = (byte)TilemapEnum.MinWidth;
            yCount = (byte)TilemapEnum.MinHeight;

            // Scan the full level to determine it's size:
            if (roomData.bg != null)
            {
                RoomGenerate.DetectLayerSize(roomData.bg, ref xCount, ref yCount);
            }
            if (roomData.main != null)
            {
                RoomGenerate.DetectLayerSize(roomData.main, ref xCount, ref yCount);
            }
            if (roomData.obj != null)
            {
                RoomGenerate.DetectLayerSize(roomData.obj, ref xCount, ref yCount);
            }
            if (roomData.fg != null)
            {
                RoomGenerate.DetectLayerSize(roomData.fg, ref xCount, ref yCount);
            }
        }