Пример #1
0
        public bool LoadWorldData(string worldId = "")
        {
            worldId = worldId.ToUpper();

            // Update the World ID, or use existing World ID if applicable.
            if (WorldContent.WorldExists(worldId))
            {
                this.worldId = worldId;
            }
            else
            {
                return(false);
            }

            string localPath = WorldContent.GetLocalWorldPath(this.worldId);
            string json      = Systems.filesLocal.ReadFile(localPath);

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

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

            return(true);
        }
Пример #2
0
        public static bool WorldExists(string worldId)
        {
            // Verify the presence of a World ID.
            if (worldId.Length == 0)
            {
                return(false);
            }
            worldId = worldId.ToUpper();

            string localPath = WorldContent.GetLocalWorldPath(worldId);

            // Make sure the world exists:
            return(Systems.filesLocal.FileExists(localPath));
        }
Пример #3
0
        }                                                                                // MusicTrack enum

        public void SaveWorld()
        {
            // Can only save a world state if the world ID is assigned correctly.
            if (this.worldId == null || this.worldId.Length == 0)
            {
                return;
            }
            this.worldId = this.worldId.ToUpper();

            // Determine the Destination Path and Destination Level ID
            string localFile = WorldContent.GetLocalWorldPath(this.worldId);

            // Make sure the directory exists:
            string localDir = Path.GetDirectoryName(localFile);

            Systems.filesLocal.MakeDirectory(localDir, true);

            // Save State
            string json = JsonConvert.SerializeObject(this.data);

            Systems.filesLocal.WriteFile(localFile, json);
        }