public static void Add(AddonOption addon) { if (Registry.IsActive || !AcceptingAddons) { throw new Mod.Exception("Options must be added before a world is loaded"); } if (string.IsNullOrEmpty(addon.Key)) { throw new Mod.Exception("Key is null or empty"); } if (!KeyRegex.IsMatch(addon.Key)) { throw new Mod.Exception("Key must not contain any non-alphanumeric characters except for an underscore"); } if (OptionRegistry.ContainsKey(addon.Key)) { throw new Mod.Exception("Key already exists"); } if (!ModRegistry.Contains(addon.Link.ModContentPack)) { ModRegistry.Add(addon.Link.ModContentPack); } OptionRegistry.Add(addon.Key, addon); HasAddons = true; }
public static T GetAddonDefaultValue <T>(OptionTarget target, AddonOption addon, T invalidValue = default(T)) { var rules = GetDefaultRules(PawnType.FromTarget(target)); if ((rules == null) || !addon.AllowedInPreset) { return(invalidValue); } return(rules.GetAddonValue(addon, invalidValue)); }
internal static OptionHandle <T> Add <T>(PawnRulesLink link, string key, OptionTarget target, OptionWidget widget, string label, string tooltip, T defaultValue, bool allowedInPreset = true) { var option = new AddonOption(link, link.ModContentPack.PackageId + "_" + key, target, widget, label, tooltip, typeof(T), defaultValue, allowedInPreset); AddonManager.Add(option); var handle = new OptionHandle <T>(option); option.Handle = handle; return(handle); }