Exemplo n.º 1
0
        public Mission(IniSection iniSection, bool isCampaignMission)
        {
            InternalName = iniSection.SectionName;
            Side         = iniSection.GetIntValue(nameof(Side), 0);
            Scenario     = iniSection.GetStringValue(nameof(Scenario), string.Empty);
            GUIName      = iniSection.GetStringValue("Description", "Undefined mission");
            if (iniSection.KeyExists("UIName"))
            {
                GUIName = iniSection.GetStringValue("UIName", GUIName);
            }

            IconPath         = iniSection.GetStringValue(nameof(IconPath), string.Empty);
            GUIDescription   = iniSection.GetStringValue("LongDescription", string.Empty);
            PreviewImagePath = iniSection.GetStringValue(nameof(PreviewImagePath), string.Empty);
            RequiredAddon    = iniSection.GetBooleanValue(nameof(RequiredAddon), false);
            Enabled          = iniSection.GetBooleanValue(nameof(Enabled), true);
            BuildOffAlly     = iniSection.GetBooleanValue(nameof(BuildOffAlly), false);
            WarnOnHardWithoutMediumPlayed  = iniSection.GetBooleanValue(nameof(WarnOnHardWithoutMediumPlayed), WarnOnHardWithoutMediumPlayed);
            PlayerAlwaysOnNormalDifficulty = iniSection.GetBooleanValue(nameof(PlayerAlwaysOnNormalDifficulty), false);

            if (iniSection.KeyExists("DifficultyLabels"))
            {
                DifficultyLabels = iniSection.GetListValue("DifficultyLabels", ',', s => s).ToArray();

                if (DifficultyLabels.Length != DifficultyLabelCount)
                {
                    throw new NotSupportedException($"Invalid number of DifficultyLabels= specified for mission { InternalName }: " +
                                                    $"{DifficultyLabels.Length}, expected {DifficultyLabelCount}");
                }
            }

            CampaignInternalName  = iniSection.GetStringValue(nameof(CampaignInternalName), null);
            RequiresUnlocking     = iniSection.GetBooleanValue(nameof(RequiresUnlocking), isCampaignMission);
            UnlockMissions        = iniSection.GetStringValue(nameof(UnlockMissions), string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            UsedGlobalVariables   = iniSection.GetStringValue(nameof(UsedGlobalVariables), string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            UnlockGlobalVariables = iniSection.GetStringValue(nameof(UnlockGlobalVariables), string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            // Parse conditional mission unlocks
            int i = 0;

            while (true)
            {
                string conditionalMissionUnlockData = iniSection.GetStringValue("ConditionalMissionUnlock" + i, null);
                if (string.IsNullOrWhiteSpace(conditionalMissionUnlockData))
                {
                    break;
                }

                var conditionalMissionUnlock = ConditionalMissionUnlock.FromString(conditionalMissionUnlockData);
                if (conditionalMissionUnlock != null)
                {
                    ConditionalMissionUnlocks.Add(conditionalMissionUnlock);
                }

                i++;
            }

            GUIDescription = GUIDescription.Replace("@", Environment.NewLine);
        }
 /// <summary>
 /// Creates a game command and parses its information from an INI section.
 /// </summary>
 /// <param name="iniSection">The INI section.</param>
 public GameCommand(IniSection iniSection)
 {
     ININame       = iniSection.SectionName;
     UIName        = iniSection.GetStringValue("UIName", "Unnamed command");
     Category      = iniSection.GetStringValue("Category", "Unknown category");
     Description   = iniSection.GetStringValue("Description", "Unknown description");
     DefaultHotkey = new Hotkey(iniSection.GetIntValue("DefaultKey", 0));
 }
 /// <summary>
 /// Parses the product version information from an INI section.
 /// </summary>
 /// <param name="section">The INI section.</param>
 public void Parse(IniSection section)
 {
     VersionNumber = section.GetIntValue(VERSION_NUMBER_STRING, 0);
     DisplayString = section.GetStringValue(DISPLAYED_VERSION_STRING, string.Empty);
 }