AinaVT / LethalConfig

A mod configuration menu for Lethal Company
https://thunderstore.io/c/lethal-company/p/AinaVT/LethalConfig/
GNU General Public License v3.0
15 stars 6 forks source link

Cannot create multiple GenericButtonConfigItems #38

Closed FerusGrim closed 6 months ago

FerusGrim commented 6 months ago

When creating a GenericButtonConfigItem, the first one registers fine, but the second is discarded as a duplicate.

[Info   :ainavt.lc.lethalconfig] Registered config "LethalConfig.ConfigItems.GenericButtonConfigItem"
[Warning:ainavt.lc.lethalconfig] Ignoring duplicated config "LethalConfig.ConfigItems.GenericButtonConfigItem"
        LethalConfigManager.AddConfigItem(new GenericButtonConfigItem("Actions", "Reset",
            "Reset all settings to their default values", "Reset", () =>
            {
                // Toggle logic
            }));

        LethalConfigManager.AddConfigItem(new GenericButtonConfigItem("Actions", "Toggle", "Manually toggle the plugin", "Toggle", LessBrightHarmonyPatch.ToggleLight));

There is no way I can see to differentiate these two items, other than the section and name, yet the second is not being identified as a separate item.

I'm sure I'm missing something, but I'm at a loss. :)

FerusGrim commented 6 months ago

I could not figure out how to properly import this project, so I don't want to make a PR with, likely, broken code. However, I believe this should solve this issue:

        internal bool IsSameConfig(BaseConfigItem configItem)
        {
            var isSameSection;
            var isSameKey;
            if (configItem is GenericButtonConfigItem otherButton && this is GenericButtonConfigItem button)
            {
                isSameSection = otherButton.ButtonOptions.Section == button.ButtonOptions.Section;
                isSameKey = otherButton.ButtonOptions.Name == button.ButtonOptions.Name;
            }
            else
            {
                isSameSection = configItem.UnderlyingSection == UnderlyingSection;
                isSameKey = configItem.UnderlyingName == UnderlyingName;
            }
            var isSameMod = configItem.Owner.modInfo.GUID == Owner.modInfo.GUID;
            return isSameSection && isSameKey && isSameMod;
        }
    }
AinaVT commented 6 months ago

Please, if you can, test with the latest version (1.4.0).

FerusGrim commented 6 months ago

Thank you very much! Issue has been resolved as of edff15e1b40d4d89f22330b1740a9045319f8fc4!