Example #1
0
        public static RoomData ExtractRoomData(string data)
        {
            int end = data.Length - dataHeader.Length - 1;

            for (int i = end; i > 0; i--)
            {
                string sub = data.Substring(i, dataHeader.Length);
                if (sub.Equals(dataHeader))
                {
                    return(JsonUtility.FromJson <RoomData>(data.Substring(i + dataHeader.Length)));
                }
            }
            ShrineTools.Log($"No room data found at {data}");
            return(new RoomData());
        }
Example #2
0
        public static void ApplyRoomData(PrototypeDungeonRoom room, RoomData roomData)
        {
            if (roomData.exitPositions != null)
            {
                for (int i = 0; i < roomData.exitPositions.Length; i++)
                {
                    DungeonData.Direction dir = (DungeonData.Direction)Enum.Parse(typeof(DungeonData.Direction), roomData.exitDirections[i].ToUpper());
                    AddExit(room, roomData.exitPositions[i], dir);
                }
            }
            else
            {
                AddExit(room, new Vector2(room.Width / 2, room.Height), DungeonData.Direction.NORTH);
                AddExit(room, new Vector2(room.Width / 2, 0), DungeonData.Direction.SOUTH);
                AddExit(room, new Vector2(room.Width, room.Height / 2), DungeonData.Direction.EAST);
                AddExit(room, new Vector2(0, room.Height / 2), DungeonData.Direction.WEST);
            }

            if (roomData.enemyPositions != null)
            {
                for (int i = 0; i < roomData.enemyPositions.Length; i++)
                {
                    AddEnemyToRoom(room, roomData.enemyPositions[i], roomData.enemyGUIDs[i], roomData.enemyReinforcementLayers[i], roomData.randomizeEnemyPositions);
                }
            }

            if (roomData.placeablePositions != null)
            {
                for (int i = 0; i < roomData.placeablePositions.Length; i++)
                {
                    AddPlaceableToRoom(room, roomData.placeablePositions[i], roomData.placeableGUIDs[i]);
                }
            }

            if (roomData.floors != null)
            {
                foreach (var floor in roomData.floors)
                {
                    room.prerequisites.Add(new DungeonPrerequisite()
                    {
                        prerequisiteType = DungeonPrerequisite.PrerequisiteType.TILESET,
                        requiredTileset  = ShrineTools.GetEnumValue <GlobalDungeonData.ValidTilesets>(floor)
                    });
                }
            }
            //Set categories
            if (!string.IsNullOrEmpty(roomData.category))
            {
                room.category = ShrineTools.GetEnumValue <PrototypeDungeonRoom.RoomCategory>(roomData.category);
            }
            if (!string.IsNullOrEmpty(roomData.normalSubCategory))
            {
                room.subCategoryNormal = ShrineTools.GetEnumValue <PrototypeDungeonRoom.RoomNormalSubCategory>(roomData.normalSubCategory);
            }
            //========================
            if (!string.IsNullOrEmpty(roomData.bossSubCategory))
            {
                room.subCategoryBoss = ShrineTools.GetEnumValue <PrototypeDungeonRoom.RoomBossSubCategory>(roomData.bossSubCategory);
            }
            //========================
            if (!string.IsNullOrEmpty(roomData.specialSubCategory))
            {
                room.subCategorySpecial = ShrineTools.GetEnumValue <PrototypeDungeonRoom.RoomSpecialSubCategory>(roomData.specialSubCategory);
            }
            room.usesProceduralDecoration = true;
            room.allowFloorDecoration     = roomData.doFloorDecoration;
            room.allowWallDecoration      = roomData.doWallDecoration;
            room.usesProceduralLighting   = roomData.doLighting;
        }