<commit_before>local SWS_ADDON_NAME, StatWeightScore = ...;
local OptionsModule = StatWeightScore:NewModule(SWS_ADDON_NAME.."Options");

local AceConfig = LibStub("AceConfig-3.0");
local AceConfigDialog = LibStub("AceConfigDialog-3.0");
local AceDB = LibStub("AceDB-3.0");
local AceDBOptions = LibStub("AceDBOptions-3.0");

local XmlModule;
local GemsModule;
local StatsModule;

local Utils;
local L;

local ImportTypes = {
    ["sim"] = "SimulationCraft xml"
};

function OptionsModule:CreateOptions()
    self.Defaults = {
        profile = {
            EnableTooltip = true,
            EnchantLevel = 1,
            BlankLineMainAbove = true,
            BlankLineMainBelow = false,
            BlankLineRefAbove = true,
            BlankLineRefBelow = false,
            Specs = {}
        }
    };

    self.Options = {
        type = "group",
        args = {
            General = {
                type = "group",
                get = function(info)
                    return StatWeightScore.db.profile[info[#info]];
                end,
                set = function(info, value)
                    StatWeightScore.db.profile[info[#info]] = value;
                end,
                name = GetAddOnMetadata(SWS_ADDON_NAME, "Title").." v"..StatWeightScore.Version,
                args = {
                    EnableTooltip = {
                        order = 10,
                        type = "toggle",
                        name = L["Options_Enabled"],
                        desc = L["Options_EnabledGlobal_Tooltip"],
                    },
                    EnchantLevel = {
                        order = 20,
                        type = "select",
                        name = L["Options_EnchantLevel_Label"],
                        desc = L["Options_EnchantLevel_Tooltip"],
                        values = function()
                            local v = {};
                            for i, gem in ipairs(GemsModule:GetGems()) do
                                v[i] = gem.Name;
                            end

                            return v;
                        end,
                    },
                    Display = {
                        type = "group",
                        name = "Display",
                        inline = true,
                        args = {
                            BlankLineMainAbove = {
                                order = 30,
                                type = "toggle",
                                name = L["Options_BlankLineMainAbove_Label"],
                                desc = L["Options_BlankLineMainAbove_Tooltip"],
                            },
                            BlankLineMainBelow = {
                                order = 30,
                                type = "toggle",
                                name = L["Options_BlankLineMainBelow_Label"],
                                desc = L["Options_BlankLineMainBelow_Tooltip"],
                            },
                            NewLine1 = {
                                type= 'description',
                                order = 35,
                                name= '',
                            },
                            BlankLineRefAbove = {
                                order = 40,
                                type = "toggle",
                                name = L["Options_BlankLineRefAbove_Label"],
                                desc = L["Options_BlankLineRefAbove_Tooltip"],
                            },
                            BlankLineRefBelow = {
                                order = 40,
                                type = "toggle",
                                name = L["Options_BlankLineRefBelow_Label"],
                                desc = L["Options_BlankLineRefBelow_Tooltip"],
                            },
                        }
                    }
                }
            },
            Weights = {
                type = "group",
                name = L["Options_StatWeightsSetup"],
                args = {
                    CreateNew = {
                        type = "execute",
                        name = L["Options_CreateNewSpec"],
                        func = function()
                            self:CreateNewSpec();
                        end
                    },
                }
            },
            commands = {
                type = "group",
                args = {
                    config = {
                        type = "execute",
                        name = L["Options_Open"],
                        func = function()
                            self:ToggleOptions();
                        end
                    },
                    weights = {
                        type = "execute",
                        name = L["Options_Weights_Open"],
                        func = function()
                            self:ToggleOptions(L["Options_Weights_Section"]);
                        end
                    }
                }
            }
        }
    };
end

function OptionsModule:OnInitialize()
    XmlModule = StatWeightScore:GetModule(SWS_ADDON_NAME.."Xml");
    GemsModule = StatWeightScore:GetModule(SWS_ADDON_NAME.."Gems");
    StatsModule = StatWeightScore:GetModule(SWS_ADDON_NAME.."Stats");
    L = StatWeightScore.L;
    Utils = StatWeightScore.Utils;

    self.ImportType = "sim";

    local db = AceDB:New(SWS_ADDON_NAME.."DB", self.Defaults);
    StatWeightScore.db = db;

    self:MigrateLegacySettings();

    if(not db.profile.Specs) then
        db.profile.Specs = {}
    end

    self:CreateOptions();

    self.Options.args.profiles = AceDBOptions:GetOptionsTable(db);

    for name, _ in pairs(db.profile.Specs) do<commit_msg>moved defaults initialization before db initialization, so it is actually used. really fixes #22<commit_after>local SWS_ADDON_NAME, StatWeightScore = ...;
local OptionsModule = StatWeightScore:NewModule(SWS_ADDON_NAME.."Options");

local AceConfig = LibStub("AceConfig-3.0");
local AceConfigDialog = LibStub("AceConfigDialog-3.0");
local AceDB = LibStub("AceDB-3.0");
local AceDBOptions = LibStub("AceDBOptions-3.0");

local XmlModule;
local GemsModule;
local StatsModule;

local Utils;
local L;

local ImportTypes = {
    ["sim"] = "SimulationCraft xml"
};

OptionsModule.Defaults = {
    profile = {
        EnableTooltip = true,
        EnchantLevel = 1,
        BlankLineMainAbove = true,
        BlankLineMainBelow = false,
        BlankLineRefAbove = true,
        BlankLineRefBelow = false,
        Specs = {}
    }
};


function OptionsModule:CreateOptions()
    self.Options = {
        type = "group",
        args = {
            General = {
                type = "group",
                get = function(info)
                    return StatWeightScore.db.profile[info[#info]];
                end,
                set = function(info, value)
                    StatWeightScore.db.profile[info[#info]] = value;
                end,
                name = GetAddOnMetadata(SWS_ADDON_NAME, "Title").." v"..StatWeightScore.Version,
                args = {
                    EnableTooltip = {
                        order = 10,
                        type = "toggle",
                        name = L["Options_Enabled"],
                        desc = L["Options_EnabledGlobal_Tooltip"],
                    },
                    EnchantLevel = {
                        order = 20,
                        type = "select",
                        name = L["Options_EnchantLevel_Label"],
                        desc = L["Options_EnchantLevel_Tooltip"],
                        values = function()
                            local v = {};
                            for i, gem in ipairs(GemsModule:GetGems()) do
                                v[i] = gem.Name;
                            end

                            return v;
                        end,
                    },
                    Display = {
                        type = "group",
                        name = "Display",
                        inline = true,
                        args = {
                            BlankLineMainAbove = {
                                order = 30,
                                type = "toggle",
                                name = L["Options_BlankLineMainAbove_Label"],
                                desc = L["Options_BlankLineMainAbove_Tooltip"],
                            },
                            BlankLineMainBelow = {
                                order = 30,
                                type = "toggle",
                                name = L["Options_BlankLineMainBelow_Label"],
                                desc = L["Options_BlankLineMainBelow_Tooltip"],
                            },
                            NewLine1 = {
                                type= 'description',
                                order = 35,
                                name= '',
                            },
                            BlankLineRefAbove = {
                                order = 40,
                                type = "toggle",
                                name = L["Options_BlankLineRefAbove_Label"],
                                desc = L["Options_BlankLineRefAbove_Tooltip"],
                            },
                            BlankLineRefBelow = {
                                order = 40,
                                type = "toggle",
                                name = L["Options_BlankLineRefBelow_Label"],
                                desc = L["Options_BlankLineRefBelow_Tooltip"],
                            },
                        }
                    }
                }
            },
            Weights = {
                type = "group",
                name = L["Options_StatWeightsSetup"],
                args = {
                    CreateNew = {
                        type = "execute",
                        name = L["Options_CreateNewSpec"],
                        func = function()
                            self:CreateNewSpec();
                        end
                    },
                }
            },
            commands = {
                type = "group",
                args = {
                    config = {
                        type = "execute",
                        name = L["Options_Open"],
                        func = function()
                            self:ToggleOptions();
                        end
                    },
                    weights = {
                        type = "execute",
                        name = L["Options_Weights_Open"],
                        func = function()
                            self:ToggleOptions(L["Options_Weights_Section"]);
                        end
                    }
                }
            }
        }
    };
end

function OptionsModule:OnInitialize()
    XmlModule = StatWeightScore:GetModule(SWS_ADDON_NAME.."Xml");
    GemsModule = StatWeightScore:GetModule(SWS_ADDON_NAME.."Gems");
    StatsModule = StatWeightScore:GetModule(SWS_ADDON_NAME.."Stats");
    L = StatWeightScore.L;
    Utils = StatWeightScore.Utils;

    self.ImportType = "sim";

    local db = AceDB:New(SWS_ADDON_NAME.."DB", self.Defaults);
    StatWeightScore.db = db;

    self:MigrateLegacySettings();

    self:CreateOptions();

    self.Options.args.profiles = AceDBOptions:GetOptionsTable(db);

    for name, _ in pairs(db.profile.Specs) do
{'fraction_non_alphanumeric': 0.08873483535528597, 'fraction_numerical': 0.004332755632582322, 'mean_word_length': 0.9403160726294553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1496146', 'n_tokens_mistral': 2851, 'n_tokens_neox': 2603, 'n_words': 465}