コード例 #1
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
        /// <summary>
        /// Sets a <see cref="string"/> value in the modded settings
        /// </summary>
        /// <param name="owner">The <see cref="Mod"/> that owns this setting</param>
        /// <param name="saveID">The id of the setting</param>
        /// <param name="value">The value you want to set the setting to</param>
        /// <param name="writeToFile"><see langword="true"/> if the setting should be written to the save file immediately, <see langword="false"/> if not. It is recommended to set this to <see langword="false"/> and then calling <see cref="WriteSettingsToFile"/> if you set values often</param>
        public static void SetModdedSettingsStringValue(Mod owner, string saveID, string value, bool writeToFile = true)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            OptionsSaver.SetSetting(owner, saveID, value, writeToFile);
        }
コード例 #2
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
        public static void SetModdedSettingsStringValue(Mod mod, string id, string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            OptionsSaver.SetSetting(mod, id, value, true);
        }
コード例 #3
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
        /// <summary>
        /// Gets a <see langword="bool"/> value saved in the loaded settings
        /// </summary>
        /// <param name="mod">The <see cref="Mod"/> that owns the setting</param>
        /// <param name="id">The id of the setting</param>
        /// <param name="defaultValue">The value that should be returned if no saved setting could be found</param>
        /// <returns>The value of the setting, will be the value of defaultValue if the option could not be found</returns>
        public static bool GetModdedSettingsBoolValue(Mod mod, string id, bool defaultValue)
        {
            object value = OptionsSaver.LoadSetting(mod, id);

            if (value != null && value is bool boolValue)
            {
                return(boolValue);
            }

            return(defaultValue);
        }
コード例 #4
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
        /// <summary>
        /// Gets a <see cref="string"/> value saved in the loaded settings
        /// </summary>
        /// <param name="mod">The <see cref="Mod"/> that owns the setting</param>
        /// <param name="id">The id of the setting</param>
        /// <param name="defaultValue">The value that should be returned if no saved setting could be found</param>
        /// <returns>The value of the setting, will be the value of defaultValue if the option could not be found</returns>
        public static string GetModdedSettingsStringValue(Mod mod, string id, string defaultValue)
        {
            object value = OptionsSaver.LoadSetting(mod, id);

            if (value != null && value is string)
            {
                return(value as string);
            }

            return(defaultValue);
        }
コード例 #5
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
        /// <summary>
        /// Gets a <see cref="KeyCode"/> value saved in the loaded settings
        /// </summary>
        /// <param name="mod">The <see cref="Mod"/> that owns the setting</param>
        /// <param name="id">The id of the setting</param>
        /// <param name="defaultValue">The value that should be returned if no saved setting could be found</param>
        /// <returns>The value of the setting, will be the value of defaultValue if the option could not be found</returns>
        public static KeyCode GetModdedSettingsKeyCodeValue(Mod mod, string id, KeyCode defaultValue)
        {
            object value = OptionsSaver.LoadSetting(mod, id);

            if (value != null && value is int intValue)
            {
                return((KeyCode)intValue);
            }

            return(defaultValue);
        }
コード例 #6
0
        private static void InitializeOptions()
        {
            var executablePath = Path.GetDirectoryName(Application.ExecutablePath);

            if (executablePath == null)
            {
                return;
            }
            var fileName = Path.Combine(executablePath, "options.xml");

            saver   = new OptionsSaver(fileName);
            options = saver.LoadOptions();
        }
コード例 #7
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
        /// <summary>
        /// Gets a <see langword="int"/> value saved in the loaded settings
        /// </summary>
        /// <param name="mod">The <see cref="Mod"/> that owns the setting</param>
        /// <param name="id">The id of the setting</param>
        /// <param name="defaultValue">The value that should be returned if no saved setting could be found</param>
        /// <returns>The value of the setting, will be the value of defaultValue if the option could not be found</returns>
        public static int GetModdedSettingsIntValue(Mod mod, string id, int defaultValue)
        {
            object value = OptionsSaver.LoadSetting(mod, id);

            if (value != null)
            {
                if (value is int intValue)
                {
                    return(intValue);
                }

                if (value is long longValue)
                {
                    return((int)longValue);
                }
            }

            return(defaultValue);
        }
コード例 #8
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
        /// <summary>
        /// Gets a <see langword="float"/> value saved in the loaded settings
        /// </summary>
        /// <param name="mod">The <see cref="Mod"/> that owns the setting</param>
        /// <param name="id">The id of the setting</param>
        /// <param name="defaultValue">The value that should be returned if no saved setting could be found</param>
        /// <returns>The value of the setting, will be the value of defaultValue if the option could not be found</returns>
        public static float GetModdedSettingsFloatValue(Mod mod, string id, float defaultValue)
        {
            object value = OptionsSaver.LoadSetting(mod, id);

            if (value != null)
            {
                if (value is float floatValue)
                {
                    return(floatValue);
                }

                if (value is double doubleValue)
                {
                    return((float)doubleValue);
                }
            }

            return(defaultValue);
        }
コード例 #9
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
 /// <summary>
 /// Returns if a setting with the given owner and ID is saved
 /// </summary>
 /// <param name="owner">The <see cref="Mod"/> that owns the setting</param>
 /// <param name="saveID">The ID of the setting</param>
 public static bool HasSetting(Mod owner, string saveID)
 {
     return(OptionsSaver.HasSettingSaved(owner, saveID));
 }
コード例 #10
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
 /// <summary>
 /// Saves all settings to the settings file, use this to manually write to the file if you passed <see langword="false"/> to any of the SetModdedSettings_____Value methods
 /// </summary>
 public static void WriteSettingsToFile()
 {
     OptionsSaver.SaveToFile();
 }
コード例 #11
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
 /// <summary>
 /// Sets a <see cref="KeyCode"/> value in the loaded settings
 /// </summary>
 /// <param name="mod">The <see cref="Mod"/> that owns this setting</param>
 /// <param name="id">The id of the setting</param>
 /// <param name="value">The value you want to set the setting to</param>
 /// <param name="writeToFile"><see langword="true"/> if the setting should be written to the save file immediately, <see langword="false"/> if not. It is recommended to set this to <see langword="false"/> and then calling <see cref="WriteSettingsToFile"/> if you set values often</param>
 public static void SetModdedSettingsKeyCodeValue(Mod mod, string id, KeyCode value, bool writeToFile = true)
 {
     OptionsSaver.SetSetting(mod, id, (int)value, writeToFile);
 }
コード例 #12
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
 /// <summary>
 /// Sets a <see langword="bool"/> value in the loaded settings
 /// </summary>
 /// <param name="mod">The <see cref="Mod"/> that owns this setting</param>
 /// <param name="id">The id of the setting</param>
 /// <param name="value">The value you want to set the setting to</param>
 /// <param name="writeToFile"><see langword="true"/> if the setting should be written to the save file immediately, <see langword="false"/> if not. It is recommended to set this to <see langword="false"/> and then calling <see cref="WriteSettingsToFile"/> if you set values often</param>
 public static void SetModdedSettingsBoolValue(Mod mod, string id, bool value, bool writeToFile = true)
 {
     OptionsSaver.SetSetting(mod, id, value, writeToFile);
 }
コード例 #13
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
 /// <summary>
 /// Sets a <see langword="int"/> value in the loaded settings
 /// </summary>
 /// <param name="owner">The <see cref="Mod"/> that owns this setting</param>
 /// <param name="saveID">The id of the setting</param>
 /// <param name="value">The value you want to set the setting to</param>
 /// <param name="writeToFile"><see langword="true"/> if the setting should be written to the save file immediately, <see langword="false"/> if not. It is recommended to set this to <see langword="false"/> and then calling <see cref="WriteSettingsToFile"/> if you set values often</param>
 public static void SetModdedSettingsIntValue(Mod owner, string saveID, int value, bool writeToFile = true)
 {
     OptionsSaver.SetSetting(owner, saveID, value, writeToFile);
 }
コード例 #14
0
ファイル: ModdedSettings.cs プロジェクト: fyrkantis/ModBot
 public static void SetModdedSettingsIntValue(Mod mod, string id, int value)
 {
     OptionsSaver.SetSetting(mod, id, value, true);
 }