コード例 #1
0
 public static List <HeroSettings>[] GetSettings()
 {
     // Read hero_settings resource. Each value in array is a line in hero_settings.txt.
     string[] settings = Properties.Resources.hero_settings.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
     // List of settings for each hero.                                                 V +1 due to general settings.
     List <HeroSettings>[] settinglist = new List <HeroSettings> [Enum.GetNames(typeof(Hero)).Length + 1];
     for (int i = 0, heroindex = -1; i < settings.Length; i++)
     {
         if (settings[i].Length >= 1) // Make sure line is not empty
         {
             if (settings[i][0] == '-')
             {
                 heroindex++; // Index of hero to add settings to. 0 = General, 1 = Ana, 2 = Bastion...27 = Zenyatta.
                 settinglist[heroindex] = new List <HeroSettings>();
             }
             if (heroindex != -1 && settings[i][0] != '-')
             {
                 // Add setting to list
                 string[]     settingsData = settings[i].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                 HeroSettings add          = new HeroSettings(
                     settingsData[0],
                     (SettingType)Enum.Parse(typeof(SettingType), settingsData[1])
                     );
                 settinglist[heroindex].Add(add);
             }
         }
     }
     return(settinglist);
 }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hero">Hero to change settings for. Set to null for general settings.</param>
        /// <param name="team">Team to change hero settings for.</param>
        /// <param name="set">Array of settings to change. Must be the same size as setto.</param>
        /// <param name="setTo">Array to change settings to. Must be the same size as set.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="team"/> is Spectator or Queue.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="set"/> or <paramref name="setTo"/> is null.</exception>
        public SetHero(Hero?hero, Team team, string[] set, object[] setTo)
        {
            if (Team.HasFlag(Team.Spectator) || Team.HasFlag(Team.Queue))
            {
                throw new ArgumentOutOfRangeException(nameof(team), team, "Team cannot be Spectator or Queue.");
            }

            if (set == null)
            {
                throw new ArgumentNullException(nameof(set));
            }

            if (setTo == null)
            {
                throw new ArgumentNullException(nameof(setTo));
            }

            if (set.Length != setTo.Length)
            {
                throw new ArgumentException($"{nameof(set)} and {nameof(setTo)} must be the same length.");
            }

            for (int i = 0; i < set.Length; i++)
            {
                SettingType?settingType = HeroSettings.GetSettingType(hero, set[i]);
                // If the setting does not exist.
                if (settingType == null)
                {
                    if (hero != null)
                    {
                        throw new InvalidSetheroException($"The setting \"{set[i]}\" does not exist in {hero.ToString()}'s settings.");
                    }
                    else
                    {
                        throw new InvalidSetheroException($"The setting \"{set[i]}\" does not exist in the general settings.");
                    }
                }
                // For setting types that require a boolean.
                if (settingType == SettingType.toggle)
                {
                    if (setTo[i] is bool == false)
                    {
                        throw new InvalidSetheroException($"The setting \"{set[i]}\" requires a boolean.");
                    }
                }
                // For setting types that require an integer.
                else if (settingType == SettingType.value || settingType == SettingType.dropdown)
                {
                    if (setTo[i] is int == false)
                    {
                        throw new InvalidSetheroException($"The setting \"{set[i]}\" requires a integer.");
                    }
                }
            }

            Hero  = hero;
            Team  = team;
            Set   = set;
            SetTo = setTo;
        }