refactoring, bugfix

This commit is contained in:
Manuel Simon Hirsig
2016-11-09 02:08:45 +01:00
parent c7d2284b3d
commit 05fb051bd4
18 changed files with 109 additions and 99 deletions
+4 -2
View File
@@ -83,7 +83,8 @@ function SetItemRef(...)
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
local item_info = info.item(tonumber(select(3, strfind(arg[1], '^item:(%d+)'))))
if item_info then
return active_tab.CLICK_LINK(item_info)
end
end
@@ -93,7 +94,8 @@ function UseContainerItem(...)
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
local item_info = info.container_item(arg[1], arg[2])
if item_info then
return active_tab.USE_ITEM(item_info)
end
end
+4 -2
View File
@@ -57,13 +57,15 @@ do
end
function M.kill_listener(listener_id)
for listener in present(listeners[listener_id]) do
local listener = listeners[listener_id]
if listener then
listener.killed = true
end
end
function M.kill_thread(thread_id)
for thread in present(threads[thread_id]) do
local thread = threads[thread_id]
if thread then
thread.killed = true
end
end
+4 -2
View File
@@ -30,8 +30,10 @@ function LOAD()
CreateFrame('Frame', nil, MerchantFrame):SetScript('OnUpdate', merchant_on_update)
event_listener('NEW_AUCTION_UPDATE', function()
for data in present(info.auction_sell_item()) do
for item_id in present(item_id(data.name)) do
local data = info.auction_sell_item()
if data then
local item_id = item_id(data.name)
if item_id then
aux_merchant_sell[_M.item_id(data.name)] = data.vendor_price / (info.max_item_charges(item_id) or data.count)
end
end
+3 -2
View File
@@ -108,7 +108,7 @@ end
function weighted_median(list)
sort(list, function(a,b) return a.value < b.value end)
local weight = 0
for _, element in list do
for _, element in ipairs(list) do
weight = weight + element.weight
if weight >= .5 then
return element.value
@@ -117,7 +117,8 @@ function weighted_median(list)
end
function push_record(item_record)
for market_value in present(market_value(item_record)) do
local market_value = market_value(item_record)
if market_value then
tinsert(item_record.data_points, 1, weak-O('market_value', market_value, 'time', item_record.next_push))
while getn(item_record.data_points) > 11 do
release(item_record.data_points[getn(item_record.data_points)])
+2 -1
View File
@@ -12,7 +12,8 @@ do
local scan_states = T
function M.start(params)
for old_state in present(scan_states[params.type]) do
local old_state = scan_states[params.type]
if old_state then
abort(old_state.id)
end
do (params.on_scan_start or nop)() end
+1 -1
View File
@@ -83,7 +83,7 @@ function SlashCmdList.AUX(command)
elseif arguments[1] == 'chars' then
local realm = GetCVar'realmName'
local chars = T
for name in aux_characters[realm] or T do
for name in aux_characters[realm] or empty do
tinsert(chars, name)
end
if getn(chars) > 0 then
+18 -9
View File
@@ -124,38 +124,44 @@ function game_tooltip_hooks:SetHyperlink(itemstring)
end
function game_tooltip_hooks:SetAuctionItem(type, index)
for link in present(GetAuctionItemLink(type, index)) do
local link = GetAuctionItemLink(type, index)
if link then
extend_tooltip(GameTooltip, link, select(3, GetAuctionItemInfo(type, index)))
end
end
function game_tooltip_hooks:SetLootItem(slot)
for link in present(GetLootSlotLink(slot)) do
local link = GetLootSlotLink(slot)
if link then
extend_tooltip(GameTooltip, link, select(3, GetLootSlotInfo(slot)))
end
end
function game_tooltip_hooks:SetQuestItem(qtype, slot)
for link in present(GetQuestItemLink(qtype, slot)) do
local link = GetQuestItemLink(qtype, slot)
if link then
extend_tooltip(GameTooltip, link, select(3, GetQuestItemInfo(qtype, slot)))
end
end
function game_tooltip_hooks:SetQuestLogItem(qtype, slot)
for link in present(GetQuestLogItemLink(qtype, slot)) do
local link = GetQuestLogItemLink(qtype, slot)
if link then
extend_tooltip(GameTooltip, link, select(3, GetQuestLogRewardInfo(slot)))
end
end
function game_tooltip_hooks:SetBagItem(bag, slot)
for link in present(GetContainerItemLink(bag, slot)) do
local link = GetContainerItemLink(bag, slot)
if link then
extend_tooltip(GameTooltip, link, select(2, GetContainerItemInfo(bag, slot)))
end
end
function game_tooltip_hooks:SetInboxItem(index)
local name, _, quantity = GetInboxItem(index)
for id in present(name and cache.item_id(name)) do
local id = name and cache.item_id(name)
if id then
local _, itemstring, quality = GetItemInfo(id)
local hex = select(4, GetItemQualityColor(tonumber(quality)))
local link = hex .. '|H' .. itemstring .. '|h[' .. name .. ']|h' .. FONT_COLOR_CODE_CLOSE
@@ -164,13 +170,15 @@ function game_tooltip_hooks:SetInboxItem(index)
end
function game_tooltip_hooks:SetInventoryItem(unit, slot)
for link in present(GetInventoryItemLink(unit, slot)) do
local link = GetInventoryItemLink(unit, slot)
if link then
extend_tooltip(GameTooltip, link, 1)
end
end
function game_tooltip_hooks:SetMerchantItem(slot)
for link in present(GetMerchantItemLink(slot)) do
local link = GetMerchantItemLink(slot)
if link then
local quantity = select(4, GetMerchantItemInfo(slot))
extend_tooltip(GameTooltip, link, quantity)
end
@@ -189,7 +197,8 @@ function game_tooltip_hooks:SetCraftItem(skill, slot)
end
function game_tooltip_hooks:SetCraftSpell(slot)
for link in present(GetCraftItemLink(slot)) do
local link = GetCraftItemLink(slot)
if link then
extend_tooltip(GameTooltip, link, 1)
end
end
+1 -1
View File
@@ -3,7 +3,7 @@ module 'aux'
local gui = require 'aux.gui'
function LOAD()
for _, info in tab_info do
for _, info in ipairs(tab_info) do
tabs:create_tab(info.name)
end
end
+3 -3
View File
@@ -859,9 +859,9 @@ local methods = {
-- get index of selected row
local prevSelectedIndex
if rt.selected then
for index, row in rt.rows do
for i, row in rt.rows do
if row:IsVisible() and row.data and row.data.record == rt.selected then
prevSelectedIndex = index
prevSelectedIndex = i
end
end
end
@@ -1038,7 +1038,7 @@ function M.CreateAuctionResultsTable(parent, config)
-- create the header cells
rt.headCells = T
for i, column_config in rt.config do
for i, column_config in ipairs(rt.config) do
local cell = CreateFrame('Button', nil, rt.contentFrame)
cell:SetHeight(HEAD_HEIGHT)
if i == 1 then
+21 -28
View File
@@ -13,13 +13,6 @@ local ST_HEAD_HEIGHT = 26.3
local ST_HEAD_SPACE = 2
local DEFAULT_COL_INFO = {{width=1}}
local function GetTableIndex(tbl, value)
for i, v in tbl do
if value == v then return i end
end
end
local function OnColumnClick()
local button = arg1
if this.st.sortInfo.enabled and button == 'LeftButton' then
@@ -55,7 +48,7 @@ local defaultColScripts = {
OnLeave = function()
this.row.mouseover = false
if not this.row.data then return end
if this.st.selectionDisabled or not this.st.selected or this.st.selected ~= GetTableIndex(this.st.rowData, this.row.data) then
if this.st.selectionDisabled or not this.st.selected or this.st.selected ~= key(this.st.rowData, this.row.data) then
this.row.highlight:Hide()
end
@@ -68,7 +61,7 @@ local defaultColScripts = {
OnClick = function()
if not this.row.data then return end
this.st:ClearSelection()
this.st.selected = GetTableIndex(this.st.rowData, this.row.data)
this.st.selected = key(this.st.rowData, this.row.data)
this.row.highlight:Show()
local handler = this.st.handlers.OnClick
@@ -119,8 +112,8 @@ local methods = {
if not data then break end
st.rows[i].data = data
if (st.selected == GetTableIndex(st.rowData, data) and not st.selectionDisabled)
or (st.highlighted and st.highlighted == GetTableIndex(st.rowData, data))
if (st.selected == key(st.rowData, data) and not st.selectionDisabled)
or (st.highlighted and st.highlighted == key(st.rowData, data))
or st.rows[i].mouseover
then
st.rows[i].highlight:Show()
@@ -128,9 +121,9 @@ local methods = {
st.rows[i].highlight:Hide()
end
for colNum, col in st.rows[i].cols do
if st.colInfo[colNum] then
local colData = data.cols[colNum]
for j, col in st.rows[i].cols do
if st.colInfo[j] then
local colData = data.cols[j]
if type(colData.value) == 'function' then
col:SetText(colData.value(unpack(colData.args)))
else
@@ -244,13 +237,13 @@ local methods = {
end
-- adjust head col widths
for colNum, col in st.headCols do
if st.colInfo[colNum] then
for i, col in st.headCols do
if st.colInfo[i] then
col:Show()
col:SetWidth(st.colInfo[colNum].width * width)
col:SetWidth(st.colInfo[i].width * width)
col:SetHeight(st.sizes.headHeight)
col:SetText(st.colInfo[colNum].name or "")
col.text:SetJustifyH(st.colInfo[colNum].headAlign or 'CENTER')
col:SetText(st.colInfo[i].name or "")
col.text:SetJustifyH(st.colInfo[i].headAlign or 'CENTER')
else
col:Hide()
end
@@ -262,21 +255,21 @@ local methods = {
end
-- adjust rows widths
for rowNum, row in st.rows do
if rowNum > st.sizes.numRows then
for i, row in st.rows do
if i > st.sizes.numRows then
row.data = nil
row:Hide()
else
row:Show()
-- add any missing cols
while getn(row.cols) < getn(st.colInfo) do
st:AddRowCol(rowNum)
st:AddRowCol(i)
end
for colNum, col in row.cols do
if st.headCols[colNum] and st.colInfo[colNum] then
for j, col in row.cols do
if st.headCols[j] and st.colInfo[j] then
col:Show()
col:SetWidth(st.colInfo[colNum].width * width)
col.text:SetJustifyH(st.colInfo[colNum].align or 'LEFT')
col:SetWidth(st.colInfo[j].width * width)
col.text:SetJustifyH(st.colInfo[j].align or 'LEFT')
else
col:Hide()
end
@@ -318,9 +311,9 @@ local methods = {
tinsert(st.headCols, col)
-- add new cells to the rows
for rowNum, row in st.rows do
for i, row in st.rows do
while getn(row.cols) < getn(st.headCols) do
st:AddRowCol(rowNum)
st:AddRowCol(i)
end
end
end,
+3 -2
View File
@@ -115,7 +115,7 @@ function update_auction_listing()
local unit_start_price = get_unit_start_price()
local unit_buyout_price = get_unit_buyout_price()
for i, auction_record in existing_auctions[selected_item.key] or temp-T do
for i, auction_record in ipairs(existing_auctions[selected_item.key] or empty) do
local blizzard_bid_undercut, buyout_price_undercut = undercut(auction_record, stack_size_slider:GetValue())
blizzard_bid_undercut = money.from_string(money.to_string(blizzard_bid_undercut, true, nil, 3))
@@ -414,7 +414,8 @@ function update_inventory_records()
local auctionable_map = temp-T
for slot in info.inventory do
temp(slot)
for item_info in present(temp-info.container_item(unpack(slot))) do
local item_info = temp-info.container_item(unpack(slot))
if item_info then
local charge_class = item_info.charges or 0
if info.auctionable(item_info.tooltip, nil, item_info.lootable) then
if not auctionable_map[item_info.item_key] then
+13 -9
View File
@@ -133,7 +133,8 @@ function get_filter_builder_query()
if blizzard_query.subclass and blizzard_query.subclass > 0 then
add(strlower(subclasses[blizzard_query.subclass]))
end
for slot_index in present(blizzard_query.slot) do
local slot_index = blizzard_query.slot
if slot_index then
local slots = temp-A(GetAuctionInvTypes(blizzard_query.class or 0, blizzard_query.subclass or 0))
add(strlower(_G[slots[slot_index]]))
end
@@ -151,7 +152,7 @@ end
function set_form(filter)
clear_form()
for _, component in filter.components do
for _, component in ipairs(filter.components) do
if component[1] == 'blizzard' then
blizzard_query[component[2]] = component[4]
else
@@ -198,7 +199,7 @@ function formatted_post_filter(components)
local stack = temp-T
local str = ''
for i, component in components do
for i, component in ipairs(components) do
if no_line_break then
str = str .. ' '
elseif i > 1 then
@@ -215,7 +216,8 @@ function formatted_post_filter(components)
component_text = component_text .. filter_color(tonumber(component[3]) or '')
tinsert(stack, component[3])
elseif component[1] == 'filter' then
for parameter in present(component[3]) do
local parameter = component[3]
if parameter then
if component[2] == 'item' then
parameter = info.display_name(cache.item_id(parameter)) or '[' .. parameter .. ']'
elseif filter_util.filters[component[2]].input_type == 'money' then
@@ -270,8 +272,10 @@ function add_component(component)
end
function add_post_filter()
for str in present(filter_input:GetText()) do
for filter in present(filter_util.filters[str]) do
local str = filter_input:GetText()
if str then
local filter = filter_util.filters[str]
if filter then
if filter.input_type ~= '' then
str = str .. '/' .. filter_parameter_input:GetText()
end
@@ -355,7 +359,7 @@ function initialize_class_dropdown()
end
end
UIDropDownMenu_AddButton(O('text', ALL, 'value', 0, 'func', on_click))
for i, class in temp-A(GetAuctionItemClasses()) do
for i, class in ipairs(temp-A(GetAuctionItemClasses())) do
UIDropDownMenu_AddButton(O('text', class, 'value', i, 'func', on_click))
end
end
@@ -368,7 +372,7 @@ function initialize_subclass_dropdown()
end
end
UIDropDownMenu_AddButton(O('text', ALL, 'value', 0, 'func', on_click))
for i, subclass in temp-A(GetAuctionItemSubClasses(blizzard_query.class or 0)) do
for i, subclass in ipairs(temp-A(GetAuctionItemSubClasses(blizzard_query.class or 0))) do
UIDropDownMenu_AddButton(O('text', subclass, 'value', i, 'func', on_click))
end
end
@@ -379,7 +383,7 @@ function initialize_slot_dropdown()
update_form()
end
UIDropDownMenu_AddButton(O('text', ALL, 'value', '', 'func', on_click))
for i, slot in temp-A(GetAuctionInvTypes(blizzard_query.class == 2 and 2 or 0, blizzard_query.subclass or 0)) do
for i, slot in ipairs(temp-A(GetAuctionInvTypes(blizzard_query.class == 2 and 2 or 0, blizzard_query.subclass or 0))) do
UIDropDownMenu_AddButton(O('text', _G[slot], 'value', i, 'func', on_click))
end
end
+3 -3
View File
@@ -8,7 +8,7 @@ _G.aux_recent_searches = T
function update_search_listings()
local autobuy_filter_rows = T
for i, autobuy_filter in aux_auto_buy_filters do
for i, autobuy_filter in ipairs(aux_auto_buy_filters) do
local name = strsub(autobuy_filter.prettified, 1, 250)
tinsert(autobuy_filter_rows, O(
'cols', A(O('value', name)),
@@ -19,7 +19,7 @@ function update_search_listings()
auto_buy_listing:SetData(autobuy_filter_rows)
local favorite_search_rows = T
for i, favorite_search in aux_favorite_searches do
for i, favorite_search in ipairs(aux_favorite_searches) do
local name = strsub(favorite_search.prettified, 1, 250)
tinsert(favorite_search_rows, O(
'cols', A(O('value', name)),
@@ -30,7 +30,7 @@ function update_search_listings()
favorite_searches_listing:SetData(favorite_search_rows)
local recent_search_rows = T
for i, recent_search in aux_recent_searches do
for i, recent_search in ipairs(aux_recent_searches) do
local name = strsub(recent_search.prettified, 1, 250)
tinsert(recent_search_rows, O(
'cols', A(O('value', name)),
-13
View File
@@ -34,19 +34,6 @@ function M.replicate(count, value)
if count > 0 then return value, replicate(count - 1, value) end
end
do
local state
local function f()
local temp = state
state = nil
return temp
end
function M.present(v)
state = v
return f
end
end
M.index = vararg-function(arg)
local t = tremove(arg, 1)
for i = 1, getn(arg) do t = t and t[arg[i]] end return t
+2 -2
View File
@@ -18,7 +18,7 @@ function M:complete_filter()
local start_index, _, current_modifier = strfind(filter_string, '([^/;]*)$')
current_modifier = current_modifier or ''
for _, suggestion in suggestions do
for _, suggestion in ipairs(suggestions) do
if strsub(strupper(suggestion), 1, strlen(current_modifier)) == strupper(current_modifier) then
this:SetText(strlower(strsub(filter_string, 1, start_index - 1) .. suggestion))
this:HighlightText(strlen(filter_string), -1)
@@ -35,7 +35,7 @@ function M.complete(options)
local text = self:GetText()
for _, item_name in options() do
for _, item_name in ipairs(options()) do
if strsub(strupper(item_name), 1, strlen(text)) == strupper(text) then
self:SetText(strlower(item_name))
self:HighlightText(strlen(text), -1)
+17 -13
View File
@@ -213,7 +213,8 @@ M.filters = {
function operator(str)
local operator = str == 'not' and A('operator', 'not', 1)
for name in temp-S('and', 'or') do
for arity in present(select(3, strfind(str, '^' .. name .. '(%d*)$'))) do
local arity = select(3, strfind(str, '^' .. name .. '(%d*)$'))
if arity then
arity = tonumber(arity)
operator = not (arity and arity < 2) and A('operator', name, arity)
end
@@ -229,9 +230,10 @@ do
return self
end
if self.exact then return end
for number in present(tonumber(select(3, strfind(str, '^(%d+)$')))) do
local number = tonumber(select(3, strfind(str, '^(%d+)$')))
if number then
if number >= 1 and number <= 60 then
for _, key in temp-A('min_level', 'max_level') do
for _, key in ipairs(temp-A('min_level', 'max_level')) do
if not self[key] then
self[key] = A(str, number)
return A('blizzard', key, str, number)
@@ -338,7 +340,7 @@ function M.query(filter_string)
end
local polish_notation_counter = 0
for _, component in filter.post do
for _, component in ipairs(filter.post) do
if component[1] == 'operator' then
polish_notation_counter = max(polish_notation_counter, 1)
polish_notation_counter = polish_notation_counter + (tonumber(component[2]) or 1) - 1
@@ -368,7 +370,7 @@ end
function M.queries(filter_string)
local parts = split(filter_string, ';')
local queries = T
for _, str in parts do
for _, str in ipairs(parts) do
str = trim(str)
local query, _, error = query(str)
if not query then
@@ -391,19 +393,19 @@ function suggestions(filter)
-- classes
if not filter.blizzard.class then
for _, class in temp-A(GetAuctionItemClasses()) do tinsert(suggestions, class) end
for _, class in ipairs(temp-A(GetAuctionItemClasses())) do tinsert(suggestions, class) end
end
-- subclasses
if not filter.blizzard.subclass then
for _, subclass in temp-A(GetAuctionItemSubClasses(index(filter.blizzard.class, 2) or 0)) do
for _, subclass in ipairs(temp-A(GetAuctionItemSubClasses(index(filter.blizzard.class, 2) or 0))) do
tinsert(suggestions, subclass)
end
end
-- slots
if not filter.blizzard.slot then
for _, invtype in temp-A(GetAuctionInvTypes(index(filter.blizzard.class, 2) == 2 and 2 or 0, index(filter.blizzard.subclass, 2) or 0)) do
for _, invtype in ipairs(temp-A(GetAuctionInvTypes(index(filter.blizzard.class, 2) == 2 and 2 or 0, index(filter.blizzard.subclass, 2) or 0))) do
tinsert(suggestions, _G[invtype])
end
end
@@ -418,7 +420,7 @@ function suggestions(filter)
-- item names
if getn(filter.components) == 0 then
for _, name in aux_auctionable_items do
for _, name in ipairs(aux_auctionable_items) do
tinsert(suggestions, name .. '/exact')
end
end
@@ -429,14 +431,15 @@ end
function M.filter_string(components)
local query_builder = query_builder()
for _, component in components do
for _, component in ipairs(components) do
if component[1] == 'blizzard' then
query_builder.append(filter[4] or filter[3])
elseif component[1] == 'operator' then
query_builder.append(component[2] .. (component[2] ~= 'not' and tonumber(component[3]) or ''))
elseif component[1] == 'filter' then
query_builder.append(component[2])
for parameter in present(component[3]) do
local parameter = component[3]
if parameter then
if filter_util.filters[component[2]].input_type == 'money' then
parameter = money.to_string(money.from_string(parameter), nil, true, nil, nil, true)
end
@@ -451,7 +454,7 @@ end
function prettified_filter_string(filter)
local prettified = query_builder()
for _, component in filter.components do
for _, component in ipairs(filter.components) do
if component[1] == 'blizzard' then
if component[2] == 'name' then
if filter.blizzard.exact then
@@ -468,7 +471,8 @@ function prettified_filter_string(filter)
if component[2] ~= 'tooltip' then
prettified.append(color.orange(component[2]))
end
for parameter in present(component[3]) do
local parameter = component[3]
if parameter then
if component[2] == 'item' then
prettified.append(info.display_name(cache.item_id(parameter)) or color.label.enabled('[' .. parameter .. ']'))
else
+8 -5
View File
@@ -43,8 +43,8 @@ do
end
function M.container_item(bag, slot)
for link in present(GetContainerItemLink(bag, slot)) do
local link = GetContainerItemLink(bag, slot)
if link then
local item_id, suffix_id, unique_id, enchant_id = parse_link(link)
local item_info = temp-item(item_id, suffix_id, unique_id, enchant_id)
@@ -102,7 +102,8 @@ end
function M.auction(index, query_type)
query_type = query_type or 'list'
for link in present(GetAuctionItemLink(query_type, index)) do
local link = GetAuctionItemLink(query_type, index)
if link then
local item_id, suffix_id, unique_id, enchant_id = parse_link(link)
local item_info = temp-item(item_id, suffix_id, unique_id, enchant_id)
@@ -248,7 +249,8 @@ function M.load_tooltip(frame, tooltip)
end
function M.display_name(item_id, no_brackets, no_color)
for item_info in present(item(item_id)) do
local item_info = item(item_id)
if item_info then
local name = item_info.name
if not no_brackets then
name = '[' .. name .. ']'
@@ -428,7 +430,8 @@ end
function M.bag_type(bag)
if bag == 0 then return 1 end
for link in present(GetInventoryItemLink('player', ContainerIDToInventoryID(bag))) do
local link = GetInventoryItemLink('player', ContainerIDToInventoryID(bag))
if link then
local item_id = parse_link(link)
local item_info = item(item_id)
return item_subclass_index(3, item_info.subclass)
+2 -1
View File
@@ -73,7 +73,8 @@ function M.find(auction_record, status_bar, on_abort, on_failure, on_success)
end
function M.item_query(item_id, first_page, last_page)
for item_info in present(info.item(item_id)) do
local item_info = info.item(item_id)
if item_info then
local query = filter_util.query(item_info.name .. '/exact')
query.blizzard_query.first_page = first_page
query.blizzard_query.last_page = last_page