From e024597cff9600da5be882bcb8f45f6ff58fb531 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Mon, 22 Aug 2016 20:57:51 +0200 Subject: [PATCH] big refactoring --- aux-addon.toc | 4 +- control.lua | 2 +- core.lua | 121 ++++++++++++++++++++++++++++ {components => core}/cache.lua | 0 {components => core}/disenchant.lua | 0 {components => core}/history.lua | 0 {components => core}/post.lua | 0 {components => core}/scan.lua | 0 {components => core}/slash.lua | 0 {components => core}/stack.lua | 0 {components => core}/tooltip.lua | 0 frames.lua | 85 +++++++++++++++++++ {tables => gui}/auction_listing.lua | 0 gui.lua => gui/core.lua | 0 {tables => gui}/item_listing.lua | 0 {tables => gui}/listing.lua | 0 init.lua | 5 +- tabs/search/core.lua | 3 +- 18 files changed, 216 insertions(+), 4 deletions(-) rename {components => core}/cache.lua (100%) rename {components => core}/disenchant.lua (100%) rename {components => core}/history.lua (100%) rename {components => core}/post.lua (100%) rename {components => core}/scan.lua (100%) rename {components => core}/slash.lua (100%) rename {components => core}/stack.lua (100%) rename {components => core}/tooltip.lua (100%) create mode 100644 frames.lua rename {tables => gui}/auction_listing.lua (100%) rename gui.lua => gui/core.lua (100%) rename {tables => gui}/item_listing.lua (100%) rename {tables => gui}/listing.lua (100%) diff --git a/aux-addon.toc b/aux-addon.toc index 650acac..9452664 100644 --- a/aux-addon.toc +++ b/aux-addon.toc @@ -6,9 +6,11 @@ module.lua init.lua core.lua -util\core.lua +util.lua control.lua gui.lua +frames.lua + util\completion.lua util\persistence.lua diff --git a/control.lua b/control.lua index fdfa62f..4d495d9 100644 --- a/control.lua +++ b/control.lua @@ -1,4 +1,4 @@ -module 'control' +module 'core' event_frame = CreateFrame 'Frame' listeners = {} diff --git a/core.lua b/core.lua index 109c19c..965160e 100644 --- a/core.lua +++ b/core.lua @@ -1,5 +1,126 @@ module 'core' +function INIT() + import :_ 'core' :_ 'util' + function LOAD() + import :_ 'core' :_ 'control' :_ 'util' + end +end + +module 'core' +public.version = '5.0.0' + +do + local table_pool, temporary = {}, {} + + CreateFrame'Frame':SetScript('OnUpdate', function() + for t in temporary do + recycle(t) + log(getn(table_pool)) + end + wipe(temporary) + end) + + function public.wipe(t) -- like with a cloth or something + for k in t do + t[k] = nil + end + table.setn(t, 0) + end + + function public.recycle(t) + temporary[t] = nil + wipe(t) + tinsert(table_pool, t) + end + + function public.accessor.t() return + tremove(table_pool) or {} + end + + function public.accessor.tt() + local t = tremove(table_pool) or {} + temporary[t] = true + return t + end + + do + local mt = { + __call=function(self, arg) return self[1](arg) end, + __sub=function(self, arg) return self[1](arg) end, + } + function public.modifier(f) + local self = t + self[1] = f + return setmetatable(self, mt) + end + end + + public.tmp = modifier(function(t) + temporary[t] = true + return t + end) + + do + local mt = { + __call=function(self, arg1, arg2) + tinsert(self, arg2 or arg1) + return self + end, + __index=function(self, key) + tinsert(self, key) + return self + end, + } + function public.accessor.from() + return setmetatable(tt, mt) + end + end + + do + local mt = {__call = function(self, key) return self[key] end} + public.set = modifier(function(table) + local self = t + for _, v in table do self[v] = true end + recycle(table) + return setmetatable(self, mt) + end) + end + + public.array = modifier(function(table) + local self = t + for _, v in table do tinsert(self, v) end + recycle(table) + return self + end) + + -- TODO map +end + +local event_frame = CreateFrame 'Frame' +for event in tmp-set-from . ADDON_LOADED . VARIABLES_LOADED . PLAYER_LOGIN . AUCTION_HOUSE_SHOW . AUCTION_HOUSE_CLOSED . AUCTION_BIDDER_LIST_UPDATE . AUCTION_OWNED_LIST_UPDATE do + event_frame:RegisterEvent(event) +end + +ADDON_LOADED = t +do + local variables_loaded_hooks, player_login_hooks = t, t + function public.mutator.LOAD(f) tinsert(variables_loaded_hooks, f) end + function public.mutator.LOAD2(f) tinsert(player_login_hooks, f) end + event_frame:SetScript('OnEvent', function() + if event == 'ADDON_LOADED' then + if ADDON_LOADED[arg1] then ADDON_LOADED[arg1]() end + elseif event == 'VARIABLES_LOADED' then + for _, f in variables_loaded_hooks do f() end + elseif event == 'PLAYER_LOGIN' then + for _, f in player_login_hooks do f() end + log('v'..version..' loaded.') + else + _m[event]() + end + end) +end + public.bids_loaded = false public.current_owner_page = nil diff --git a/components/cache.lua b/core/cache.lua similarity index 100% rename from components/cache.lua rename to core/cache.lua diff --git a/components/disenchant.lua b/core/disenchant.lua similarity index 100% rename from components/disenchant.lua rename to core/disenchant.lua diff --git a/components/history.lua b/core/history.lua similarity index 100% rename from components/history.lua rename to core/history.lua diff --git a/components/post.lua b/core/post.lua similarity index 100% rename from components/post.lua rename to core/post.lua diff --git a/components/scan.lua b/core/scan.lua similarity index 100% rename from components/scan.lua rename to core/scan.lua diff --git a/components/slash.lua b/core/slash.lua similarity index 100% rename from components/slash.lua rename to core/slash.lua diff --git a/components/stack.lua b/core/stack.lua similarity index 100% rename from components/stack.lua rename to core/stack.lua diff --git a/components/tooltip.lua b/core/tooltip.lua similarity index 100% rename from components/tooltip.lua rename to core/tooltip.lua diff --git a/frames.lua b/frames.lua new file mode 100644 index 0000000..5842548 --- /dev/null +++ b/frames.lua @@ -0,0 +1,85 @@ +module 'core' + +public.bids_loaded = false +public.current_owner_page = nil + +function LOAD() + import :_ 'util' 'gui' + do + local frame = CreateFrame('Frame', gui.name, UIParent) + tinsert(UISpecialFrames, 'aux_frame1') + gui.set_window_style(frame) + gui.set_size(frame, 768, 447) + frame:SetPoint('LEFT', 100, 0) + frame:SetToplevel(true) + frame:SetMovable(true) + frame:EnableMouse(true) + frame:SetClampedToScreen(true) + frame:RegisterForDrag 'LeftButton' + frame:SetScript('OnDragStart', function() this:StartMoving() end) + frame:SetScript('OnDragStop', function() this:StopMovingOrSizing() end) + frame:SetScript('OnShow', function() PlaySound 'AuctionWindowOpen' end) + frame:SetScript('OnHide', function() PlaySound 'AuctionWindowClose' CloseAuctionHouse() end) + frame.content = CreateFrame('Frame', nil, frame) + frame.content:SetPoint('TOPLEFT', 4, -80) + frame.content:SetPoint('BOTTOMRIGHT', -4, 35) + frame:Hide() + public.frame = frame + end + do + local tabs = gui.tabs(frame, 'DOWN') + tabs._on_select = on_tab_click + for _, tab in _m.tabs do tabs:create_tab(tab.name) end + function public.set_tab(id) tabs:select(id) end + end + do + local btn = gui.button(frame, 16) + btn:SetPoint('BOTTOMRIGHT', -6, 6) + gui.set_size(btn, 65, 24) + btn:SetText 'Close' + btn:SetScript('OnClick', L(frame.Hide, frame)) + public.close_button = btn + end + do + local btn = gui.button(frame, 16) + btn:SetPoint('RIGHT', close_button, 'LEFT' , -5, 0) + gui.set_size(btn, 65, 24) + btn:SetText 'Default UI' + btn:SetScript('OnClick',function() + if AuctionFrame:IsVisible() then HideUIPanel(AuctionFrame) else ShowUIPanel(AuctionFrame) end + end) + end +end + +function public.log(...) + local msg = '[aux]' + for i=1,arg.n do msg = msg..' '..tostring(arg[i]) end + DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE..msg) +end + +tabs = {} +function public.tab(index, name) + local module_env = getfenv(2) + local tab = {name=name, env=module_env} + function module_env.public.accessor.ACTIVE() return tab == active_tab end + for handler in tmp-set-from . OPEN . CLOSE . CLICK_LINK . USE_ITEM do module_env.mutable[handler] = nil end + tabs[index] = tab +end +do + local active_tab_index + function accessor.active_tab() return tabs[active_tab_index] end + function on_tab_click(index) + call(active_tab_index and active_tab.env.CLOSE) + active_tab_index = index + call(active_tab_index and active_tab.env.OPEN) + end +end + +public.orig = setmetatable({[_g]={}}, {__index=function(self, key) return self[_g][key] end}) +function public.hook(name, handler, object) + handler = handler or getfenv(2)[name] + object = object or _g + orig[object] = orig[object] or {} + assert(not orig[object][name], '"'..name..'" is already hooked into.') + orig[object][name], object[name] = object[name], handler +end \ No newline at end of file diff --git a/tables/auction_listing.lua b/gui/auction_listing.lua similarity index 100% rename from tables/auction_listing.lua rename to gui/auction_listing.lua diff --git a/gui.lua b/gui/core.lua similarity index 100% rename from gui.lua rename to gui/core.lua diff --git a/tables/item_listing.lua b/gui/item_listing.lua similarity index 100% rename from tables/item_listing.lua rename to gui/item_listing.lua diff --git a/tables/listing.lua b/gui/listing.lua similarity index 100% rename from tables/listing.lua rename to gui/listing.lua diff --git a/init.lua b/init.lua index 04fe4b3..96c80b9 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,8 @@ function INIT() - import :_ 'core' :_ 'control' :_ 'util' -- TODO auto import 'core' instead + import :_ 'core' :_ 'util' + function LOAD() + import :_ 'core' :_ 'control' :_ 'util' + end end module 'core' diff --git a/tabs/search/core.lua b/tabs/search/core.lua index 6ca9354..4c477b9 100644 --- a/tabs/search/core.lua +++ b/tabs/search/core.lua @@ -50,7 +50,8 @@ end RESULTS, SAVED, FILTER = 1, 2, 3 -function LOAD2() +function LOAD() + import 'core' create_frames() set_tab(SAVED) update_auto_buy_filter()