From 5f03b95e8f5e47f65787f052d5e6e38c07a7c87a Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Tue, 23 Aug 2016 04:58:46 +0200 Subject: [PATCH] refactoring --- aux-addon.lua | 71 ++++++++----------- control.lua | 8 +-- core/scan.lua | 2 +- core/tooltip.lua | 17 +++-- gui/auction_listing.lua | 4 +- gui/core.lua | 147 ++++++++++++++++++++-------------------- gui/item_listing.lua | 2 +- gui/listing.lua | 2 +- module.lua | 3 +- tabs/auctions/core.lua | 1 - tabs/auctions/frame.lua | 8 +-- tabs/bids/core.lua | 1 - tabs/bids/frame.lua | 8 +-- tabs/post/core.lua | 1 - tabs/post/frame.lua | 14 ++-- tabs/search/core.lua | 1 - tabs/search/frame.lua | 12 ++-- tabs/search/results.lua | 26 +++---- util/color.lua | 2 +- util/core.lua | 51 +++++++------- util/filter.lua | 17 +++-- util/info.lua | 4 +- util/money.lua | 7 +- util/persistence.lua | 11 ++- util/scan.lua | 4 +- util/sort.lua | 10 +-- 26 files changed, 209 insertions(+), 225 deletions(-) diff --git a/aux-addon.lua b/aux-addon.lua index de02d7f..b72f5aa 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -10,7 +10,7 @@ do CreateFrame'Frame':SetScript('OnUpdate', function() for t in temporary do recycle(t) - log(getn(table_pool)) +-- log(getn(table_pool)) end wipe(temporary) end) @@ -33,21 +33,12 @@ do tremove(table_pool) or {} end - function public.accessor.tt() -- TODO or 'tmp'? + function public.accessor.tt() -- TODO or 'tmp'? t (and t -> T)? local t = tremove(table_pool) or {} temporary[t] = true return t end - do - local T = t - local mt = {__unm=function(self) T = t; return setmetatable(self, nil) end} - function public.accessor.T() - wipe(T) - return setmetatable(T, mt) - end - end - function public.modifier(f) local function apply(_, value) return f(value) end return setmetatable(t, { @@ -57,16 +48,16 @@ do end local temp, perm = modifier(function(t) temporary[t] = true; return t end), modifier(function(t) temporary[t] = false; return t end) public.temp() -- TODO or 'auto'? - function accessor() return setmetatable(T, mt) end + function accessor() return setmetatable(tt, mt) end function mutator(value) return temp(value) end public.perm() -- TODO or 'keep'? - function accessor() return setmetatable(T, mt) end + function accessor() return setmetatable(tt, mt) end function mutator(value) return perm(value) end function public.collector_mt(f) return { __unm=function(self) - setmetatable(self, nil) + return setmetatable(self, nil) end, __index=function(self, key) f(self, key) @@ -81,7 +72,7 @@ do do local mt = collector_mt(tinsert) function public.accessor.list() - return setmetatable(T, mt) + return setmetatable(tt, mt) end end do @@ -89,7 +80,7 @@ do rawset(self, value, true) end) function public.accessor.set() - return setmetatable(T, mt) + return setmetatable(tt, mt) end end do @@ -97,12 +88,13 @@ do local mt = collector_mt(function(self, value) if key ~= nil then rawset(self, key, value) + key = nil else key = value end end) - function public.accessor.map() - return setmetatable(T, mt) + function public.accessor.object() + return setmetatable(tt, mt) end end end @@ -131,17 +123,17 @@ do end) end -function public.log(...) +function public.log(...) temp=arg local msg = '[aux]' for i=1,arg.n do msg = msg..' '..tostring(arg[i]) end DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE..msg) - recycle(arg) end -tabs = t -for k, v in map :search_tab 'Search' :post_tab 'Post' :auctions_tab 'Auctions' :bids_tab 'Bids' do - local m, tab = _m, -map :name(k) :title(v) +tab_info = t +for k, v in -object :search_tab 'Search' :post_tab 'Post' :auctions_tab 'Auctions' :bids_tab 'Bids' do + local m, tab = _m, -object :name(v); + log(tab.name); (function() module(k) function mutator.OPEN(f) tab.OPEN = f end @@ -150,12 +142,12 @@ for k, v in map :search_tab 'Search' :post_tab 'Post' :auctions_tab 'Auctions' : function mutator.CLICK_LINK(f) tab.CLICK_LINK = f end function public.accessor.ACTIVE() return tab == m.active_tab end end)() - tinsert(tab, tabs) + tinsert(tab_info, tab) end do local active_tab_index - function accessor.active_tab() return tabs[active_tab_index] end + function accessor.active_tab() return tab_info[active_tab_index] end function on_tab_click(index) call(active_tab_index and active_tab.CLOSE) active_tab_index = index @@ -163,8 +155,8 @@ do end end -function SetItemRef(...) temp(arg) - if arg[3] ~= 'RightButton' or not index(active_tab, 'env', 'CLICK_LINK') or not strfind(arg[1], '^item:%d+') then +function SetItemRef(...) temp=arg + if arg[3] ~= 'RightButton' or not index(active_tab, 'CLICK_LINK') or not strfind(arg[1], '^item:%d+') then return orig.SetItemRef(unpack(arg)) end for item_info in present(info.item(tonumber(select(3, strfind(arg[1], '^item:(%d+)'))))) do @@ -172,17 +164,17 @@ function SetItemRef(...) temp(arg) end end -function UseContainerItem(...) temp(arg) - if modified or not index(active_tab, 'env', 'USE_ITEM') then +function UseContainerItem(...) temp=arg + if modified or not index(active_tab, 'USE_ITEM') then return orig.UseContainerItem(unpack(arg)) end for item_info in present(info.container_item(arg[1], arg[2])) do - return active_tab.env.USE_ITEM(item_info) + return active_tab.USE_ITEM(item_info) end end public.orig = setmetatable({[_g]=t}, {__index=function(self, key) return self[_g][key] end}) -function public.hook() +function public.hook(...) local name, object, handler if arg.n == 3 then name, object, handler = unpack(arg) @@ -248,7 +240,7 @@ end function AUCTION_HOUSE_SHOW() AuctionFrame:Hide() - frame:Show() + aux_frame:Show() set_tab(1) end @@ -259,7 +251,7 @@ function AUCTION_HOUSE_CLOSED() stack.stop() scan.abort() set_tab() - frame:Hide() + aux_frame:Hide() end function AUCTION_BIDDER_LIST_UPDATE() @@ -268,7 +260,7 @@ end do local last_owner_page_requested - function GetOwnerAuctionItems(...) temp(arg) + function GetOwnerAuctionItems(...) temp=arg local page = arg[1] last_owner_page_requested = page return orig.GetOwnerAuctionItems(unpack(arg)) @@ -281,7 +273,7 @@ end function ADDON_LOADED.Blizzard_AuctionUI() AuctionFrame:UnregisterEvent 'AUCTION_HOUSE_SHOW' AuctionFrame:SetScript('OnHide', nil) - hook('ShowUIPanel', function(...) temp(arg) + hook('ShowUIPanel', function(...) temp=arg if arg[1] == AuctionFrame then return AuctionFrame:Show() end return orig.ShowUIPanel(unpack(arg)) end) @@ -296,8 +288,7 @@ do return label end function ADDON_LOADED.Blizzard_CraftUI() - hook('CraftFrame_SetSelection', function(...) - temp(arg) + hook('CraftFrame_SetSelection', function(...) temp=arg local results = {orig.CraftFrame_SetSelection(unpack(arg))} local id = GetCraftSelectionIndex() local reagent_count = GetCraftNumReagents(id) @@ -324,8 +315,7 @@ do end) end function ADDON_LOADED.Blizzard_TradeSkillUI() - hook('TradeSkillFrame_SetSelection', function(...) - temp(arg) + hook('TradeSkillFrame_SetSelection', function(...) temp=arg local results = {orig.TradeSkillFrame_SetSelection(unpack(arg))} local id = GetTradeSkillSelectionIndex() local reagent_count = GetTradeSkillNumReagents(id) @@ -353,8 +343,7 @@ do end end -function AuctionFrameAuctions_OnEvent(...) - temp(arg) +function AuctionFrameAuctions_OnEvent(...) temp=arg if AuctionFrameAuctions:IsVisible() then return orig.AuctionFrameAuctions_OnEvent(unpack(arg)) end diff --git a/control.lua b/control.lua index 524d5a7..09a33e1 100644 --- a/control.lua +++ b/control.lua @@ -61,7 +61,7 @@ end function public.event_listener(event, cb) local listener_id = id - listeners[listener_id] = {event=event, cb=cb, kill=function(...) if arg.n == 0 or arg[1] then kill_listener(listener_id) end end} + listeners[listener_id] = {event=event, cb=cb, kill=function(...) temp=arg if arg.n == 0 or arg[1] then kill_listener(listener_id) end end} event_frame:RegisterEvent(event) return listener_id end @@ -73,13 +73,13 @@ function public.on_next_event(event, callback) end) end -function public.thread(k, ...) +function public.thread(k, ...) temp=arg local thread_id = id threads[thread_id] = {k = L(k, unpack(arg))} return thread_id end -function public.wait(k, ...) +function public.wait(k, ...) temp=arg if type(k) == 'number' then when(function() k = k - 1 return k <= 1 end, unpack(arg)) else @@ -87,7 +87,7 @@ function public.wait(k, ...) end end -function public.when(p, k, ...) +function public.when(p, k, ...) temp=arg if p() then return k(unpack(arg)) else diff --git a/core/scan.lua b/core/scan.lua index 8da2570..4c033c4 100644 --- a/core/scan.lua +++ b/core/scan.lua @@ -45,7 +45,7 @@ end function accessor.query() return state.params.queries[state.query_index] end -function wait_for_callback(...) +function wait_for_callback(...) temp=arg local send_signal, signal_received = signal() local suspended local ret diff --git a/core/tooltip.lua b/core/tooltip.lua index 2bc8e0d..feddf22 100644 --- a/core/tooltip.lua +++ b/core/tooltip.lua @@ -1,5 +1,4 @@ module 'tooltip' ---import 'gui' 'lol' 'kek' _g.aux_tooltip_value = true @@ -10,7 +9,7 @@ game_tooltip_money = nil function LOAD() for name, f in game_tooltip_hooks do local name, f = name, f - _m.hook(name, GameTooltip, function(...) temp(arg) + _m.hook(name, GameTooltip, function(...) temp=arg hooked_setter = true game_tooltip_money = 0 local ret = {orig[GameTooltip][name](unpack(arg))} @@ -20,7 +19,7 @@ function LOAD() end) end local orig = SetItemRef - setglobal('SetItemRef', function(...) + setglobal('SetItemRef', function(...) temp=arg local result = orig(unpack(arg)) local name, _, quality = GetItemInfo(arg[1]) if not IsShiftKeyDown() and not IsControlKeyDown() and name then @@ -31,7 +30,7 @@ function LOAD() return result end) local orig = GameTooltip:GetScript('OnTooltipAddMoney') - GameTooltip:SetScript('OnTooltipAddMoney', function(...) + GameTooltip:SetScript('OnTooltipAddMoney', function(...) temp=arg if hooked_setter then game_tooltip_money = arg1 else @@ -127,7 +126,7 @@ end function game_tooltip_hooks:SetHyperlink(itemstring) local name, _, quality = GetItemInfo(itemstring) if name then - local _, _, _, hex = GetItemQualityColor(quality) + local hex = select(4, GetItemQualityColor(quality)) local link = hex.. '|H'..itemstring..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE extend_tooltip(GameTooltip, link, 1) end @@ -179,7 +178,7 @@ function game_tooltip_hooks:SetInboxItem(index) local id = name and cache.item_id(name) if id then local _, itemstring, quality = GetItemInfo(id) - local _, _, _, hex = GetItemQualityColor(tonumber(quality)) + local hex = select(4, GetItemQualityColor(tonumber(quality))) local link = hex.. '|H'..itemstring..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE extend_tooltip(GameTooltip, link, quantity) end @@ -195,7 +194,7 @@ end function game_tooltip_hooks:SetMerchantItem(slot) local link = GetMerchantItemLink(slot) if link then - local _, _, _, quantity = GetMerchantItemInfo(slot) + local quantity = select(4, GetMerchantItemInfo(slot)) extend_tooltip(GameTooltip, link, quantity) end end @@ -213,8 +212,8 @@ function game_tooltip_hooks:SetCraftItem(skill, slot) end function game_tooltip_hooks:SetCraftSpell(slot) - if x(GetCraftItemLink(slot)) then - extend_tooltip(GameTooltip, __, 1) + for link in present(GetCraftItemLink(slot)) do + extend_tooltip(GameTooltip, link, 1) end end diff --git a/gui/auction_listing.lua b/gui/auction_listing.lua index 72ab54e..d5615a6 100644 --- a/gui/auction_listing.lua +++ b/gui/auction_listing.lua @@ -926,7 +926,7 @@ local methods = { end end, - SetSort = function(self, ...) + SetSort = function(self, ...) temp=arg for k=1,arg.n do for i, sort in self.sorts do if sort.index == abs(arg[k]) then @@ -934,7 +934,7 @@ local methods = { break end end - tinsert(self.sorts, 1, { index = abs(arg[k]), descending = arg[k] < 0 }) + tinsert(self.sorts, 1, {index=abs(arg[k]), descending=arg[k] < 0 }) end self.isSorted = nil diff --git a/gui/core.lua b/gui/core.lua index 2ff73b3..c5964cd 100644 --- a/gui/core.lua +++ b/gui/core.lua @@ -1,5 +1,79 @@ module 'gui' +function LOAD() + do + local blizzard_backdrop, aux_background, aux_border + + aux_border = DropDownList1:CreateTexture() + aux_border:SetTexture(1, 1, 1, .02) + aux_border:SetPoint('TOPLEFT', DropDownList1Backdrop, 'TOPLEFT', -2, 2) + aux_border:SetPoint('BOTTOMRIGHT', DropDownList1Backdrop, 'BOTTOMRIGHT', 1.5, -1.5) + aux_border:SetBlendMode 'ADD' + aux_background = DropDownList1:CreateTexture(nil, 'OVERLAY') + aux_background:SetTexture(color.content.background()) + aux_background:SetAllPoints(DropDownList1Backdrop) + blizzard_backdrop = DropDownList1Backdrop:GetBackdrop() + hook('ToggleDropDownMenu', function(...) temp=arg + local ret = {orig.ToggleDropDownMenu(unpack(arg)) } + local dropdown = _g[arg[4] or ''] or this:GetParent() + if strfind(dropdown:GetName() or '', '^aux_frame%d+$') then + set_aux_dropdown_style(dropdown) + else + set_blizzard_dropdown_style() + end + return unpack(ret) + end) + + function set_aux_dropdown_style(dropdown) + DropDownList1Backdrop:SetBackdrop{} + aux_border:Show() + aux_background:Show() + DropDownList1:SetWidth(dropdown:GetWidth() * 0.9) + DropDownList1:SetHeight(DropDownList1:GetHeight() - 10) + DropDownList1:ClearAllPoints() + DropDownList1:SetPoint('TOPLEFT', dropdown, 'BOTTOMLEFT', -2, -2) + for i=1,UIDROPDOWNMENU_MAXBUTTONS do + local button = _g['DropDownList1Button'..i] + button:SetPoint('TOPLEFT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7) + button:SetPoint('TOPRIGHT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7) + local text = button:GetFontString() + text:SetFont(font, font_size.small2) + text:SetPoint('TOPLEFT', 18, 0) + text:SetPoint('BOTTOMRIGHT', -8, 0) + local highlight = _g['DropDownList1Button'..i..'Highlight'] + highlight:ClearAllPoints() + highlight:SetDrawLayer 'OVERLAY' + highlight:SetHeight(14) + highlight:SetPoint('LEFT', 5, 0) + highlight:SetPoint('RIGHT', -3, 0) + local check = _g['DropDownList1Button'..i..'Check'] + check:SetWidth(16) + check:SetHeight(16) + check:SetPoint('LEFT', 3, -1) + end + end + + function set_blizzard_dropdown_style() + DropDownList1Backdrop:SetBackdrop(blizzard_backdrop) + aux_border:Hide() + aux_background:Hide() + for i=1,UIDROPDOWNMENU_MAXBUTTONS do + local button = _g['DropDownList1Button'..i] + local text = button:GetFontString() + text:SetFont([[Fonts\FRIZQT__.ttf]], 10) + text:SetShadowOffset(1, -1) + local highlight = _g['DropDownList1Button'..i..'Highlight'] + highlight:SetAllPoints() + highlight:SetDrawLayer 'BACKGROUND' + local check = _g['DropDownList1Button'..i..'Check'] + check:SetWidth(24) + check:SetHeight(24) + check:SetPoint('LEFT', 0, 0) + end + end + end +end + public.font = [[Fonts\ARIALN.TTF]] public.font_size = { @@ -23,7 +97,6 @@ end do local menu, structure, orig menu = CreateFrame('Frame', name, UIParent, 'UIMenuTemplate') - hook('OnShow', menu) orig = menu:GetScript 'OnShow' menu:SetScript('OnShow', function() UIMenu_Initialize() @@ -43,78 +116,6 @@ do end end -do - local blizzard_backdrop, aux_background, aux_border - - aux_border = DropDownList1:CreateTexture() - aux_border:SetTexture(1, 1, 1, .02) - aux_border:SetPoint('TOPLEFT', DropDownList1Backdrop, 'TOPLEFT', -2, 2) - aux_border:SetPoint('BOTTOMRIGHT', DropDownList1Backdrop, 'BOTTOMRIGHT', 1.5, -1.5) - aux_border:SetBlendMode 'ADD' - aux_background = DropDownList1:CreateTexture(nil, 'OVERLAY') - aux_background:SetTexture(color.content.background()) - aux_background:SetAllPoints(DropDownList1Backdrop) - blizzard_backdrop = DropDownList1Backdrop:GetBackdrop() - hook('ToggleDropDownMenu', function(...) - local ret = {orig.ToggleDropDownMenu(unpack(arg))} - local dropdown = _g[arg[4] or ''] or this:GetParent() - if strfind(dropdown:GetName() or '', '^aux_frame%d+$') then - set_aux_dropdown_style(dropdown) - else - set_blizzard_dropdown_style() - end - return unpack(ret) - end) - - function set_aux_dropdown_style(dropdown) - DropDownList1Backdrop:SetBackdrop{} - aux_border:Show() - aux_background:Show() - DropDownList1:SetWidth(dropdown:GetWidth() * 0.9) - DropDownList1:SetHeight(DropDownList1:GetHeight() - 10) - DropDownList1:ClearAllPoints() - DropDownList1:SetPoint('TOPLEFT', dropdown, 'BOTTOMLEFT', -2, -2) - for i=1,UIDROPDOWNMENU_MAXBUTTONS do - local button = _g['DropDownList1Button'..i] - button:SetPoint('TOPLEFT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7) - button:SetPoint('TOPRIGHT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7) - local text = button:GetFontString() - text:SetFont(font, font_size.small2) - text:SetPoint('TOPLEFT', 18, 0) - text:SetPoint('BOTTOMRIGHT', -8, 0) - local highlight = _g['DropDownList1Button'..i..'Highlight'] - highlight:ClearAllPoints() - highlight:SetDrawLayer 'OVERLAY' - highlight:SetHeight(14) - highlight:SetPoint('LEFT', 5, 0) - highlight:SetPoint('RIGHT', -3, 0) - local check = _g['DropDownList1Button'..i..'Check'] - check:SetWidth(16) - check:SetHeight(16) - check:SetPoint('LEFT', 3, -1) - end - end - - function set_blizzard_dropdown_style() - DropDownList1Backdrop:SetBackdrop(blizzard_backdrop) - aux_border:Hide() - aux_background:Hide() - for i=1,UIDROPDOWNMENU_MAXBUTTONS do - local button = _g['DropDownList1Button'..i] - local text = button:GetFontString() - text:SetFont([[Fonts\FRIZQT__.ttf]], 10) - text:SetShadowOffset(1, -1) - local highlight = _g['DropDownList1Button'..i..'Highlight'] - highlight:SetAllPoints() - highlight:SetDrawLayer 'BACKGROUND' - local check = _g['DropDownList1Button'..i..'Check'] - check:SetWidth(24) - check:SetHeight(24) - check:SetPoint('LEFT', 0, 0) - end - end -end - function public.set_size(frame, width, height) frame:SetWidth(width) frame:SetHeight(height or width) diff --git a/gui/item_listing.lua b/gui/item_listing.lua index a11a05f..0f14303 100644 --- a/gui/item_listing.lua +++ b/gui/item_listing.lua @@ -1,4 +1,4 @@ -module 'item_listing' +module 'item_listing' import 'gui' local ROW_HEIGHT = 39 diff --git a/gui/listing.lua b/gui/listing.lua index ddc5fd2..283cff7 100644 --- a/gui/listing.lua +++ b/gui/listing.lua @@ -1,4 +1,4 @@ -module 'listing' +module 'listing' import 'gui' local ST_COUNT = 0 diff --git a/module.lua b/module.lua index a073a18..7de8af9 100644 --- a/module.lua +++ b/module.lua @@ -42,11 +42,12 @@ do local state, modifier = _state[self], MODIFIER[key]; local modifiers = state.modifiers if modifier then if mask(MODIFIER_MASK[key], modifiers) ~= modifiers then modifier_error() end - state.modifiers = modifiers + modifier; return self + state.modifiers = modifiers + modifier elseif not state.metadata[key] or collision_error(key) then if mask(PROPERTY_MASK, modifiers) ~= modifiers then modifier_error() end state.property, state.metadata[key], state.modifiers = key, modifiers + PROPERTY, PRIVATE end + return self end end function declarator_mt.__newindex(self, key, value) diff --git a/tabs/auctions/core.lua b/tabs/auctions/core.lua index a3692d2..a0c3ecb 100644 --- a/tabs/auctions/core.lua +++ b/tabs/auctions/core.lua @@ -1,5 +1,4 @@ module 'auctions_tab' -tab(3, 'Auctions') auction_records = nil diff --git a/tabs/auctions/frame.lua b/tabs/auctions/frame.lua index f2bec9c..3e77910 100644 --- a/tabs/auctions/frame.lua +++ b/tabs/auctions/frame.lua @@ -1,4 +1,4 @@ -module 'auctions_tab' import 'gui' +module 'auctions_tab' import 'gui' 'auction_listing' function create_frames() frame = CreateFrame('Frame', nil, aux_frame) @@ -8,8 +8,8 @@ function create_frames() frame.listing = gui.panel(frame) frame.listing:SetPoint('TOP', frame, 'TOP', 0, -8) - frame.listing:SetPoint('BOTTOMLEFT', frame.content, 'BOTTOMLEFT', 0, 0) - frame.listing:SetPoint('BOTTOMRIGHT', frame.content, 'BOTTOMRIGHT', 0, 0) + frame.listing:SetPoint('BOTTOMLEFT', aux_frame.content, 'BOTTOMLEFT', 0, 0) + frame.listing:SetPoint('BOTTOMRIGHT', aux_frame.content, 'BOTTOMRIGHT', 0, 0) listing = auction_listing.CreateAuctionResultsTable(frame.listing, auction_listing.auctions_config) listing:SetSort(1,2,3,4,5,6,7,8) @@ -28,7 +28,7 @@ function create_frames() status_bar = gui.status_bar(frame) status_bar:SetWidth(265) status_bar:SetHeight(25) - status_bar:SetPoint('TOPLEFT', frame.content, 'BOTTOMLEFT', 0, -6) + status_bar:SetPoint('TOPLEFT', aux_frame.content, 'BOTTOMLEFT', 0, -6) status_bar:update_status(100, 100) status_bar:set_text('') end diff --git a/tabs/bids/core.lua b/tabs/bids/core.lua index 9550ad2..9b8c38f 100644 --- a/tabs/bids/core.lua +++ b/tabs/bids/core.lua @@ -1,5 +1,4 @@ module 'bids_tab' -tab(4, 'Bids') auction_records = nil diff --git a/tabs/bids/frame.lua b/tabs/bids/frame.lua index f5e4625..53d4266 100644 --- a/tabs/bids/frame.lua +++ b/tabs/bids/frame.lua @@ -1,4 +1,4 @@ -module 'bids_tab' import 'gui' +module 'bids_tab' import 'gui' 'auction_listing' function create_frames() frame = CreateFrame('Frame', nil, aux_frame) @@ -8,8 +8,8 @@ function create_frames() frame.listing = gui.panel(frame) frame.listing:SetPoint('TOP', frame, 'TOP', 0, -8) - frame.listing:SetPoint('BOTTOMLEFT', frame.content, 'BOTTOMLEFT', 0, 0) - frame.listing:SetPoint('BOTTOMRIGHT', frame.content, 'BOTTOMRIGHT', 0, 0) + frame.listing:SetPoint('BOTTOMLEFT', aux_frame.content, 'BOTTOMLEFT', 0, 0) + frame.listing:SetPoint('BOTTOMRIGHT', aux_frame.content, 'BOTTOMRIGHT', 0, 0) listing = auction_listing.CreateAuctionResultsTable(frame.listing, auction_listing.bids_config) listing:SetSort(1,2,3,4,5,6,7,8) @@ -32,7 +32,7 @@ function create_frames() status_bar = gui.status_bar(frame) status_bar:SetWidth(265) status_bar:SetHeight(25) - status_bar:SetPoint('TOPLEFT', frame.content, 'BOTTOMLEFT', 0, -6) + status_bar:SetPoint('TOPLEFT', aux_frame.content, 'BOTTOMLEFT', 0, -6) status_bar:update_status(100, 0) status_bar:set_text('') end diff --git a/tabs/post/core.lua b/tabs/post/core.lua index cd66a4b..3d10138 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -1,5 +1,4 @@ module 'post_tab' -tab(2, 'Post') local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440 local settings_schema = {'record', '#', {stack_size='number'}, {duration='number'}, {start_price='number'}, {buyout_price='number'}, {hidden='boolean'}} diff --git a/tabs/post/frame.lua b/tabs/post/frame.lua index 176a505..56df209 100644 --- a/tabs/post/frame.lua +++ b/tabs/post/frame.lua @@ -1,4 +1,4 @@ -module 'post_tab' import 'gui' +module 'post_tab' import [''] 'core' 'gui' 'listing' 'item_listing' 'money' function create_frames() frame = CreateFrame('Frame', nil, aux_frame) @@ -8,20 +8,20 @@ function create_frames() frame.content = CreateFrame('Frame', nil, frame) frame.content:SetPoint('TOP', frame, 'TOP', 0, -8) - frame.content:SetPoint('BOTTOMLEFT', frame.content, 'BOTTOMLEFT', 0, 0) - frame.content:SetPoint('BOTTOMRIGHT', frame.content, 'BOTTOMRIGHT', 0, 0) + frame.content:SetPoint('BOTTOMLEFT', aux_frame.content, 'BOTTOMLEFT', 0, 0) + frame.content:SetPoint('BOTTOMRIGHT', aux_frame.content, 'BOTTOMRIGHT', 0, 0) - frame.inventory = gui.panel(frame.content) + frame.inventory = gui.panel(aux_frame.content) frame.inventory:SetWidth(212) frame.inventory:SetPoint('TOPLEFT', 0, 0) frame.inventory:SetPoint('BOTTOMLEFT', 0, 0) - frame.parameters = gui.panel(frame.content) + frame.parameters = gui.panel(aux_frame.content) frame.parameters:SetHeight(173) frame.parameters:SetPoint('TOPLEFT', frame.inventory, 'TOPRIGHT', 2.5, 0) frame.parameters:SetPoint('TOPRIGHT', 0, 0) - frame.auctions = gui.panel(frame.content) + frame.auctions = gui.panel(aux_frame.content) frame.auctions:SetHeight(228) frame.auctions:SetPoint('BOTTOMLEFT', frame.inventory, 'BOTTOMRIGHT', 2.5, 0) frame.auctions:SetPoint('BOTTOMRIGHT', 0, 0) @@ -84,7 +84,7 @@ function create_frames() status_bar = gui.status_bar(frame) status_bar:SetWidth(265) status_bar:SetHeight(25) - status_bar:SetPoint('TOPLEFT', frame.content, 'BOTTOMLEFT', 0, -6) + status_bar:SetPoint('TOPLEFT', aux_frame.content, 'BOTTOMLEFT', 0, -6) status_bar:update_status(100, 100) status_bar:set_text('') end diff --git a/tabs/search/core.lua b/tabs/search/core.lua index 2b31881..5ff0737 100644 --- a/tabs/search/core.lua +++ b/tabs/search/core.lua @@ -1,5 +1,4 @@ module 'search_tab' -tab(1, 'Search') StaticPopupDialogs['AUX_SEARCH_TABLE_FULL'] = { text = 'Table full!\nFurther results from this search will still be processed but no longer displayed in the table.', diff --git a/tabs/search/frame.lua b/tabs/search/frame.lua index 3024596..758df04 100644 --- a/tabs/search/frame.lua +++ b/tabs/search/frame.lua @@ -1,4 +1,4 @@ -module 'search_tab' import 'gui' +module 'search_tab' import 'gui' [''] 'core' 'completion' 'listing' 'auction_listing' FILTER_SPACING = 28.5 @@ -9,13 +9,13 @@ function create_frames() frame:Hide() frame.filter = gui.panel(frame) - frame.filter:SetAllPoints(frame.content) + frame.filter:SetAllPoints(aux_frame.content) frame.results = gui.panel(frame) - frame.results:SetAllPoints(frame.content) + frame.results:SetAllPoints(aux_frame.content) frame.saved = CreateFrame('Frame', nil, frame) - frame.saved:SetAllPoints(frame.content) + frame.saved:SetAllPoints(aux_frame.content) frame.saved.favorite = gui.panel(frame.saved) frame.saved.favorite:SetWidth(378.5) @@ -243,7 +243,7 @@ function create_frames() end do local btn = gui.button(frame, gui.font_size.large2) - btn:SetPoint('BOTTOMLEFT', frame.content, 'TOPLEFT', 10, 8) + btn:SetPoint('BOTTOMLEFT', aux_frame.content, 'TOPLEFT', 10, 8) btn:SetWidth(243) btn:SetHeight(22) btn:SetText 'Search Results' @@ -272,7 +272,7 @@ function create_frames() local frame = CreateFrame('Frame', nil, frame) frame:SetWidth(265) frame:SetHeight(25) - frame:SetPoint('TOPLEFT', frame.content, 'BOTTOMLEFT', 0, -6) + frame:SetPoint('TOPLEFT', aux_frame.content, 'BOTTOMLEFT', 0, -6) status_bar_frame = frame end do diff --git a/tabs/search/results.lua b/tabs/search/results.lua index 62925c3..b57089a 100644 --- a/tabs/search/results.lua +++ b/tabs/search/results.lua @@ -116,9 +116,9 @@ function update_auto_buy_filter() local queries = filter.queries(_g.aux_auto_buy_filter) if queries then if getn(queries) > 1 then - log('Error: The automatic buyout filter may contain only one query') + log 'Error: The automatic buyout filter does not support multi-queries' elseif size(queries[1].blizzard_query) > 0 then - log('Error: The automatic buyout filter does not support Blizzard filters') + log 'Error: The automatic buyout filter does not support Blizzard filters' else auto_buy_validator = queries[1].validator auto_buy_filter_button.prettified = queries[1].prettified @@ -168,20 +168,20 @@ function start_real_time_scan(query, search, continuation) end end, on_complete = function() - local map = {} + local map = tt for _, record in search.records do map[record.sniping_signature] = record end for _, record in new_records do map[record.sniping_signature] = record end - new_records = {} + new_records = t for _, record in map do tinsert(new_records, record) end if getn(new_records) > 1000 then - StaticPopup_Show('AUX_SEARCH_TABLE_FULL') + StaticPopup_Show 'AUX_SEARCH_TABLE_FULL' else search.records = new_records search.table:SetDatabase(search.records) @@ -193,7 +193,7 @@ function start_real_time_scan(query, search, continuation) end, on_abort = function() search.status_bar:update_status(100, 100) - search.status_bar:set_text('Scan paused') + search.status_bar:set_text 'Scan paused' search.continuation = next_page or not ignore_page and query.blizzard_query.first_page or true @@ -233,9 +233,9 @@ function start_search(queries, continuation) on_scan_start = function() search.status_bar:update_status(0,0) if continuation then - search.status_bar:set_text('Resuming scan...') + search.status_bar:set_text 'Resuming scan...' else - search.status_bar:set_text('Scanning auctions...') + search.status_bar:set_text 'Scanning auctions...' end end, on_page_loaded = function(_, total_scan_pages) @@ -261,13 +261,13 @@ function start_search(queries, continuation) elseif getn(search.records) < 1000 then tinsert(search.records, auction_record) if getn(search.records) == 1000 then - StaticPopup_Show('AUX_SEARCH_TABLE_FULL') + StaticPopup_Show 'AUX_SEARCH_TABLE_FULL' end end end, on_complete = function() search.status_bar:update_status(100, 100) - search.status_bar:set_text('Scan complete') + search.status_bar:set_text 'Scan complete' if current_search == search and frame.results:IsVisible() and getn(search.records) == 0 then set_tab(SAVED) @@ -278,7 +278,7 @@ function start_search(queries, continuation) end, on_abort = function() search.status_bar:update_status(100, 100) - search.status_bar:set_text('Scan paused') + search.status_bar:set_text 'Scan paused' if current_query then search.continuation = {current_query, current_page + 1} @@ -313,10 +313,10 @@ function public.execute(resume, real_time) return elseif real_time then if getn(queries) > 1 then - log('Invalid filter: The real time mode does not support multiple queries') + log 'Error: The real time mode does not support multi-queries' return elseif queries[1].blizzard_query.first_page or queries[1].blizzard_query.last_page then - log('Invalid filter: The real time mode does not support page range filters') + log 'Error: The real time mode does not support page ranges' return end end diff --git a/util/color.lua b/util/color.lua index e6bcfc0..9c35511 100644 --- a/util/color.lua +++ b/util/color.lua @@ -1,4 +1,4 @@ -module 'util' +module 'core' COLORS = { text = {enabled = {255, 254, 250, 1}, disabled = {147, 151, 139, 1}}, diff --git a/util/core.lua b/util/core.lua index 137bd2a..ad82918 100644 --- a/util/core.lua +++ b/util/core.lua @@ -1,28 +1,11 @@ -module 'util' +module 'core' -public.join = _g.join +public.join = _g.table.concat function public.replicate(count, value) if count > 0 then return value, replicate(count - 1, value) end end -do - local value, charges - local function mutator(n) - return function(v) - assert(charges == 0) - value, charges = v, n - return v - end - end - for i=1,9 do public[join{replicate(i, 'x')}] = mutator(i) end - function public.accessor.__() - assert(charges > 0) - charges = charges - 1 - return value - end -end - do local state local function f() @@ -67,14 +50,12 @@ do end end -function public.call(f, ...) - temp(arg) +function public.call(f, ...) temp=arg if f then return f(unpack(arg)) end end -function public.index(t, ...) +function public.index(t, ...) temp=arg for i=1,arg.n do t = t and t[arg[i]] end - recycle(arg) return t end @@ -106,10 +87,9 @@ do end end -function public.expand(array, ...) +function public.expand(array, ...) temp=arg local t = t for i=1,arg.n do t[arg[i]] = array[i] end - recycle(arg) return t end @@ -120,10 +100,25 @@ function public.copy(t) return setmetatable(copy, getmetatable(t)) end -function public.select(i, ...) - temp(arg) +function public.select(i, ...) temp=arg while i > 1 do i = i - 1; tremove(arg, i) end - return tremove(arg, 1), unpack(temp) + return tremove(arg, 1), unpack(arg) +end + +function public.collect(t, ...) temp=arg + local T = T + for _, v in t do + tinsert(T, arg[v]) + end + return T +end + +function public.hashset(t) + local set = _m.t + for _, v in t do + set[v] = true + end + return set end function public.size(t) diff --git a/util/filter.lua b/util/filter.lua index f19aab6..6922d71 100644 --- a/util/filter.lua +++ b/util/filter.lua @@ -285,10 +285,11 @@ function public.parse_query_string(str) local i = 1 while parts[i] do - if x(operator(parts[i])) then - tinsert(post_filter, __) - elseif x(filters[parts[i]]) then - local input_type = __.input_type + local operator = operator(parts[i]) + if operator then + tinsert(post_filter, operator) + elseif filters[parts[i]] then + local input_type = filters[parts[i]].input_type if input_type ~= '' then if not parts[i + 1] or not parse_parameter(input_type, parts[i + 1]) then if parts[i] == 'item' then @@ -494,8 +495,10 @@ function blizzard_query(components) local query = {name=filters.name and filters.name[2]} local item_info, class_index, subclass_index, slot_index - if filters.exact and x(cache.item_id(filters.name[2])) and x(info.item(__)) then - item_info = __ + local item_id = cache.item_id(filters.name[2]) + item_info = item_id and info.item(item_id) + if filters.exact and item_info then + item_info = info.item(item_id) class_index = info.item_class_index(item_info.class) subclass_index = info.item_subclass_index(class_index or 0, item_info.subclass) slot_index = info.item_slot_index(class_index or 0, subclass_index or 0, item_info.slot) @@ -510,7 +513,7 @@ function blizzard_query(components) query.slot = slot_index query.quality = item_info.quality else - for _, key in {'min_level', 'max_level', 'class', 'subclass', 'slot', 'usable', 'quality'} do + for key in set 'min_level' 'max_level' 'class' 'subclass' 'slot' 'usable' 'quality' do query[key] = index(filters[key], 2) end end diff --git a/util/info.lua b/util/info.lua index 7423e4b..47cce91 100644 --- a/util/info.lua +++ b/util/info.lua @@ -176,7 +176,7 @@ end function public.set_shopping_tooltip(slot) local index1, index2 = inventory_index(slot) - local tooltips = {} + local tooltips = tt if index1 then local tooltip = tooltip(function(tt) tt:SetInventoryItem('player', index1) end) if getn(tooltip) > 0 then @@ -273,7 +273,7 @@ function public.tooltip(mutator) mutator(AuxTooltip) AuxTooltip:Show() - local tooltip = {} + local tooltip = t for i=1,AuxTooltip:NumLines() do tinsert(tooltip, { left_text = _g['AuxTooltipTextLeft'..i]:GetText(), diff --git a/util/money.lua b/util/money.lua index 6dad09c..4b027bc 100644 --- a/util/money.lua +++ b/util/money.lua @@ -80,7 +80,7 @@ function public.to_string(money, pad, trim, decimal_points, color, no_color) local text if trim then - local parts = {} + local parts = tt if gold > 0 then tinsert(parts, format_number(gold, false, nil, color)..gold_text) end @@ -113,8 +113,9 @@ function public.to_string(money, pad, trim, decimal_points, color, no_color) end function public.from_string(value) - if xx(tonumber(value)) and __ >= 0 then - return __ * COPPER_PER_GOLD + local number = tonumber(value) + if number and number >= 0 then + return number * COPPER_PER_GOLD end -- remove any colors diff --git a/util/persistence.lua b/util/persistence.lua index 4ccc3b7..ebf741f 100644 --- a/util/persistence.lua +++ b/util/persistence.lua @@ -1,6 +1,6 @@ module 'persistence' -_g.aux_datasets = {} +_g.aux_datasets = t do local realm, faction @@ -15,7 +15,7 @@ end function public.load_dataset() local dataset_key = dataset_key - _g.aux_datasets[dataset_key] = _g.aux_datasets[dataset_key] or {} + _g.aux_datasets[dataset_key] = _g.aux_datasets[dataset_key] or t return _g.aux_datasets[dataset_key] end @@ -64,8 +64,7 @@ function public.write(schema, obj) end function public.read_list(schema, str) - if str == '' then return {} end - + if str == '' then return t end local separator = schema[2] local element_type = schema[3] local parts = split(str, separator) @@ -85,7 +84,7 @@ end function public.read_record(schema, str) local separator = schema[2] - local record = {} + local record = t local parts = split(str, separator) for i=3,getn(schema) do local key, type = next(schema[i]) @@ -96,7 +95,7 @@ end function public.write_record(schema, record) local separator = schema[2] - local parts = {} + local parts = tt for i=3,getn(schema) do local key, type = next(schema[i]) tinsert(parts, write(type, record[key])) diff --git a/util/scan.lua b/util/scan.lua index 7622ac2..a2bfc69 100644 --- a/util/scan.lua +++ b/util/scan.lua @@ -7,8 +7,8 @@ function public.find(auction_record, status_bar, on_abort, on_failure, on_succes return auction_info and auction_info.search_signature == auction_record.search_signature end - local queries = {} - tinsert(queries, {}) + local queries = t + tinsert(queries, t) if auction_record.blizzard_query then diff --git a/util/sort.lua b/util/sort.lua index 9eebe66..01d7867 100644 --- a/util/sort.lua +++ b/util/sort.lua @@ -1,10 +1,10 @@ module 'sorting' -public.LT = {} -public.EQ = {} -public.GT = {} +public() -function public.compare(a, b, desc) +LT, EQ, GT = t, t, t + +function compare(a, b, desc) if a < b then return desc and GT or LT elseif a > b then @@ -14,7 +14,7 @@ function public.compare(a, b, desc) end end -function public.multi_lt(xs, ys) +function multi_lt(xs, ys) local i = 1 while true do if xs[i] and ys[i] and xs[i] ~= ys[i] then