Exemple #1
0
        public static LevelFormat GetLevelData(string levelId)
        {
            if (levelId.Length == 0)
            {
                return(null);
            }
            levelId = levelId.ToUpper();

            // Make sure the level exists:
            string fullLevelPath = LevelContent.GetFullLevelPath(levelId);

            if (!File.Exists(fullLevelPath))
            {
                return(null);
            }

            string json = File.ReadAllText(fullLevelPath);

            // If there is no JSON content, end the attempt to load level:
            if (json == "")
            {
                return(null);
            }

            // Load the Data
            return(JsonConvert.DeserializeObject <LevelFormat>(json));
        }
Exemple #2
0
        public bool LoadLevelData(string levelId = "")
        {
            levelId = levelId.ToUpper();

            // Update the Level ID, or use existing Level ID if applicable.
            if (levelId.Length > 0)
            {
                this.levelId = levelId;
            }
            else
            {
                return(false);
            }

            string fullLevelPath = LevelContent.GetFullLevelPath(this.levelId);

            // Make sure the level exists:
            if (!File.Exists(fullLevelPath))
            {
                return(false);
            }

            string json = File.ReadAllText(fullLevelPath);

            // If there is no JSON content, end the attempt to load level:
            if (json == "")
            {
                return(false);
            }

            // Load the Data
            this.data = JsonConvert.DeserializeObject <LevelFormat>(json);

            return(true);
        }
Exemple #3
0
        // Verify that the level exists in the level directory.
        public static bool LevelExists(string levelId)
        {
            levelId = levelId.ToUpper();
            string fullLevelPath = LevelContent.GetFullLevelPath(levelId);

            return(File.Exists(fullLevelPath));
        }
Exemple #4
0
        public static byte[] GetTileData(Dictionary <string, Dictionary <string, ArrayList> > layerData, short gridX, short gridY)
        {
            if (!LevelContent.VerifyTiles(layerData, gridX, gridY))
            {
                return(null);
            }
            ArrayList tileList = layerData[gridY.ToString()][gridX.ToString()];

            return(new byte[] { byte.Parse(tileList[0].ToString()), byte.Parse(tileList[1].ToString()) });
        }
Exemple #5
0
        public LevelContent(string levelPath = null, string levelId = null)
        {
            LevelContent.SetLevelPath(levelPath);

            // Attempt to load Level Data
            if (levelId != null)
            {
                this.LoadLevelData(levelId);
            }
        }
Exemple #6
0
        public GameHandler(string saveId)
        {
            this.saveId = saveId;

            // Make sure the Saves directory exists.
            Systems.filesLocal.MakeDirectory("Saves/" + saveId);
            Systems.filesLocal.MakeDirectory("Saves/" + saveId + "/Campaign");

            // Content
            this.levelContent = new LevelContent();
            this.worldContent = new WorldContent();

            // State
            this.campaignState = new CampaignState(this);
            this.levelState    = new LevelState(this);
            this.playlistState = new PlaylistState(this);
        }
Exemple #7
0
        public static LevelFormat BuildEmptyLevel(string levelId)
        {
            LevelFormat level = new LevelFormat {
                id          = levelId.ToUpper(),
                account     = "",
                title       = "Unnamed Level",
                description = "",
                gameClass   = (byte)GameClassFlag.LevelStandard,
                timeLimit   = 300,
                music       = (byte)MusicTrack.None,
                icon        = new byte[] { 0, 0, 0, 0, 0 },
                rooms       = new List <RoomFormat>()
                {
                    LevelContent.BuildRoomData()
                }
            };

            return(level);
        }
Exemple #8
0
        public static ArrayList GetTileDataWithParams(Dictionary <string, Dictionary <string, ArrayList> > layerData, short gridX, short gridY)
        {
            if (!LevelContent.VerifyTiles(layerData, gridX, gridY))
            {
                return(null);
            }
            ArrayList tileObj = layerData[gridY.ToString()][gridX.ToString()];

            // Convert the parameter list from JObject to Dictionary<string, short>
            if (tileObj.Count > 2)
            {
                // If the parameter list is already a Dictionary<string, short>, we don't need to convert it.
                // This can occur if we recently edited the data in the editor.
                if (tileObj[2] is Dictionary <string, short> == false)
                {
                    tileObj[2] = JsonConvert.DeserializeObject <Dictionary <string, short> >(tileObj[2].ToString());
                }
            }

            return(tileObj);
        }
Exemple #9
0
        }                                                                                   // MusicTrack enum

        public void SaveLevel(string baseDir = null, string destLevelId = null)
        {
            // Determine the Destination Path and Destination Level ID
            if (baseDir == null)
            {
                baseDir = LevelContent.levelPath;
            }
            if (destLevelId == null)
            {
                destLevelId = this.levelId;
            }

            // Can only save a level state if the level ID is assigned correctly.
            if (destLevelId.Length == 0)
            {
                return;
            }
            destLevelId = destLevelId.ToUpper();

            // Make sure the directory exists:
            if (!Directory.Exists(baseDir))
            {
                Directory.CreateDirectory(baseDir);
            }

            // Make sure the level's directory exists:
            string levelDir = LevelContent.GetFullLevelDir(baseDir, destLevelId);

            if (!Directory.Exists(levelDir))
            {
                Directory.CreateDirectory(levelDir);
            }

            // Save State
            string fullDestPath = Path.Combine(baseDir, LevelContent.GetLocalLevelPath(destLevelId));
            string json         = JsonConvert.SerializeObject(this.data);

            File.WriteAllText(fullDestPath, json);
        }
Exemple #10
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);
            }
        }
Exemple #11
0
 public static string GetFullLevelPath(string levelId)
 {
     levelId = levelId.ToUpper();
     return(Path.Combine(LevelContent.levelPath, LevelContent.GetLocalLevelPath(levelId)));
 }