Exemple #1
0
        /// <summary>
        /// Save a set of game options to file
        /// </summary>
        private static void SaveOptionsToFile(GameOptionsInfo optionsToSave)
        {
            //Convert to JSON Format and save
            string saveData = JsonConvert.SerializeObject(optionsToSave, Formatting.Indented);

            File.WriteAllText(optionsSaveLocaton, saveData);
        }
Exemple #2
0
        /// <summary>
        /// Save the current game options in memory and to file
        /// </summary>
        public static void SaveGameOptions(GameOptionsInfo optionsToSave)
        {
            //Save options in memory
            currentGameOptions = optionsToSave;

            //Save ootions to file
            SaveOptionsToFile(currentGameOptions);

            //Trigger event
            GameOptionsUpdated?.Invoke();
        }
Exemple #3
0
        /// <summary>
        /// Load Game Options from file
        /// </summary>
        /// <returns></returns>
        private static GameOptionsInfo LoadOptionsFromFile()
        {
            //If we don't have an options file then return
            //the default null
            if (!File.Exists(optionsSaveLocaton))
            {
                return(null);
            }

            //Load the options from the file, deserialize and return
            string          loadData      = File.ReadAllText(optionsSaveLocaton);
            GameOptionsInfo loadedOptions = JsonConvert.DeserializeObject <GameOptionsInfo>(loadData);

            return(loadedOptions);
        }
Exemple #4
0
        /// <summary>
        /// Get the current Game Options, from file if none are stored in memory
        /// or the last saved options values in memory
        /// </summary>
        /// <returns>Current Game Options</returns>
        public static GameOptionsInfo GetCurrentGameOptions()
        {
            //If we haven't yet loaded the game options from file,
            //load them
            if (!optionsLoaded)
            {
                currentGameOptions = LoadOptionsFromFile();
                optionsLoaded      = true;
            }

            //If game options are null then assign the default game options
            if (currentGameOptions == null)
            {
                currentGameOptions = new GameOptionsInfo();
            }

            //Return current game options
            return(currentGameOptions);
        }