diff --git a/aux-addon.lua b/aux-addon.lua index 0f3a6c2..215244d 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -13,9 +13,12 @@ local search_tab = require 'aux.tabs.search' _G.aux_scale = 1 -function M.set_p(v) - inspect(nil, v) -end +_G.aux = { + character = {}, + faction = {}, + realm = {}, + account = {}, +} function M.print(...) DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE .. ' ' .. join(map(arg, tostring), ' ')) @@ -32,7 +35,6 @@ for event in temp-S('ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION event_frame:RegisterEvent(event) end -ADDON_LOADED = {} do local handlers, handlers2 = {}, {} function M.set_LOAD(f) @@ -43,7 +45,13 @@ do end event_frame:SetScript('OnEvent', function() if event == 'ADDON_LOADED' then - (ADDON_LOADED[arg1] or nop)() + if arg1 == 'Blizzard_AuctionUI' then + Blizzard_AuctionUI() + elseif arg1 == 'Blizzard_CraftUI' then + Blizzard_CraftUI() + elseif arg1 == 'Blizzard_TradeSkillUI' then + Blizzard_TradeSkillUI() + end elseif event == 'VARIABLES_LOADED' then for _, f in handlers do f() end elseif event == 'PLAYER_LOGIN' then @@ -55,6 +63,38 @@ do end) end +do + local cache = {} + function LOAD() + cache.account = aux.account + do + local key = format('%s|%s', GetCVar'realmName', UnitName'player') + aux.character[key] = aux.character[key] or {} + cache.character = aux.character[key] + end + do + local key = GetCVar'realmName' + aux.realm[key] = aux.realm[key] or {} + cache.realm = aux.realm[key] + end + end + function LOAD2() + do + local key = format('%s|%s', GetCVar'realmName', UnitFactionGroup'player') + aux.faction[key] = aux.faction[key] or {} + cache.faction = aux.faction[key] + end + end + for scope in temp-S('character', 'faction', 'realm', 'account') do + local scope = scope + M[scope .. '_data'] = function(k, v) + if not cache[scope] then error('Cache not ready', 2) end + cache[scope][k] = cache[scope][k] or v or {} + return cache[scope][k] + end + end +end + tab_info = {} function M.TAB(name) local tab = O('name', name) @@ -198,7 +238,7 @@ do end end -function ADDON_LOADED.Blizzard_AuctionUI() +function Blizzard_AuctionUI() AuctionFrame:UnregisterEvent('AUCTION_HOUSE_SHOW') AuctionFrame:SetScript('OnHide', nil) hook('ShowUIPanel', function(...) @@ -227,7 +267,7 @@ do end end) end - function ADDON_LOADED.Blizzard_CraftUI() + function Blizzard_CraftUI() hook('CraftFrame_SetSelection', function(...) local ret = temp-A(orig.CraftFrame_SetSelection(unpack(arg))) local id = GetCraftSelectionIndex() @@ -257,7 +297,7 @@ do hook_quest_item(_G['CraftReagent' .. i]) end end - function ADDON_LOADED.Blizzard_TradeSkillUI() + function Blizzard_TradeSkillUI() hook('TradeSkillFrame_SetSelection', function(...) local ret = temp-A(orig.TradeSkillFrame_SetSelection(unpack(arg))) local id = GetTradeSkillSelectionIndex() diff --git a/control.lua b/control.lua index ac8cf3b..edb29f5 100644 --- a/control.lua +++ b/control.lua @@ -1,6 +1,6 @@ module 'aux' -local event_frame = CreateFrame('Frame') +local event_frame = CreateFrame'Frame' local listeners, threads = T, T diff --git a/core/cache.lua b/core/cache.lua index b27f08a..596b26d 100644 --- a/core/cache.lua +++ b/core/cache.lua @@ -45,7 +45,7 @@ do return characters[name] and true or false end function LOAD2() - characters = persistence.realm'characters' + characters = realm_data'characters' for k, v in characters do if GetTime() > v + 60 * 60 * 24 * 30 then characters[k] = nil diff --git a/core/history.lua b/core/history.lua index bdc827c..5674fc5 100644 --- a/core/history.lua +++ b/core/history.lua @@ -10,7 +10,7 @@ local history_schema = {'tuple', '#', {next_push='number'}, {daily_min_buyout='n local value_cache = {} function LOAD2() - data = persistence.faction'history' + data = faction_data'history' end do diff --git a/core/slash.lua b/core/slash.lua index 85673af..736f02a 100644 --- a/core/slash.lua +++ b/core/slash.lua @@ -3,10 +3,9 @@ module 'aux.core.slash' include 'aux' local cache = require 'aux.core.cache' -local persistence = require 'aux.util.persistence' function LOAD2() - tooltip_settings = persistence.character'tooltip' + tooltip_settings = character_data'tooltip' end _G.aux_ignore_owner = true diff --git a/core/tooltip.lua b/core/tooltip.lua index 9dc6ed1..6534757 100644 --- a/core/tooltip.lua +++ b/core/tooltip.lua @@ -6,7 +6,6 @@ include 'aux' local info = require 'aux.util.info' local money = require 'aux.util.money' local cache = require 'aux.core.cache' -local persistence = require 'aux.util.persistence' local disenchant = require 'aux.core.disenchant' local history = require 'aux.core.history' local auction_listing = require 'aux.gui.auction_listing' @@ -16,7 +15,7 @@ local UNKNOWN = GRAY_FONT_COLOR_CODE .. '?' .. FONT_COLOR_CODE_CLOSE local game_tooltip_hooks, game_tooltip_money = {}, 0 function LOAD() - settings = persistence.character('tooltip', {value=true}) + settings = character_data('tooltip', {value=true}) do local inside_hook = false for name, f in game_tooltip_hooks do diff --git a/tabs/post/core.lua b/tabs/post/core.lua index 8f5febf..a8400b8 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -27,7 +27,7 @@ function get_default_settings() end function LOAD2() - data = persistence.faction'post' + data = faction_data'post' end function read_settings(item_key) diff --git a/tabs/search/saved.lua b/tabs/search/saved.lua index b695d12..a5b3898 100644 --- a/tabs/search/saved.lua +++ b/tabs/search/saved.lua @@ -2,10 +2,9 @@ module 'aux.tabs.search' local filter_util = require 'aux.util.filter' local gui = require 'aux.gui' -local persistence = require 'aux.util.persistence' function LOAD2() - recent_searches, favorite_searches = persistence.realm'recent_searches', persistence.realm'favorite_searches' + recent_searches, favorite_searches = realm_data'recent_searches', realm_data'favorite_searches' end function update_search_listings() diff --git a/util/persistence.lua b/util/persistence.lua index 57cba05..728cff9 100644 --- a/util/persistence.lua +++ b/util/persistence.lua @@ -3,45 +3,6 @@ module 'aux.util.persistence' include 'T' include 'aux' -_G.aux = { - character = {}, - faction = {}, - realm = {}, - account = {}, -} - -do - local cache = {} - function LOAD() - cache.account = aux.account - do - local key = format('%s|%s', GetCVar'realmName', UnitName'player') - aux.character[key] = aux.character[key] or {} - cache.character = aux.character[key] - end - do - local key = GetCVar'realmName' - aux.realm[key] = aux.realm[key] or {} - cache.realm = aux.realm[key] - end - end - function LOAD2() - do - local key = format('%s|%s', GetCVar'realmName', UnitFactionGroup'player') - aux.faction[key] = aux.faction[key] or {} - cache.faction = aux.faction[key] - end - end - for scope in temp-S('character', 'faction', 'realm', 'account') do - local scope = scope - M[scope] = function(k, v) - if not cache[scope] then error('Cache not ready', 2) end - cache[scope][k] = cache[scope][k] or v or {} - return cache[scope][k] - end - end -end - function M.read(schema, str) if schema == 'string' then return str