savedvariables refactoring

This commit is contained in:
Manuel Simon Hirsig
2017-03-18 15:41:22 +01:00
parent 0bfcc98c8c
commit 427f2b9dfa
9 changed files with 55 additions and 57 deletions
+48 -8
View File
@@ -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 .. '<aux> ' .. 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()
+1 -1
View File
@@ -1,6 +1,6 @@
module 'aux'
local event_frame = CreateFrame('Frame')
local event_frame = CreateFrame'Frame'
local listeners, threads = T, T
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -2
View File
@@ -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
+1 -2
View File
@@ -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
+1 -1
View File
@@ -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)
+1 -2
View File
@@ -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()
-39
View File
@@ -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