public static void VerifyConfigValues(TreeOverhaulConfig config, TreeOverhaul mod) { bool invalidConfig = false; if (config.SaveSprouts < 0 || config.SaveSprouts > 3) { invalidConfig = true; config.SaveSprouts = 0; } if (config.FruitTreeGrowth < 0 || config.FruitTreeGrowth > 2) { invalidConfig = true; config.FruitTreeGrowth = 0; } if (config.ShakingSeedChance < 0) { invalidConfig = true; config.ShakingSeedChance = 0; } if (config.ShakingSeedChance > 100) { invalidConfig = true; config.ShakingSeedChance = 100; } if (invalidConfig) { mod.DebugLog("At least one config value was out of range and was reset."); mod.Helper.WriteConfig(config); } }
public static void SetUpModConfigMenu(TreeOverhaulConfig config, TreeOverhaul mod) { GenericModConfigMenuAPI api = mod.Helper.ModRegistry.GetApi <GenericModConfigMenuAPI>("spacechase0.GenericModConfigMenu"); if (api == null) { return; } var manifest = mod.ModManifest; api.RegisterModConfig(manifest, () => config = new TreeOverhaulConfig(), delegate { mod.Helper.WriteConfig(config); VerifyConfigValues(config, mod); }); api.RegisterLabel(manifest, "General Tweaks", null); api.RegisterSimpleOption(manifest, "Stop Seed Growth In Shade", "Seeds don't sprout in the 8 surrounding tiles of a tree", () => config.StopShadeSaplingGrowth, (bool val) => config.StopShadeSaplingGrowth = val); api.RegisterSimpleOption(manifest, "Growth Ignores Stumps", "Trees can grow even if a small stump is next to them", () => config.GrowthIgnoresStumps, (bool val) => config.GrowthIgnoresStumps = val); api.RegisterChoiceOption(manifest, "Save Sprouts From Tools", "Normal and fruit trees can't be killed by the selected tools", () => GetElementFromConfig(SSChoices, config.SaveSprouts), (string val) => config.SaveSprouts = GetIndexFromArrayElement(SSChoices, val), SSChoices); api.RegisterLabel(manifest, "Winter Tweaks", null); api.RegisterSimpleOption(manifest, "Normal Trees Grow In Winter", null, () => config.NormalTreesGrowInWinter, (bool val) => config.NormalTreesGrowInWinter = val); api.RegisterSimpleOption(manifest, "Mushroom Trees Grow In Winter", null, () => config.MushroomTreesGrowInWinter, (bool val) => config.MushroomTreesGrowInWinter = val); api.RegisterSimpleOption(manifest, "Fruit Trees Don't Grow In Winter", null, () => config.FruitTreesDontGrowInWinter, (bool val) => config.FruitTreesDontGrowInWinter = val); api.RegisterLabel(manifest, "Buffs And Nerfs", null); api.RegisterSimpleOption(manifest, "Buff Mahogany Tree Growth", "20% unfertilized and 100% fertilized (from 15% and 60%)", () => config.BuffMahoganyTrees, (bool val) => config.BuffMahoganyTrees = val); api.RegisterClampedOption(manifest, "Seed Chance From Shaking", "Chance that a seed drops from shaking a tree (default: 5%, chance depends on host)", () => config.ShakingSeedChance, (int val) => config.ShakingSeedChance = val, 0, 100); api.RegisterSimpleOption(manifest, "Faster Normal Tree Growth", "Normal trees try to grow twice every day, still random whether they succeed", () => config.FasterNormalTreeGrowth, (bool val) => config.FasterNormalTreeGrowth = val); api.RegisterChoiceOption(manifest, "Fruit Tree Growth Options", null, () => GetElementFromConfig(FTChoices, config.FruitTreeGrowth), (string val) => config.FruitTreeGrowth = GetIndexFromArrayElement(FTChoices, val), FTChoices); }
/// <summary> /// The mod entry point, called after the mod is first loaded. /// Loads config file and subscribes methods to some of the events /// </summary> /// <param name="helper">Provides simplified APIs for writing mods.</param> public override void Entry(IModHelper helper) { config = Helper.ReadConfig <TreeOverhaulConfig>(); TreeOverhaulConfig.VerifyConfigValues(config, this); Helper.Events.GameLoop.DayStarted += delegate { OnDayStarted(); }; // when the day ends reset all relevant data for 'SafeSprouts' feature just to be sure. This could happen if the day ends in the middle of an animation. Helper.Events.GameLoop.DayEnding += delegate { ResetSprouts(); SaveMahoganyTreeGrowth(); }; // when we return to title reset all relevant data for 'SafeSprouts' feature just to be sure. Helper.Events.GameLoop.ReturnedToTitle += delegate { ResetSprouts(); }; Helper.Events.GameLoop.UpdateTicked += delegate { CheckForToolUseToSaveSprouts(); }; Helper.Events.Input.ButtonPressed += CheckForWeaponUseToSaveSprouts; Helper.Events.GameLoop.GameLaunched += delegate { TreeOverhaulConfig.SetUpModConfigMenu(config, this); }; }
/// <summary> /// The mod entry point, called after the mod is first loaded. /// Loads config file and adds method to the event of starting a new day. /// </summary> /// <param name="helper">Provides simplified APIs for writing mods.</param> public override void Entry(IModHelper helper) { helper.Events.GameLoop.DayStarted += OnDayStarted; treeOverhaulConfig = helper.ReadConfig <TreeOverhaulConfig>(); }
public override void Entry(IModHelper helper) { TimeEvents.AfterDayStarted += Events_NewDay; treeOverhaulConfig = helper.ReadConfig <TreeOverhaulConfig>(); this.Monitor.Log(GetType().Name + " has loaded", LogLevel.Trace); }