From 6ab94d24198a59551ad7cb4beb45329edad4692d Mon Sep 17 00:00:00 2001 From: Munglunch Date: Wed, 24 Sep 2014 15:55:26 -0500 Subject: [PATCH] many changes --- Interface/AddOns/SVUI/SVUI.lua | 8 +- Interface/AddOns/SVUI/configs/configs.lua | 13 +- Interface/AddOns/SVUI/docs/configs.lua | 66 +++ Interface/AddOns/SVUI/docs/schema.lua | 116 +++++ .../LibSuperVillain-1.0/LibSuperVillain-1.0.lua | 237 ++++----- .../SVUI/libs/LibSuperVillain-1.0/src/database.lua | 356 ------------- .../libs/LibSuperVillain-1.0/src/librarian.lua | 61 --- .../SVUI/libs/LibSuperVillain-1.0/src/linguist.lua | 74 --- .../SVUI/libs/LibSuperVillain-1.0/src/registry.lua | 527 -------------------- Interface/AddOns/SVUI/libs/libs.xml | 2 +- Interface/AddOns/SVUI/packages/bag/SVBag.lua | 10 +- Interface/AddOns/SVUI/packages/map/SVMap.lua | 4 +- .../AddOns/SVUI/packages/override/SVOverride.lua | 2 +- Interface/AddOns/SVUI/scripts/mounts.lua | 2 +- Interface/AddOns/SVUI/scripts/questwatch.lua | 2 +- Interface/AddOns/SVUI/system/load.lua | 2 +- Interface/AddOns/SVUI/system/setup.lua | 8 +- .../SVUI_AnsweringService.lua | 4 +- Interface/AddOns/SVUI_ArtOfWar/SVUI_ArtOfWar.lua | 4 +- .../AddOns/SVUI_ConfigOMatic/SVUI_ConfigOMatic.lua | 2 +- .../AddOns/SVUI_ConfigOMatic/modules/_load.xml | 2 - Interface/AddOns/SVUI_ConfigOMatic/modules/art.lua | 340 ------------- Interface/AddOns/SVUI_Laborer/SVUI_Laborer.lua | 4 +- Interface/AddOns/SVUI_LogOMatic/SVUI_LogOMatic.lua | 4 +- .../AddOns/SVUI_StyleOMatic/SVUI_StyleOMatic.lua | 8 +- Interface/AddOns/SVUI_StyleOMatic/addons/guild.lua | 2 +- .../AddOns/SVUI_StyleOMatic/addons/petjournal.lua | 2 +- Interface/AddOns/SVUI_StyleOMatic/addons/pvp.lua | 2 +- Interface/AddOns/SVUI_StyleOMatic/addons/quest.lua | 2 +- .../AddOns/SVUI_StyleOMatic/addons/system.lua | 2 +- .../AddOns/SVUI_StyleOMatic/addons/worldmap.lua | 6 +- .../SVUI_TrackingDevice/SVUI_TrackingDevice.lua | 6 +- 32 files changed, 336 insertions(+), 1544 deletions(-) create mode 100644 Interface/AddOns/SVUI/docs/configs.lua create mode 100644 Interface/AddOns/SVUI/docs/schema.lua delete mode 100644 Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/database.lua delete mode 100644 Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/librarian.lua delete mode 100644 Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/linguist.lua delete mode 100644 Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/registry.lua delete mode 100644 Interface/AddOns/SVUI_ConfigOMatic/modules/art.lua diff --git a/Interface/AddOns/SVUI/SVUI.lua b/Interface/AddOns/SVUI/SVUI.lua index 3a650e0..262b6c3 100644 --- a/Interface/AddOns/SVUI/SVUI.lua +++ b/Interface/AddOns/SVUI/SVUI.lua @@ -172,13 +172,13 @@ local Core_StaticPopup_Show = function(self, arg) end local Core_Debugger = function(self, msg) - if(not self.___debugging) then return end - local outbound = (debugPattern):format(self.___addonName, "DEBUG") + if(not self.DebugMode) then return end + local outbound = (debugPattern):format(self.NameID, "DEBUG") _sendmessage(msg, outbound) end local Core_AddonMessage = function(self, msg) - local outbound = (messagePattern):format(self.___addonName) + local outbound = (messagePattern):format(self.NameID) _sendmessage(msg, outbound) end @@ -258,6 +258,8 @@ end --[[ INITIALIZE THE CORE OBJECT ]]-- +-- We have to send the names of our three SavedVariables files since the WoW API +-- has no method for parsing them in LUA. local SVUI = SVLib:NewCore("SVUI_Global", "SVUI_Profile", "SVUI_Cache") SVUI.Snap = {} diff --git a/Interface/AddOns/SVUI/configs/configs.lua b/Interface/AddOns/SVUI/configs/configs.lua index 3e2d252..ae73b11 100644 --- a/Interface/AddOns/SVUI/configs/configs.lua +++ b/Interface/AddOns/SVUI/configs/configs.lua @@ -17,18 +17,7 @@ GET ADDON DATA ########################################################## ]]-- local SVUI_ADDON_NAME, SV = ... ---[[ -##################################################################################### - /$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$$$/$$$$$$ /$$$$$$ /$$$$$$ - /$$__ $$ /$$__ $$| $$$ | $$| $$_____/_ $$_/ /$$__ $$ /$$__ $$ -| $$ \__/| $$ \ $$| $$$$| $$| $$ | $$ | $$ \__/| $$ \__/ -| $$ | $$ | $$| $$ $$ $$| $$$$$ | $$ | $$ /$$$$| $$$$$$ -| $$ | $$ | $$| $$ $$$$| $$__/ | $$ | $$|_ $$ \____ $$ -| $$ $$| $$ | $$| $$\ $$$| $$ | $$ | $$ \ $$ /$$ \ $$ -| $$$$$$/| $$$$$$/| $$ \ $$| $$ /$$$$$$| $$$$$$/| $$$$$$/ - \______/ \______/ |__/ \__/|__/ |______/ \______/ \______/ -##################################################################################### -]]-- + local playerClass = select(2, UnitClass("player")); local filterClass = playerClass or "NONE" diff --git a/Interface/AddOns/SVUI/docs/configs.lua b/Interface/AddOns/SVUI/docs/configs.lua new file mode 100644 index 0000000..b2409d8 --- /dev/null +++ b/Interface/AddOns/SVUI/docs/configs.lua @@ -0,0 +1,66 @@ +--[[ +############################################################################## +_____/\\\\\\\\\\\____/\\\________/\\\__/\\\________/\\\__/\\\\\\\\\\\_ # + ___/\\\/////////\\\_\/\\\_______\/\\\_\/\\\_______\/\\\_\/////\\\///__ # + __\//\\\______\///__\//\\\______/\\\__\/\\\_______\/\\\_____\/\\\_____ # + ___\////\\\__________\//\\\____/\\\___\/\\\_______\/\\\_____\/\\\_____ # + ______\////\\\________\//\\\__/\\\____\/\\\_______\/\\\_____\/\\\_____ # + _________\////\\\______\//\\\/\\\_____\/\\\_______\/\\\_____\/\\\_____ # + __/\\\______\//\\\______\//\\\\\______\//\\\______/\\\______\/\\\_____ # + _\///\\\\\\\\\\\/________\//\\\________\///\\\\\\\\\/____/\\\\\\\\\\\_# + ___\///////////___________\///___________\/////////_____\///////////_# +############################################################################## +S U P E R - V I L L A I N - U I By: Munglunch # +############################################################################## + /$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$$$/$$$$$$ /$$$$$$ /$$$$$$ # + /$$__ $$ /$$__ $$| $$$ | $$| $$_____/_ $$_/ /$$__ $$ /$$__ $$ # +| $$ \__/| $$ \ $$| $$$$| $$| $$ | $$ | $$ \__/| $$ \__/ # +| $$ | $$ | $$| $$ $$ $$| $$$$$ | $$ | $$ /$$$$| $$$$$$ # +| $$ | $$ | $$| $$ $$$$| $$__/ | $$ | $$|_ $$ \____ $$ # +| $$ $$| $$ | $$| $$\ $$$| $$ | $$ | $$ \ $$ /$$ \ $$ # +| $$$$$$/| $$$$$$/| $$ \ $$| $$ /$$$$$$| $$$$$$/| $$$$$$/ # + \______/ \______/ |__/ \__/|__/ |______/ \______/ \______/ # +############################################################################## +]]-- + +--[[ + + The "configs" property is the default (also the backup) of ALL usable database entries. + When the addon core is initialized, a "db" property is created using a copy of "configs". + + When configs are set under their own index (ie.. SV.configs["Shiznit"]) AND a module (package, plugin ...etc) + has a schema (see NOTE) of the same name, then that index is used to set + the module's own "db" property using a pointer reference linking to the core database location. + + Package configs should be set in the primary config file (configs/configs.lua) since they are + treated and loaded as internal entities. + + For new packages (not already defined in my default configs) you will need to know the + associated schema name specific to that package. + + Just add the new package configs to the BOTTOM of the config file like this: + +]]-- + +-- SV and SV.configs will have already been defined +local Schema = "SumFukinPackage" +SV.configs[Schema] = { SumFukinValue = true } + +--[[ + + When adding plugins to the collective, be sure to set respective entries BEFORE loading, + as the same process takes place for externally connected addons. + + Plugin configs can be set like this: + +]]-- + +local SV = _G["SVUI"] +local Schema = _G["SumFukinPlugin"].Schema -- Get the already assigned schema name +SV.configs[Schema] = { SumFukinValue = true } + +--[[ + + NOTE: Schema and Modules are explained in their respective documents + +]]-- \ No newline at end of file diff --git a/Interface/AddOns/SVUI/docs/schema.lua b/Interface/AddOns/SVUI/docs/schema.lua new file mode 100644 index 0000000..8b878db --- /dev/null +++ b/Interface/AddOns/SVUI/docs/schema.lua @@ -0,0 +1,116 @@ +--[[ +############################################################################## +_____/\\\\\\\\\\\____/\\\________/\\\__/\\\________/\\\__/\\\\\\\\\\\_ # + ___/\\\/////////\\\_\/\\\_______\/\\\_\/\\\_______\/\\\_\/////\\\///__ # + __\//\\\______\///__\//\\\______/\\\__\/\\\_______\/\\\_____\/\\\_____ # + ___\////\\\__________\//\\\____/\\\___\/\\\_______\/\\\_____\/\\\_____ # + ______\////\\\________\//\\\__/\\\____\/\\\_______\/\\\_____\/\\\_____ # + _________\////\\\______\//\\\/\\\_____\/\\\_______\/\\\_____\/\\\_____ # + __/\\\______\//\\\______\//\\\\\______\//\\\______/\\\______\/\\\_____ # + _\///\\\\\\\\\\\/________\//\\\________\///\\\\\\\\\/____/\\\\\\\\\\\_# + ___\///////////___________\///___________\/////////_____\///////////_# +############################################################################## +S U P E R - V I L L A I N - U I By: Munglunch # +############################################################################## + /$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$$$ /$$ /$$ /$$$$$$ # + /$$__ $$ /$$__ $$| $$ | $$| $$_____/| $$$ /$$$ /$$__ $$ # +| $$ \__/| $$ \__/| $$ | $$| $$ | $$$$ /$$$$| $$ \ $$ # +| $$$$$$ | $$ | $$$$$$$$| $$$$$ | $$ $$/$$ $$| $$$$$$$$ # + \____ $$| $$ | $$__ $$| $$__/ | $$ $$$| $$| $$__ $$ # + /$$ \ $$| $$ $$| $$ | $$| $$ | $$\ $ | $$| $$ | $$ # +| $$$$$$/| $$$$$$/| $$ | $$| $$$$$$$$| $$ \/ | $$| $$ | $$ # + \______/ \______/ |__/ |__/|________/|__/ |__/|__/ |__/ # +############################################################################## +]]-- + +--[[ + + Schema is a property and concept used to help dynamically define database indexes. + The main purpose for its creation was to provide a way to generate useable config + variables for any plugin, including those that are LoadOnDemand! + + To the best of my knowledge, this has never been done before (/flex)! + + The schema convention is utilized by the "LibSuperVillain" library to ensure + proper organization of our various addon configs (see NOTE) + + For Packages: + + You have to define the modules schema when you send its object to the library + + Here is an example: + +]]-- + +local lib = LibStub("LibSuperVillain-1.0") +local PKG = {}; + +--Here you would build your package object, then... + +lib:NewPackage(PKG, "SumFukinPackage") + +--So now you can get the schema name like this: + +local Schema = PKG.Schema + +--[[ + + For Plugins: + + You will set the schema in the plugins .toc file using meta-data fields + prefixed with "X" to indicate its a custom entry, the SuperVillain indicator "SVUI", + and finally the type of entry it is + + (there are two possibilities at the time of this writing. "Header" and "Schema") + + so it will end up looking like this: + X-SVUI-Header + + or this: + X-SVUI-Schema + + Your toc should end up looking something like this: + + ~(SumFukinPlugin.toc) + + ## Interface: 60000 + ## Author: SumFukinDude + ## Version: 1.0 + ## X-SVUI-Header: Some Fukin Addon + ## X-SVUI-Schema: SumFukinSchema + + + Having defined and initialized all requirements at this point, your database will now + have named references linking to this object by schema. +]]-- + +--[[ + + LoadOnDemand: + + When schema is defined for plugins that are NOT loaded by default, the library will + be able to parse all toc files that contain an "X-SVUI-Schema" property and generate + a database entry as well as a config option so that we can manipulate that plugin and + save our changes. + + The benefit here is this: + + Let's use SVUI_Laborer for example. If by default this LOD addon is Disabled, we can't read + on any lua code inside the addon. This prevents the ability to set config variables and therefore + build config options. Before we would have had to add a button to allow the player to click and "Enable" it. + This is fine but what if we also want to make the choice to keep it enabled every time we log in? + That would not have worked since your options would not be loaded UNTIL you clicked the enable button! + Using schema however, we can still create our configs + AND set the data entry from saved variables (if they exist in the file) + which allows our core to not only detect its existence but also see if it was previously enabled + and if so then go ahead and load/enable the addon. + + BOOM!! + +]]-- + +--[[ + + NOTE: Configs and Modules are explained in their respective documents + +]]-- \ No newline at end of file diff --git a/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/LibSuperVillain-1.0.lua b/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/LibSuperVillain-1.0.lua index ed31a2f..2d89317 100644 --- a/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/LibSuperVillain-1.0.lua +++ b/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/LibSuperVillain-1.0.lua @@ -84,17 +84,17 @@ if not lib then return end --[[ ADDON DATA ]]-- -local AddonName, AddonCore = ... +local CoreName, CoreObject = ... local AddonVersion = GetAddOnMetadata(..., "Version"); -local SchemaFromMeta = "X-" .. AddonName .. "-Schema"; -local HeaderFromMeta = "X-" .. AddonName .. "-Header"; +local SchemaFromMeta = "X-" .. CoreName .. "-Schema"; +local HeaderFromMeta = "X-" .. CoreName .. "-Header"; local InterfaceVersion = select(4, GetBuildInfo()); --[[ COMMON LOCAL VARS ]]-- -local GLOBAL_FILENAME = AddonName.."_Global"; -local PROFILE_FILENAME = AddonName.."_Profile"; -local CACHE_FILENAME = AddonName.."_Cache"; +local GLOBAL_FILENAME = CoreName.."_Global"; +local PROFILE_FILENAME = CoreName.."_Profile"; +local CACHE_FILENAME = CoreName.."_Cache"; local SOURCE_KEY = 1; local GLOBAL_SV, PROFILE_SV, CACHE_SV; local PluginString = "" @@ -115,7 +115,7 @@ lib.EventManager = CreateFrame("Frame", nil) --[[ COMMON META METHODS ]]-- -local rootstring = function(self) return self.___addonName end +local rootstring = function(self) return self.NameID end --[[ CUSTOM LUA METHODS ]]-- @@ -304,7 +304,7 @@ local function tablecopy(d, s) if type(v) == "table" then if not saved then rawset(d, k, {}) end tablecopy(d[k], v) - elseif(not saved or (saved and type(saved) ~= type(v))) then + elseif(saved == nil or (saved and type(saved) ~= type(v))) then rawset(d, k, v) end end @@ -390,12 +390,12 @@ local meta_database = { local src = dv and dv[k] --print(k .. " - " .. tostring(src)) - if(src) then + if(src ~= nil) then if(type(src) == "table") then - if(sv[k] == nil) then sv[k] = {} end + if(sv[k] == nil or (sv[k] ~= nil and type(sv[k]) ~= "table")) then sv[k] = {} end tablecopy(sv[k], src) else - if(sv[k] == nil or (sv[k] and type(sv[k]) ~= type(src))) then sv[k] = src end + if(sv[k] == nil or (sv[k] ~= nil and type(sv[k]) ~= type(src))) then sv[k] = src end end end @@ -431,7 +431,7 @@ end function lib:ImportDatabase(key) if(not GLOBAL_SV.profiles[key]) then GLOBAL_SV.profiles[key] = {} end; local import = GLOBAL_SV.profiles[key]; - local saved = rawget(AddonCore.db, "data"); + local saved = rawget(CoreObject.db, "data"); import.importTest = true; --Testing value, will be removed next time the UI is reloaded for k,v in pairs(import) do @@ -439,7 +439,7 @@ function lib:ImportDatabase(key) end --Ensure that import was successful - if(not AddonCore.db.importTest) then + if(not CoreObject.db.importTest) then --If no test value found, might need reloading --Not the most clever thing in the world but.... print("Profile Error") @@ -450,7 +450,7 @@ end function lib:ExportDatabase(key) if(not GLOBAL_SV.profiles[key]) then GLOBAL_SV.profiles[key] = {} end; - local export = rawget(AddonCore.db, "data"); + local export = rawget(CoreObject.db, "data"); local saved = GLOBAL_SV.profiles[key]; tablecopy(saved, export); @@ -461,7 +461,7 @@ function lib:ExportDatabase(key) end function lib:WipeDatabase() - local sv = rawget(AddonCore.db, "data") + local sv = rawget(CoreObject.db, "data") for k,v in pairs(sv) do sv[k] = nil end @@ -469,8 +469,8 @@ end function lib:UpdateDatabase(event) if event == "PLAYER_LOGOUT" then - local sv = rawget(AddonCore.db, "data") - local src = rawget(AddonCore.db, "defaults") + local sv = rawget(CoreObject.db, "data") + local src = rawget(CoreObject.db, "defaults") for k,v in pairs(sv) do if(not src[k]) then sv[k] = nil @@ -492,24 +492,12 @@ function lib:UpdateDatabase(event) self.EventManager:UnregisterEvent("ACTIVE_TALENT_GROUP_CHANGED") end - local BACKUP_DATA = rawget(AddonCore.db, "defaults") - local db = setmetatable({}, meta_database) - db.data = PROFILE_SV.STORED[SOURCE_KEY] - db.defaults = BACKUP_DATA - - AddonCore.db = db + local data = CoreObject.db + local source = PROFILE_SV.STORED[SOURCE_KEY] + rawset(data, "data", source) end end -function lib:GetSourceData(schema) - return PROFILE_SV.STORED[SOURCE_KEY][schema] -end - -function lib:SetSourceData(schema, key, value) - print(schema) - PROFILE_SV.STORED[SOURCE_KEY][schema][key] = value -end - function lib:GetSafeData(index) return PROFILE_SV.SAFEDATA[index] end @@ -534,13 +522,13 @@ function lib:CheckData(schema, key) end function lib:NewDatabase(obj) - local schema = obj.___schema - obj.db = AddonCore.db[schema] or {} + local schema = obj.Schema + obj.db = CoreObject.db[schema] or {} obj.ResetData = setDefault end function lib:NewCache(index) - index = index or AddonCore.___schema + index = index or CoreObject.Schema AllowedIndexes[index] = true if(not CACHE_SV[index]) then CACHE_SV[index] = {} @@ -625,7 +613,7 @@ local innerOnUpdate = function(self, elapsed) for name, fn in pairs(callbacks) do local _, error = pcall(fn, obj) - if(error and AddonCore.Debugging) then + if(error and CoreObject.Debugging) then print(error) end end @@ -664,38 +652,11 @@ local unregisterUpdate = function(self, updatefunc) end local appendOptions = function(self, index, data) - local addonName = self.___addonName - local schema = self.___schema + local addonName = self.NameID + local schema = self.Schema local header = GetAddOnMetadata(addonName, HeaderFromMeta) - AddonCore.Options.args.plugins.args.pluginOptions.args[schema].args[index] = data -end - -local function LoadMods() - if ModuleQueue then - for i=1,#ModuleQueue do - local schema = ModuleQueue[i] - local obj = AddonCore[schema] - if obj and not obj.initialized then - obj.initialized = true; - local halt = false - lib:NewDatabase(obj) - if(obj.db.incompatible) then - for addon,_ in pairs(obj.db.incompatible) do - if IsAddOnLoaded(addon) then halt = true end - end - end - if obj.Load then - if(not halt) then - obj:Load() - obj.Load = nil - end - end - end - end - - twipe(ModuleQueue) - end + CoreObject.Options.args.plugins.args.pluginOptions.args[schema].args[index] = data end local function SetPluginString(addonName) @@ -705,7 +666,7 @@ local function SetPluginString(addonName) return INFO_FORMAT:format(name, version, author) end -local function SetInternalModule(obj, schema) +local function SetInternalModule(obj, schema, header) local addonmeta = {} local oldmeta = getmetatable(obj) if oldmeta then @@ -716,9 +677,9 @@ local function SetInternalModule(obj, schema) local addonName = ("SVUI [%s]"):format(schema) - obj.___addonName = addonName - obj.___schema = schema - obj.___dbDebug = false + obj.NameID = addonName + obj.Schema = schema + obj.TitleID = header if not obj.db then obj.db = {} end @@ -742,14 +703,12 @@ local function SetExternalModule(obj, schema, addonName, header, lod) addonmeta.__tostring = rootstring setmetatable( obj, addonmeta ) - obj.___addonName = addonName - obj.___schema = schema - obj.___header = header - obj.___isPlugin = true - obj.___lod = lod + obj.NameID = addonName + obj.Schema = schema + obj.TitleID = header - if(AddonCore.configs[schema]) then - obj.db = AddonCore.configs[schema] + if(CoreObject.configs[schema]) then + obj.db = CoreObject.configs[schema] else obj.db = {} end @@ -764,7 +723,7 @@ local function SetExternalModule(obj, schema, addonName, header, lod) obj.AddOption = appendOptions if(IsAddOnLoaded(addonName) and not lod) then - AddonCore.Options.args.plugins.args.pluginOptions.args[schema] = { + CoreObject.Options.args.plugins.args.pluginOptions.args[schema] = { type = "group", name = header, childGroups = "tree", @@ -774,7 +733,7 @@ local function SetExternalModule(obj, schema, addonName, header, lod) type = "toggle", name = "Enable", get = function() return obj.db.enable end, - set = function(key, value) obj:ChangeDBVar(value, "enable"); AddonCore:StaticPopup_Show("RL_CLIENT") end, + set = function(key, value) obj:ChangeDBVar(value, "enable"); CoreObject:StaticPopup_Show("RL_CLIENT") end, } } } @@ -797,27 +756,26 @@ function lib:NewScript(fn) end function lib:NewPackage(obj, schema, defaults) - if(AddonCore[schema]) then return end + if(CoreObject[schema]) then return end ModuleQueue[#ModuleQueue+1] = schema Modules[#Modules+1] = schema AllowedIndexes[schema] = true - AddonCore[schema] = SetInternalModule(obj, schema) + CoreObject[schema] = SetInternalModule(obj, schema) - if(AddonCore.AddonLaunched and not AddonCore[schema].initialized) then - --print("NewPackage - " .. schema .. ": New Database") - self:NewDatabase(AddonCore[schema]) - if(AddonCore[schema].Load) then - AddonCore[schema]:Load() + if(CoreObject.AddonLaunched and not CoreObject[schema].initialized) then + self:NewDatabase(CoreObject[schema]) + if(CoreObject[schema].Load) then + CoreObject[schema]:Load() end - AddonCore[schema].initialized = true + CoreObject[schema].initialized = true end end function lib:NewPlugin(obj) - local coreName = AddonCore.___addonName - local addonName = obj.___addonName + local coreName = CoreObject.NameID + local addonName = obj.NameID if(addonName and addonName ~= coreName) then local header = GetAddOnMetadata(addonName, HeaderFromMeta) @@ -833,15 +791,15 @@ function lib:NewPlugin(obj) PluginString = ("%s%s\n"):format(oldString, infoString) - AddonCore[schema] = SetExternalModule(obj, schema, addonName, header, lod) + CoreObject[schema] = SetExternalModule(obj, schema, addonName, header, lod) - if(AddonCore.AddonLaunched and not AddonCore[schema].initialized) then + if(CoreObject.AddonLaunched and not CoreObject[schema].initialized) then --print("NewPlugin - " .. schema .. ": New Database") - self:NewDatabase(AddonCore[schema]) - if(AddonCore[schema].Load) then - AddonCore[schema]:Load() + self:NewDatabase(CoreObject[schema]) + if(CoreObject[schema].Load) then + CoreObject[schema]:Load() end - AddonCore[schema].initialized = true + CoreObject[schema].initialized = true end end end @@ -856,7 +814,7 @@ function lib:RunCallbacks() end function lib:Update(schema, dataOnly) - local obj = AddonCore[schema] + local obj = CoreObject[schema] if obj and obj.ReLoad and not dataOnly then obj:ReLoad() end @@ -864,7 +822,7 @@ end function lib:UpdateAll() for _,schema in pairs(Modules) do - local obj = AddonCore[schema] + local obj = CoreObject[schema] if obj and obj.ReLoad then obj:ReLoad() end @@ -876,9 +834,9 @@ function lib:NewPrototype(name) local schema = GetAddOnMetadata(name, SchemaFromMeta) local obj = { - ___addonName = name, - ___version = version, - ___schema = schema + NameID = name, + Version = version, + Schema = schema } local mt = {} @@ -891,7 +849,7 @@ function lib:NewPrototype(name) obj.db = {["enable"] = false} - AddonCore[schema] = obj + CoreObject[schema] = obj return obj end @@ -905,8 +863,7 @@ end local function NewLoadOnDemand(addonName, schema, header) LoadOnDemand[schema] = addonName; - - AddonCore.Options.args.plugins.args.pluginOptions.args[schema] = { + CoreObject.Options.args.plugins.args.pluginOptions.args[schema] = { type = "group", name = header, childGroups = "tree", @@ -923,18 +880,13 @@ local function NewLoadOnDemand(addonName, schema, header) return nameString end, func = function() - print(addonName) if(not IsAddOnLoaded(addonName)) then - print("Enabling") local loaded, reason = LoadAddOn(addonName) - lib:SetSourceData(schema, "enable", true) - print(loaded) - print(reason) - AddonCore:StaticPopup_Show("RL_CLIENT") + PROFILE_SV.STORED[SOURCE_KEY][schema].enable = true + CoreObject:StaticPopup_Show("RL_CLIENT") else - print("Disabling") - lib:SetSourceData(schema, "enable", false) - AddonCore:StaticPopup_Show("RL_CLIENT") + PROFILE_SV.STORED[SOURCE_KEY][schema].enable = false + CoreObject:StaticPopup_Show("RL_CLIENT") end end, } @@ -959,20 +911,21 @@ end function lib:NewCore(gfile, pfile, cfile) --internals - AddonCore.___addonName = AddonName; - AddonCore.___version = AddonVersion; - AddonCore.___interface = tonumber(InterfaceVersion); - AddonCore.___debugging = false; - AddonCore.___schema = GetAddOnMetadata(AddonName, SchemaFromMeta); - AddonCore.___header = GetAddOnMetadata(AddonName, HeaderFromMeta); + CoreObject.NameID = CoreName; + CoreObject.Version = AddonVersion; + CoreObject.GameVersion = tonumber(InterfaceVersion); + CoreObject.DebugMode = false; + CoreObject.Schema = GetAddOnMetadata(CoreName, SchemaFromMeta); + CoreObject.TitleID = GetAddOnMetadata(CoreName, HeaderFromMeta); + --meta assurance local mt = {}; - local old = getmetatable(AddonCore); + local old = getmetatable(CoreObject); if old then for k, v in pairs(old) do mt[k] = v end end mt.__tostring = rootstring; - setmetatable(AddonCore, mt); + setmetatable(CoreObject, mt); --database GLOBAL_FILENAME = gfile or GLOBAL_FILENAME PROFILE_FILENAME = pfile or PROFILE_FILENAME @@ -984,26 +937,29 @@ function lib:NewCore(gfile, pfile, cfile) self.EventManager.Initialized = true end - AddonCore.db = tablesplice(AddonCore.configs, {}) + CoreObject.db = tablesplice(CoreObject.configs, {}) --set global - _G[AddonName] = AddonCore; - return AddonCore + _G[CoreName] = CoreObject; + return CoreObject end function lib:Initialize() - local coreSchema = AddonCore.___schema + local coreSchema = CoreObject.Schema --GLOBAL SAVED VARIABLES if not _G[GLOBAL_FILENAME] then _G[GLOBAL_FILENAME] = {} end GLOBAL_SV = _G[GLOBAL_FILENAME] + if(GLOBAL_SV.profileKeys) then twipe(GLOBAL_SV.profileKeys) else GLOBAL_SV.profileKeys = {} end + GLOBAL_SV.profiles = GLOBAL_SV.profiles or {} + for k,v in pairs(GLOBAL_SV.profiles) do GLOBAL_SV.profileKeys[k] = k end @@ -1082,10 +1038,10 @@ function lib:Initialize() --construct core dataset local db = setmetatable({}, meta_database) db.data = PROFILE_SV.STORED[SOURCE_KEY] - db.defaults = AddonCore.configs + db.defaults = CoreObject.configs - AddonCore.ResetData = setDefault - AddonCore.db = db + CoreObject.ResetData = setDefault + CoreObject.db = db --check for LOD plugins local addonCount = GetNumAddOns() @@ -1105,7 +1061,7 @@ end function lib:Launch() if LoadOnDemand then for schema,name in pairs(LoadOnDemand) do - local db = AddonCore.db[schema] + local db = CoreObject.db[schema] if(db and (db.enable or db.enable ~= false)) then if(not IsAddOnLoaded(name)) then local loaded, reason = LoadAddOn(name) @@ -1115,7 +1071,30 @@ function lib:Launch() end end - LoadMods() + if ModuleQueue then + for i=1,#ModuleQueue do + local schema = ModuleQueue[i] + local obj = CoreObject[schema] + if obj and not obj.initialized then + obj.initialized = true; + local halt = false + self:NewDatabase(obj) + if(obj.db.incompatible) then + for addon,_ in pairs(obj.db.incompatible) do + if IsAddOnLoaded(addon) then halt = true end + end + end + if obj.Load then + if(not halt) then + obj:Load() + obj.Load = nil + end + end + end + end + + twipe(ModuleQueue) + end if ScriptQueue then for i=1, #ScriptQueue do diff --git a/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/database.lua b/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/database.lua deleted file mode 100644 index a77d5ff..0000000 --- a/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/database.lua +++ /dev/null @@ -1,356 +0,0 @@ ---[[ - /$$$$$$$ /$$ /$$ -| $$__ $$ | $$ | $$ -| $$ \ $$ /$$$$$$ /$$$$$$ /$$$$$$ | $$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ -| $$ | $$|____ $$|_ $$_/ |____ $$| $$__ $$|____ $$ /$$_____/ /$$__ $$ -| $$ | $$ /$$$$$$$ | $$ /$$$$$$$| $$ \ $$ /$$$$$$$| $$$$$$ | $$$$$$$$ -| $$ | $$/$$__ $$ | $$ /$$/$$__ $$| $$ | $$/$$__ $$ \____ $$| $$_____/ -| $$$$$$$/ $$$$$$$ | $$$$/ $$$$$$$| $$$$$$$/ $$$$$$$ /$$$$$$$/| $$$$$$$ -|_______/ \_______/ \___/ \_______/|_______/ \_______/|_______/ \_______/ - - -DataBase is a component used to create and manage SVUI data objects. - -It's main purpose is to keep all methods and logic needed to properly maintain -valid data outside of the core object. ---]] - ---LIB DB STORAGE -lib.ref = {}; -lib.globals = {}; -lib.source = {}; -lib.cache = {}; -lib.defaults = {}; -lib.dataset = {}; - ---LOCAL HELPERS -local function tablecopy(d, s) - if(type(s) ~= "table") then return end - if type(d) == "table" then - for k, v in pairs(s) do - if type(v) == "table" then - if not rawget(d, k) then rawset(d, k, {}) end - tablecopy(d[k], v) - else - if rawget(d, k) == nil then - rawset(d, k, v) - end - end - end - end -end - -local function tablesplice(targetTable, mergeTable) - if type(targetTable) ~= "table" then targetTable = {} end - - if type(mergeTable) == 'table' then - for key,val in pairs(mergeTable) do - if type(val) == "table" then - val = tablesplice(targetTable[key], val) - end - targetTable[key] = val - end - end - return targetTable -end - -local function importdata(s, d) - if type(d) ~= "table" then d = {} end - if type(s) == "table" then - for k,v in pairs(s) do - if type(v) == "table" then - v = importdata(v, d[k]) - end - d[k] = v - end - end - return d -end - -local function removedefaults(db, src, nometa) - if(type(src) ~= "table") then - if(db == src) then db = nil end - return - end - if(not nometa) then - setmetatable(db, nil) - end - for k,v in pairs(src) do - if type(v) == "table" and type(db[k]) == "table" then - removedefaults(db[k], v, nometa) - if next(db[k]) == nil then - db[k] = nil - end - else - if db[k] == v then - db[k] = nil - end - end - end -end - -local function setDefault(t, sub, sub2) - local data = t.db - local sv = rawget(data, "data") - local src = lib.defaults - local savedProfile - if(sub2 and sv and sv[sub]) then - savedProfile = sv[sub][sub2] - elseif(sub and sv) then - savedProfile = sv[sub] - else - savedProfile = sv - end - if(savedProfile) then - for k,v in pairs(savedProfile) do - savedProfile[k] = nil - end - else - sv = {} - end - tablecopy(sv, src) -end - -local meta_database = { - __index = function(t, k) - if(not k or k == "") then return end - local sv = rawget(t, "data") - local dv = lib.defaults - local src = dv and dv[k] - - --print(k .. " - " .. tostring(src)) - - if(sv[k] == nil) then sv[k] = {} end - - if(src) then - tablecopy(sv[k], src) - end - - rawset(t, k, sv[k]) - return rawget(t, k) - end, -} - -function lib:SetDatabaseObject() - local sourceKey = self.ref.key; - - twipe(self.dataset) - - self.dataset = setmetatable({}, meta_database) - self.dataset.data = self.source.STORED[sourceKey] -end - -function lib:Remove(key) - if(self.globals.profiles[key]) then self.globals.profiles[key] = nil end - if(self.globals.profileKeys[key]) then self.globals.profileKeys[key] = nil end - collectgarbage("collect") -end - -function lib:GetProfiles() - return self.globals.profileKeys or {} -end - -function lib:CheckProfiles() - local hasProfile = false - local list = self.globals.profileKeys or {} - for key,_ in pairs(list) do - hasProfile = true - end - return hasProfile -end - -function lib:ImportDatabase(key) - local reference = self.ref.active; - local sourceKey = self.ref.key; - local src = self.globals.profiles[key]; - if(not src) then return end - local import = self.source.STORED[sourceKey] - tablecopy(import, src) - - ReloadUI() -end - -function lib:ExportDatabase(key) - local reference = self.ref.active - local coreAddon = _G[self.ref.addon] - local export = {} - for schema, _ in pairs(reference) do - local obj = coreAddon[schema] - if(obj and obj.db) then - export[schema] = {} - local db = obj.db - local data = rawget(db, "data") - tablecopy(export[schema], data) - end - end - - if(not self.globals.profiles[key]) then self.globals.profiles[key] = {} end - local saved = self.globals.profiles[key] - tablecopy(saved, export) -end - -function lib:WipeDatabase() - local reference = self.ref.active - local coreAddon = _G[self.ref.addon] - for schema, _ in pairs(reference) do - local obj = coreAddon[schema] - if(obj and obj.db) then - local data = obj.db - local sv = rawget(data, "data") - for k,v in pairs(sv) do - sv[k] = nil - end - end - end -end - -function lib:SetSourceKey() - if(self.source.SAFEDATA and self.source.SAFEDATA.dualSpecEnabled) then - self.ref.key = GetSpecialization() or 1 - databaseListener:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") - else - self.ref.key = 1 - end -end - -function lib:UpdateDatabase() - self:SetSourceKey() - local reference = self.ref.active - local coreAddon = _G[self.ref.addon] - for schema, _ in pairs(reference) do - --self:SetDatabaseObject(coreAddon[schema]) - end -end - -function lib:SanitizeDatabase() - local sv = self.dataset - local src = self.defaults - for k,v in pairs(sv) do - if(src[k] ~= nil) then - removedefaults(sv[k], src[k]) - end - end -end - -function lib:ToggleSpecSwap(value) - if(value) then - databaseListener:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") - self:UpdateDatabase() - else - databaseListener:UnregisterEvent("ACTIVE_TALENT_GROUP_CHANGED") - end -end - -function lib:PrepareStorage() - local globalfile = self.ref.globalfile - self.globals = tablesplice(_G[globalfile], self.globals) - self.globals.profileKeys = {} - local gProfiles = self.globals.profiles - for k,v in pairs(gProfiles) do - self.globals.profileKeys[k] = k - end - - local cachefile = self.ref.cachefile - SVUI_Cache = tablesplice(_G[cachefile], SVUI_Cache) - - local sourcesfile = self.ref.sourcesfile - --_G[sourcesfile] = {} - if not _G[sourcesfile] then _G[sourcesfile] = {} end - - self.source = tablesplice(_G[sourcesfile], self.source) - - for k,v in pairs(self.source) do - if(k ~= "STORED" and k ~= "SAFEDATA") then - self.source[k] = nil - end - end - - self.source.SAFEDATA = self.source.SAFEDATA or {dualSpecEnabled = false} - - local coreSchema = self.ref.schema - - self.source.STORED = self.source.STORED or {} - - self.source.STORED[1] = self.source.STORED[1] or {} - self.source.STORED[1][coreSchema] = self.source.STORED[1][coreSchema] or {} - - for k,v in pairs(self.source.STORED[1]) do - if(k == "STORED" or k == "SAFEDATA" or k == "LAYOUT") then - self.source.STORED[1][k] = nil - end - end - - self.source.STORED[2] = self.source.STORED[2] or {} - self.source.STORED[2][coreSchema] = self.source.STORED[2][coreSchema] or {} - - self.source.STORED[3] = self.source.STORED[3] or {} - self.source.STORED[3][coreSchema] = self.source.STORED[3][coreSchema] or {} - - if playerClass == "DRUID" then - self.source.STORED[4] = self.source.STORED[4] or {} - self.source.STORED[4][coreSchema] = self.source.STORED[4][coreSchema] or {} - elseif self.source.STORED[4] then - self.source.STORED[4] = nil - end -end - -function lib:DefineCore(addon, gfile, pfile, cfile) - local coreAddon = _G[addon]; - local schema = coreAddon.___schema; - - self.ref = { - active = {}, - addon = addon, - schema = schema, - key = 1, - globalfile = gfile, - sourcesfile = pfile, - cachefile = cfile - } - - if(not databaseListener.Initialized) then - databaseListener:RegisterEvent("PLAYER_LOGOUT") - databaseListener:SetScript("OnEvent", DataBase_OnEvent) - databaseListener.Initialized = true - end -end - -function lib:Initialize() - local sourceKey = self.ref.key; - - self:SetSourceKey() - self:PrepareStorage() - - twipe(self.dataset) - - self.dataset = setmetatable({}, meta_database) - self.dataset.data = self.source.STORED[sourceKey] -end - -function lib:NewDatabase(obj) - local schema = obj.___schema - local sourceKey = self.ref.key - self.ref.active[schema] = true - self.defaults[schema] = self.defaults[schema] or {} - - if obj.db then - tablecopy(self.defaults[schema], obj.db) - twipe(obj.db) - end - - if(not self.source.STORED[sourceKey][schema]) then - self.source.STORED[sourceKey][schema] = {} - tablecopy(self.source.STORED[sourceKey][schema], self.defaults[schema]) - end - - obj.db = self.dataset[schema] - obj.ResetData = setDefault -end - -function lib:CheckData(schema, key) - local sourceKey = self.ref.key - local file = self.source.STORED[sourceKey][schema] - print("______" .. schema .. ".db[" .. key .. "]_____") - print(file[key]) - print("______SAVED_____") -end \ No newline at end of file diff --git a/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/librarian.lua b/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/librarian.lua deleted file mode 100644 index 32b4f42..0000000 --- a/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/librarian.lua +++ /dev/null @@ -1,61 +0,0 @@ ---[[ - /$$ /$$ /$$ /$$ -| $$ |__/| $$ |__/ -| $$ /$$| $$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$$$$$ /$$$$$$$ -| $$ | $$| $$__ $$ /$$__ $$|____ $$ /$$__ $$| $$ |____ $$| $$__ $$ -| $$ | $$| $$ \ $$| $$ \__/ /$$$$$$$| $$ \__/| $$ /$$$$$$$| $$ \ $$ -| $$ | $$| $$ | $$| $$ /$$__ $$| $$ | $$ /$$__ $$| $$ | $$ -| $$$$$$$$| $$| $$$$$$$/| $$ | $$$$$$$| $$ | $$| $$$$$$$| $$ | $$ -|________/|__/|_______/ |__/ \_______/|__/ |__/ \_______/|__/ |__/ - -Librarian is a clone of LibStub, meant for use only in SVUI Libraries. - -It's main purpose is to keep all SVUI libraries away from the commonly used -LibStub tables. This helps to keep custom code clean and isolated. - -Be aware that the meta '__call' points towards a 'Proxy' method -instead of the 'Get' method. This is simply due to the higher demand of -Proxy calls over lib loading. - -Librarian also ignores versioning since SVUI code will always be current -within itself. ---]] - -local _G = _G; -local type = _G.type; -local tostring = _G.tostring; -local error = _G.error; -local setmetatable = _G.setmetatable; - -local Librarian = _G["Librarian"] - -if not Librarian then - Librarian = Librarian or {libs = {}} - _G["Librarian"] = Librarian - - function LibStub:NewLibrary(libName) - assert(type(libName) == "string", "Bad argument #2 to `NewLibrary' (string expected)") - self.libs[libName] = self.libs[libName] or {} - return self.libs[libName] - end - - function LibStub(libName, silent) - if not self.libs[libName] and not silent then - error(("Cannot find a library instance of %q."):format(tostring(libName)), 2) - end - return self.libs[libName] - end - - function Librarian:Proxy(libName, ...) - local thisLib = self.libs[libName] - if(not thisLib) then - error(("Cannot find a library instance of %q."):format(tostring(libName)), 2) - elseif(thisLib and not thisLib.Proxy) then - error(("The library '%q' does not have a 'Proxy' method."):format(tostring(libName)), 2) - end - - return thisLib:Proxy(...) - end - - setmetatable(Librarian, { __call = Librarian.Proxy }) -end \ No newline at end of file diff --git a/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/linguist.lua b/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/linguist.lua deleted file mode 100644 index 06a13da..0000000 --- a/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/linguist.lua +++ /dev/null @@ -1,74 +0,0 @@ ---[[ - /$$ /$$ /$$ /$$ -| $$ |__/ |__/ | $$ -| $$ /$$ /$$$$$$$ /$$$$$$ /$$ /$$ /$$ /$$$$$$$/$$$$$$ -| $$ | $$| $$__ $$ /$$__ $$| $$ | $$| $$ /$$_____/_ $$_/ -| $$ | $$| $$ \ $$| $$ \ $$| $$ | $$| $$| $$$$$$ | $$ -| $$ | $$| $$ | $$| $$ | $$| $$ | $$| $$ \____ $$ | $$ /$$ -| $$$$$$$$| $$| $$ | $$| $$$$$$$| $$$$$$/| $$ /$$$$$$$/ | $$$$/ -|________/|__/|__/ |__/ \____ $$ \______/ |__/|_______/ \___/ - /$$ \ $$ - | $$$$$$/ - \______/ - -Linguist is a simple localization component. Seriously, thats it! ---]] -enforce(LibStub, "LibSuperVillain-1.0 requires LibStub") - -local _G = _G; -local rawset = _G.rawset; -local rawget = _G.rawget; -local getmetatable = _G.getmetatable; -local setmetatable = _G.setmetatable; - -local lib = LibStub("LibSuperVillain-1.0", 1) - -if not lib then return end - -local rootstring = function(self) return self.___addonName end - -local failsafe = function() enforce(false) end - -local metaread = { - __index = function(self, key) - rawset(self, key, key) - return key - end -} - -local activeLocale - -local defaultwrite = setmetatable({}, { - __newindex = function(self, key, value) - if not rawget(activeLocale, key) then - rawset(activeLocale, key, value == true and key or value) - end - end, - __index = failsafe -}) - -local metawrite = setmetatable({}, { - __newindex = function(self, key, value) - rawset(activeLocale, key, value == true and key or value) - end, - __index = failsafe -}) - -lib.Localization = setmetatable({}, metaread); - -function lib:Lang(locale, isDefault) - if(not locale) then - return self.Localization - else - local gameLocale = GetLocale() - if gameLocale == "enGB" then gameLocale = "enUS" end - - activeLocale = self.Localization - - if isDefault then - return defaultwrite - elseif(locale == GAME_LOCALE or locale == gameLocale) then - return metawrite - end - end -end \ No newline at end of file diff --git a/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/registry.lua b/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/registry.lua deleted file mode 100644 index 3ea379c..0000000 --- a/Interface/AddOns/SVUI/libs/LibSuperVillain-1.0/src/registry.lua +++ /dev/null @@ -1,527 +0,0 @@ ---[[ - /$$$$$$$ /$$ /$$ -| $$__ $$ |__/ | $$ -| $$ \ $$ /$$$$$$ /$$$$$$ /$$ /$$$$$$$/$$$$$$ /$$$$$$ /$$ /$$ -| $$$$$$$/ /$$__ $$ /$$__ $$| $$ /$$_____/_ $$_/ /$$__ $$| $$ | $$ -| $$__ $$| $$$$$$$$| $$ \ $$| $$| $$$$$$ | $$ | $$ \__/| $$ | $$ -| $$ \ $$| $$_____/| $$ | $$| $$ \____ $$ | $$ /$$| $$ | $$ | $$ -| $$ | $$| $$$$$$$| $$$$$$$| $$ /$$$$$$$/ | $$$$/| $$ | $$$$$$$ -|__/ |__/ \_______/ \____ $$|__/|_______/ \___/ |__/ \____ $$ - /$$ \ $$ /$$ | $$ - | $$$$$$/ | $$$$$$/ - \______/ \______/ - -LibSystemRegistry is a library used to manage packages and scripts embedded -into the SVUI core addon. - -It's main purpose is to keep all methods and logic needed to properly keep -core add-ins functioning outside of the core object. ---]] - ---REGISTRY LOCAL STORAGE -local PluginString = "" -local PluginList, Modules, LoadOnDemand, Callbacks, ModuleQueue, ScriptQueue = {},{},{},{},{},{}; - ---REGISTRY LOCAL HELPERS -local changeDBVar = function(self, value, key, sub1, sub2, sub3) - if((sub1 and sub2 and sub3) and (self.db[sub1] and self.db[sub1][sub2] and self.db[sub1][sub2][sub3])) then - self.db[sub1][sub2][sub3][key] = value - elseif((sub1 and sub2) and (self.db[sub1] and self.db[sub1][sub2])) then - self.db[sub1][sub2][key] = value - elseif(sub1 and self.db[sub1]) then - self.db[sub1][key] = value - else - self.db[key] = value - end - - if(self.UpdateLocals) then - self:UpdateLocals() - end -end - -local innerOnEvent = function(self, event, ...) - local obj = self.module - if self[event] and type(self[event]) == "function" then - self[event](obj, event, ...) - end -end - -local registerEvent = function(self, eventname, eventfunc) - if not self.___eventframe then - self.___eventframe = CreateFrame("Frame", nil) - self.___eventframe.module = self - self.___eventframe:SetScript("OnEvent", innerOnEvent) - end - - if(not self.___eventframe[eventname]) then - local fn = eventfunc - if type(eventfunc) == "string" then - fn = self[eventfunc] - elseif(not fn and self[eventname]) then - fn = self[eventname] - end - self.___eventframe[eventname] = fn - end - - self.___eventframe:RegisterEvent(eventname) -end - -local unregisterEvent = function(self, event, ...) - if(self.___eventframe) then - self.___eventframe:UnregisterEvent(event) - end -end - -local innerOnUpdate = function(self, elapsed) - if self.elapsed and self.elapsed > (self.throttle) then - local obj = self.module - local callbacks = self.callbacks - - for name, fn in pairs(callbacks) do - local _, error = pcall(fn, obj) - if(error and AddonCore.Debugging) then - print(error) - end - end - - self.elapsed = 0 - else - self.elapsed = (self.elapsed or 0) + elapsed - end -end - -local registerUpdate = function(self, updatefunc, throttle) - if not self.___updateframe then - self.___updateframe = CreateFrame("Frame", nil); - self.___updateframe.module = self; - self.___updateframe.callbacks = {}; - self.___updateframe.elapsed = 0; - self.___updateframe.throttle = throttle or 0.2; - end - - if(updatefunc and type(updatefunc) == "string" and self[updatefunc]) then - self.___updateframe.callbacks[updatefunc] = self[updatefunc] - end - - self.___updateframe:SetScript("OnUpdate", innerOnUpdate) -end - -local unregisterUpdate = function(self, updatefunc) - if(updatefunc and type(updatefunc) == "string" and self.___updateframe.callbacks[updatefunc]) then - self.___updateframe.callbacks[updatefunc] = nil - if(#self.___updateframe.callbacks == 0) then - self.___updateframe:SetScript("OnUpdate", nil) - end - else - self.___updateframe:SetScript("OnUpdate", nil) - end -end - -local add_OptionsIndex = function(self, index, data) - local addonName = self.___addonName - local schema = self.___schema - local header = GetAddOnMetadata(addonName, HeaderFromMeta) - - AddonCore.Options.args.plugins.args.pluginOptions.args[schema].args[index] = data -end - -local function SetPluginString(addonName) - local author = GetAddOnMetadata(addonName, "Author") or "Unknown" - local name = GetAddOnMetadata(addonName, "Title") or addonName - local version = GetAddOnMetadata(addonName, "Version") or "???" - return INFO_FORMAT:format(name, version, author) -end - -local function SetInternalModule(obj, schema) - local addonmeta = {} - local oldmeta = getmetatable(obj) - if oldmeta then - for k, v in pairs(oldmeta) do addonmeta[k] = v end - end - addonmeta.__tostring = rootstring - setmetatable( obj, addonmeta ) - - local addonName = ("SVUI [%s]"):format(schema) - - obj.___addonName = addonName - obj.___schema = schema - obj.___dbDebug = false - - obj.initialized = false - obj.CombatLocked = false - obj.ChangeDBVar = changeDBVar - obj.RegisterEvent = registerEvent - obj.UnregisterEvent = unregisterEvent - obj.RegisterUpdate = registerUpdate - obj.UnregisterUpdate = unregisterUpdate - - return obj -end - -local function SetExternalModule(obj, schema, addonName, header, lod) - local addonmeta = {} - local oldmeta = getmetatable(obj) - if oldmeta then - for k, v in pairs(oldmeta) do addonmeta[k] = v end - end - addonmeta.__tostring = rootstring - setmetatable( obj, addonmeta ) - - obj.___addonName = addonName - obj.___schema = schema - obj.___header = header - obj.___lod = lod - - obj.initialized = false - obj.CombatLocked = false - obj.ChangeDBVar = changeDBVar - obj.RegisterEvent = registerEvent - obj.UnregisterEvent = unregisterEvent - obj.RegisterUpdate = registerUpdate - obj.UnregisterUpdate = unregisterUpdate - obj.AddOption = add_OptionsIndex - - if(lod) then - -- print("PLUGIN: " .. addonName) - AddonCore.Options.args.plugins.args.pluginOptions.args[schema] = { - type = "group", - name = header, - childGroups = "tree", - args = { - enable = { - order = 1, - type = "execute", - width = "full", - name = function() - local nameString = "Disable" - if(not IsAddOnLoaded(addonName)) then - nameString = "Enable" - end - return nameString - end, - func = function() - if(not IsAddOnLoaded(addonName)) then - local loaded, reason = LoadAddOn(addonName) - obj:ChangeDBVar(true, "enable") - else - obj:ChangeDBVar(false, "enable") - AddonCore:StaticPopup_Show("RL_CLIENT") - end - end, - } - } - } - else - AddonCore.Options.args.plugins.args.pluginOptions.args[schema] = { - type = "group", - name = header, - childGroups = "tree", - args = { - enable = { - order = 1, - type = "toggle", - name = "Enable", - get = function() return obj.db.enable end, - set = function(key, value) obj:ChangeDBVar(value, "enable"); AddonCore:StaticPopup_Show("RL_CLIENT") end, - } - } - } - end - - return obj -end - - ---REGISTRY PUBLIC METHODS -function lib:NewCallback(fn) - if(fn and type(fn) == "function") then - Callbacks[#Callbacks+1] = fn - end -end - -function lib:NewScript(fn) - if(fn and type(fn) == "function") then - ScriptQueue[#ScriptQueue+1] = fn - end -end - -function lib:NewPackage(obj, schema, defaults) - if(AddonCore[schema]) then return end - - ModuleQueue[#ModuleQueue+1] = schema - Modules[#Modules+1] = schema - - AddonCore[schema] = SetInternalModule(obj, schema) - - if(AddonCore.AddonLaunched and not AddonCore[schema].initialized) then - --print("NewPackage - " .. schema .. ": New Database") - LDB:NewDatabase(AddonCore[schema]) - if(AddonCore[schema].Load) then - AddonCore[schema]:Load() - end - AddonCore[schema].initialized = true - end -end - -function lib:NewPlugin(obj) - local coreName = AddonCore.___addonName - local addonName = obj.___addonName - - if(addonName and addonName ~= coreName) then - local header = GetAddOnMetadata(addonName, HeaderFromMeta) - local schema = GetAddOnMetadata(addonName, SchemaFromMeta) - local lod = IsAddOnLoadOnDemand(addonName) - if(not schema) then return end - - ModuleQueue[#ModuleQueue+1] = schema - Modules[#Modules+1] = schema - - local infoString = SetPluginString(addonName) - local oldString = PluginString - - PluginList[addonName] = infoString - PluginString = ("%s%s\n"):format(oldString, infoString) - - AddonCore[schema] = SetExternalModule(obj, schema, addonName, header, lod) - - if(AddonCore.AddonLaunched and not AddonCore[schema].initialized) then - --print("NewPlugin - " .. schema .. ": New Database") - LDB:NewDatabase(AddonCore[schema]) - if(AddonCore[schema].Load) then - AddonCore[schema]:Load() - end - AddonCore[schema].initialized = true - end - end -end - -function lib:NewAddon(addonName, schema, header) - LoadOnDemand[addonName] = schema; - - AddonCore.Options.args.plugins.args.pluginOptions.args[schema] = { - type = "group", - name = header, - childGroups = "tree", - args = { - enable = { - order = 1, - type = "execute", - width = "full", - name = function() - local nameString = "Disable" - if(not IsAddOnLoaded(addonName)) then - nameString = "Enable" - end - return nameString - end, - func = function() - if(not IsAddOnLoaded(addonName)) then - local loaded, reason = LoadAddOn(addonName) - AddonCore[schema].db.enable = true - self:LoadPackages() - else - AddonCore[schema].db.enable = false - AddonCore:StaticPopup_Show("RL_CLIENT") - end - end, - } - } - } -end - -function lib:RunCallbacks() - for i=1, #Callbacks do - local fn = Callbacks[i] - if(fn and type(fn) == "function") then - fn() - end - end -end - -function lib:Update(schema, dataOnly) - local obj = AddonCore[schema] - if obj and obj.ReLoad and not dataOnly then - obj:ReLoad() - end -end - -function lib:UpdateAll() - for _,schema in pairs(Modules) do - local obj = AddonCore[schema] - if obj and obj.ReLoad then - obj:ReLoad() - end - end -end - -function lib:Launch() - if LoadOnDemand then - for name,schema in pairs(LoadOnDemand) do - local obj = AddonCore[schema] - if(obj and obj.db and (obj.db.enable or obj.db.enable ~= false)) then - if(not IsAddOnLoaded(name)) then - local loaded, reason = LoadAddOn(name) - end - EnableAddOn(name) - end - end - end - - if ModuleQueue then - for i=1,#ModuleQueue do - local schema = ModuleQueue[i] - local obj = AddonCore[schema] - if obj and not obj.initialized then - obj.initialized = true; - local halt = false - --print("ModuleLoad - " .. schema .. ": New Database") - LDB:NewDatabase(obj) - if(obj.db.incompatible) then - for addon,_ in pairs(obj.db.incompatible) do - if IsAddOnLoaded(addon) then halt = true end - end - end - if obj.Load then - if(not halt) then - obj:Load() - obj.Load = nil - --print(schema) - end - end - end - end - - twipe(ModuleQueue) - end - - if ScriptQueue then - for i=1, #ScriptQueue do - local fn = ScriptQueue[i] - if(fn and type(fn) == "function") then - fn() - end - end - - ScriptQueue = nil - end -end - -function lib:NewPrototype(name) - local version = GetAddOnMetadata(name, "Version") - local schema = GetAddOnMetadata(name, SchemaFromMeta) - - local obj = { - ___addonName = name, - ___version = version, - ___schema = schema, - db = {["enable"] = false} - } - - local mt = {} - local old = getmetatable(obj) - if old then - for k, v in pairs(old) do mt[k] = v end - end - mt.__tostring = rootstring - setmetatable(obj, mt) - - AddonCore[schema] = obj - - return obj -end - -function lib:GetPlugins(tableList) - if(tableList and tableList ~= false) then - return PluginList - end - return PluginString -end - -function lib:Initialize() - --initialize database - LDB:Initialize() - - --set core storage - LDB:NewDatabase(AddonCore) - - local addonCount = GetNumAddOns() - for i = 1, addonCount do - local addonName, _, _, _, _, reason = GetAddOnInfo(i) - local lod = IsAddOnLoadOnDemand(i) - local header = GetAddOnMetadata(i, HeaderFromMeta) - local schema = GetAddOnMetadata(i, SchemaFromMeta) - - if(lod and schema) then - self:NewAddon(addonName, schema, header) - end - end -end - ---[[ CONSTRUCTORS ]]-- - -local Core_DeadFunction = function() return end - -local Core_StaticPopup_Show = function(self, arg) - if arg == "ADDON_ACTION_FORBIDDEN" then - StaticPopup_Hide(arg) - end -end - -local function _sendmessage(msg, prefix) - if(type(msg) == "table") then - msg = tostring(msg) - end - - if(not msg) then return end - - if(prefix) then - local outbound = ("%s %s"):format(prefix, msg); - print(outbound) - else - print(msg) - end -end - -local Core_Debugger = function(self, msg) - if(not self.___debugging) then return end - local outbound = (debugPattern):format(self.___addonName, "DEBUG") - _sendmessage(msg, outbound) -end - -local Core_AddonMessage = function(self, msg) - local outbound = (messagePattern):format(self.___addonName) - _sendmessage(msg, outbound) -end - -function lib:NewCore(gfile, pfile, cfile) - local obj = {}; - --internals - AddonCore.___addonName = AddonName; - AddonCore.___version = AddonVersion; - AddonCore.___interface = tonumber(uiVersion); - AddonCore.___debugging = false; - AddonCore.___schema = "SVSystem"; - --functions - AddonCore.fubar = Core_DeadFunction; - AddonCore.AddonMessage = Core_AddonMessage; - AddonCore.Debugger = Core_Debugger; - AddonCore.StaticPopup_Show = Core_StaticPopup_Show; - --storage - AddonCore.db = {}; - - local mt = {}; - local old = getmetatable(AddonCore); - if old then - for k, v in pairs(old) do mt[k] = v end - end - mt.__tostring = rootstring; - setmetatable(AddonCore, mt); - - --set global - _G[AddonName] = AddonCore; - - --database settings - LDB:DefineCore(AddonName, gfile, pfile, cfile) - - return AddonCore -end \ No newline at end of file diff --git a/Interface/AddOns/SVUI/libs/libs.xml b/Interface/AddOns/SVUI/libs/libs.xml index 0715887..2939c19 100644 --- a/Interface/AddOns/SVUI/libs/libs.xml +++ b/Interface/AddOns/SVUI/libs/libs.xml @@ -4,6 +4,6 @@