コード例 #1
0
        /// <summary>
        ///     Initializes the biome data from the given <see cref="ModSettingsPack" /> settings
        ///     and <see cref="BiomeDef" />, creating our settings in the process.
        /// </summary>
        /// <param name="settings">The setting pack to use</param>
        /// <param name="biome">The biome to base this off of</param>
        /// <param name="visibilityFunc">Function which returns if we should display this now</param>
        /// <param name="currentPane">The current settings pane we're on</param>
        /// <param name="weathers">A list of weathers to iterate through</param>
        /// <param name="conditions">A list of game conditions to iterate through</param>
        public BiomeData(ModSettingsPack settings, BiomeDef biome, SettingHandle.ShouldDisplay visibilityFunc,
                         SettingHandle <SettingsPane> currentPane,
                         List <WeatherDef> weathers, List <GameConditionDef> conditions)
        {
            // Build out the key:
            var key = Regex.Replace(biome.defName, "[^A-Za-z]", "");

            // Init all of our various settings
            InitGeneralSettings(settings, biome, key,
                                () => currentPane.Value == SettingsPane.General && visibilityFunc());
            InitWeatherSettings(settings, biome, key, weathers,
                                () => currentPane.Value == SettingsPane.Weather && visibilityFunc());
            InitConditionSettings(settings, key, conditions,
                                  () => currentPane.Value == SettingsPane.Conditions && visibilityFunc());

            // Port things from the v1 labeling:
            var v1Key = Regex.Replace(biome.label, "[^A-Za-z]", ""); // <-- This was a bad plan.

            if (string.IsNullOrEmpty(v1Key))
            {
                return;
            }

            var oldFunc = settings.PeekValue($"temp_func_{v1Key}");

            if (oldFunc != null && settingFunc.HasDefaultValue())
            {
                settingFunc.StringValue = oldFunc;
                settings.TryRemoveUnclaimedValue($"temp_func_{v1Key}");
            }

            var oldMult = settings.PeekValue($"temp_multiplier_{v1Key}");

            if (oldMult != null && settingMultiplier.HasDefaultValue())
            {
                settingMultiplier.StringValue = oldMult;
                settings.TryRemoveUnclaimedValue($"temp_multiplier_{v1Key}");
            }

            var oldOffset = settings.PeekValue($"temp_offset_{v1Key}");

            if (oldOffset == null || !settingOffset.HasDefaultValue())
            {
                return;
            }

            settingOffset.StringValue = settings.PeekValue($"temp_offset_{v1Key}");
            settings.TryRemoveUnclaimedValue($"temp_offset_{v1Key}");
        }