diff --git a/Aux-AddOn.toc b/Aux-AddOn.toc index 4c2425d..2af6c3a 100644 --- a/Aux-AddOn.toc +++ b/Aux-AddOn.toc @@ -1,15 +1,14 @@ ## Interface: 11200 ## Title: Aux ## SavedVariablesPerCharacter: aux_recent_searches, aux_favorite_searches, aux_post_mode, aux_price_per_unit, aux_tooltip_daily, aux_tooltip_vendor_buy, aux_tooltip_vendor_sell, aux_tooltip_disenchant_value, aux_tooltip_disenchant_distribution, aux_tooltip_disenchant_source -## SavedVariables: aux_datasets, aux_items, aux_auctionable_items, aux_merchant_buy, aux_merchant_sell +## SavedVariables: aux_datasets, aux_items, aux_item_ids, aux_auctionable_items, aux_merchant_buy, aux_merchant_sell slash.lua core.xml gui.lua control.xml persistence.lua -item_cache.lua -merchant.lua +cache.lua disenchant.lua tooltip.lua util.lua diff --git a/cache.lua b/cache.lua new file mode 100644 index 0000000..5e4bf77 --- /dev/null +++ b/cache.lua @@ -0,0 +1,155 @@ +local private, public = {}, {} +Aux.cache = public + +local MIN_ITEM_ID, MAX_ITEM_ID = 1, 30000 + +aux_items = {} +aux_item_ids = {} +aux_auctionable_items = {} +aux_merchant_buy = {} +aux_merchant_sell = {} + +function public.on_load() + private.scan_wdb() + Aux.control.event_listener('MERCHANT_SHOW', private.scan_merchant).start() +end + +function public.merchant_info(item_id) + local unit_price, limited + if aux_merchant_buy[item_id] then + local buy_fields = Aux.util.split(aux_merchant_buy[item_id], '#') + unit_price, limited = tonumber(buy_fields[1]), not not tonumber(buy_fields[2]) + end + + return aux_merchant_sell[item_id], unit_price, limited +end + +-- TODO hook GetAuctionSellItemInfo() + +function private.scan_merchant() + Aux.util.loop_inventory(function(bag, slot) + local item_info = Aux.info.container_item(bag, slot) + if item_info then + aux_merchant_sell[item_info.item_id] = item_info.tooltip.money / item_info.aux_quantity + end + end) + + -- TODO maybe more detail? zone or local merchant_name = UnitName('npc') + local merchant_item_count = GetMerchantNumItems() + for i=1,merchant_item_count do + local link = GetMerchantItemLink(i) + if link then + local item_id = Aux.info.parse_hyperlink(link) + local _, _, price, count, stock = GetMerchantItemInfo(i) + local new_unit_price, new_limited = price / count, Aux.persistence.blizzard_boolean(stock >= 0) + if aux_merchant_buy[item_id] then + local fields = Aux.util.split(aux_merchant_buy[item_id], '#') + local old_unit_price, old_limited = tonumber(fields[1]), tonumber(fields[2]) + + local unit_price + if old_limited and not new_limited then + unit_price = new_unit_price + elseif new_limited and not old_limited then + unit_price = old_unit_price + else + unit_price = min(old_unit_price, new_unit_price) + end + + aux_merchant_buy[item_id] = Aux.util.join({ + unit_price, + tostring(old_limited or new_limited), + }, '#') + else + aux_merchant_buy[item_id] = Aux.util.join({ + new_unit_price, + tostring(new_limited), + }, '#') + end + end + end +end + +function private.read_item_info(data_string) + local fields = Aux.util.split(data_string, '#') + return { + name = fields[2], + quality = tonumber(fields[3]), + level = tonumber(fields[4]), + class = fields[5], + subclass = fields[6], + slot = fields[7], + max_stack = fields[8], + texture = fields[9], + } +end + +function public.item_info(item_id) + return aux_items[item_id] and private.read_item_info(aux_items[item_id]) +end + +function public.item_id(item_name) + return aux_item_ids[strlower(item_name)] +end + +function private.scan_wdb() + + local function helper(item_id) + local processed = 0 + while processed <= 100 and item_id <= MAX_ITEM_ID do + local itemstring = 'item:'..item_id + local name, _, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring) + name = name and strlower(name) + if name and not aux_item_ids[name] then + aux_item_ids[name] = item_id + aux_items[item_id] = Aux.util.join({ + name, + quality or '', + level or '', + class or '', + subclass or '', + slot or '', + max_stack or '', + texture or '' + }, '#') + local tooltip = Aux.info.tooltip(function(tt) tt:SetHyperlink(itemstring) end) + if Aux.info.auctionable(tooltip, quality) then + tinsert(aux_auctionable_items, name) + end + processed = processed + 1 + end + item_id = item_id + 1 + end + + if item_id <= MAX_ITEM_ID then + local t0 = GetTime() + Aux.control.as_soon_as(function() return GetTime() - t0 > 0.1 end, function() + return helper(item_id) + end) + else + sort(aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end) + end + end + + helper(MIN_ITEM_ID) +end + +function public.populate_wdb() + + local function helper(item_id) + if item_id > MAX_ITEM_ID then + Aux.log('Cache populated.') + return + end + + if not GetItemInfo('item:'..item_id) then + Aux.log('Fetching item '..item_id..'.') + AuxTooltip:SetHyperlink('item:'..item_id) + end + + Aux.control.on_next_update(function() + return helper(item_id + 1) + end) + end + + helper(MIN_ITEM_ID) +end \ No newline at end of file diff --git a/core.lua b/core.lua index d186e45..7e13d9c 100644 --- a/core.lua +++ b/core.lua @@ -47,8 +47,7 @@ function Aux.on_load() end) end - Aux.merchant.on_load() - Aux.item_cache.on_load() + Aux.cache.on_load() Aux.persistence.on_load() Aux.tooltip.on_load() Aux.search_frame.on_load() @@ -99,7 +98,7 @@ function Aux.on_addon_loaded() for i=1,reagent_count do local item_id, suffix_id = Aux.info.parse_hyperlink(GetCraftReagentItemLink(id, i)) local count = ({GetCraftReagentInfo(id, i)})[3] - local _, price, limited = Aux.merchant.info(item_id) + local _, price, limited = Aux.cache.merchant_info(item_id) local value = price and not limited and price or Aux.history.value(item_id..':'..suffix_id) if not value then total_cost = nil @@ -126,7 +125,7 @@ function Aux.on_addon_loaded() for i=1,reagent_count do local item_id, suffix_id = Aux.info.parse_hyperlink(GetTradeSkillReagentItemLink(id, i)) local count = ({GetTradeSkillReagentInfo(id, i)})[3] - local _, price, limited = Aux.merchant.info(item_id) + local _, price, limited = Aux.cache.merchant_info(item_id) local value = price and not limited and price or Aux.history.value(item_id..':'..suffix_id) if not value then total_cost = nil diff --git a/info.lua b/info.lua index e6ddc04..e18dcd0 100644 --- a/info.lua +++ b/info.lua @@ -364,18 +364,18 @@ function public.itemstring(item_id, suffix_id, unique_id, enchant_id) return 'item:'..(item_id or 0)..':'..(enchant_id or 0)..':'..(suffix_id or 0)..':'..(unique_id or 0) end -function public.item(item_id, suffix_id, unique_id, enchant_id) - local itemstring = 'item:'..(item_id or 0)..':'..(enchant_id or 0)..':'..(suffix_id or 0)..':'..(unique_id or 0) +function public.item(item_id, suffix_id) + local itemstring = 'item:'..(item_id or 0)..':0:'..(suffix_id or 0)..':0' local name, itemstring, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring) return name and { - itemstring = itemstring, name = name, - texture = texture, + itemstring = itemstring, quality = quality, level = level, - slot = slot, class = class, subclass = subclass, + slot = slot, max_stack = max_stack, - } + texture = texture, + } or Aux.cache.item_info(item_id) end \ No newline at end of file diff --git a/item_cache.lua b/item_cache.lua deleted file mode 100644 index cca4a13..0000000 --- a/item_cache.lua +++ /dev/null @@ -1,68 +0,0 @@ -local private, public = {}, {} -Aux.item_cache = public - -local MIN_ITEM_ID, MAX_ITEM_ID = 1, 30000 - -aux_items = {} -aux_auctionable_items = {} - -function public.on_load() - private.find_auctionable_items() -end - -function public.item_id(item_name) - return aux_items[strlower(item_name)] -end - -function private.find_auctionable_items() - - local function helper(item_id) - local processed = 0 - while processed <= 100 and item_id <= MAX_ITEM_ID do - local itemstring = 'item:'..item_id - local name, _, quality = GetItemInfo(itemstring) - name = name and strlower(name) - if name and not aux_items[name] then - aux_items[name] = item_id - local tooltip = Aux.info.tooltip(function(tt) tt:SetHyperlink(itemstring) end) - if Aux.info.auctionable(tooltip, quality) then - tinsert(aux_auctionable_items, name) - end - processed = processed + 1 - end - item_id = item_id + 1 - end - - if item_id <= MAX_ITEM_ID then - local t0 = GetTime() - Aux.control.as_soon_as(function() return GetTime() - t0 > 0.1 end, function() - return helper(item_id) - end) - else - sort(aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end) - end - end - - helper(MIN_ITEM_ID) -end - -function public.populate_wdb() - - local function helper(item_id) - if item_id > MAX_ITEM_ID then - Aux.log('Cache populated.') - return - end - - if not GetItemInfo('item:'..item_id) then - Aux.log('Fetching item '..item_id..'.') - AuxTooltip:SetHyperlink('item:'..item_id) - end - - Aux.control.on_next_update(function() - return helper(item_id + 1) - end) - end - - helper(MIN_ITEM_ID) -end \ No newline at end of file diff --git a/merchant.lua b/merchant.lua deleted file mode 100644 index 28c619d..0000000 --- a/merchant.lua +++ /dev/null @@ -1,63 +0,0 @@ -local private, public = {}, {} -Aux.merchant = public - -aux_merchant_buy, aux_merchant_sell = {}, {} - -function public.on_load() - Aux.control.event_listener('MERCHANT_SHOW', private.scan_merchant).start() -end - -function public.info(item_id) - local unit_price, limited - if aux_merchant_buy[item_id] then - local buy_fields = Aux.util.split(aux_merchant_buy[item_id], '#') - unit_price, limited = tonumber(buy_fields[1]), not not tonumber(buy_fields[2]) - end - - return aux_merchant_sell[item_id], unit_price, limited -end - --- TODO hook GetAuctionSellItemInfo() - -function private.scan_merchant() - Aux.util.loop_inventory(function(bag, slot) - local item_info = Aux.info.container_item(bag, slot) - if item_info then - aux_merchant_sell[item_info.item_id] = item_info.tooltip.money / item_info.aux_quantity - end - end) - --- TODO maybe more detail? zone or local merchant_name = UnitName('npc') - local merchant_item_count = GetMerchantNumItems() - for i=1,merchant_item_count do - local link = GetMerchantItemLink(i) - if link then - local item_id = Aux.info.parse_hyperlink(link) - local _, _, price, count, stock = GetMerchantItemInfo(i) - local new_unit_price, new_limited = price / count, Aux.persistence.blizzard_boolean(stock >= 0) - if aux_merchant_buy[item_id] then - local fields = Aux.util.split(aux_merchant_buy[item_id], '#') - local old_unit_price, old_limited = tonumber(fields[1]), tonumber(fields[2]) - - local unit_price - if old_limited and not new_limited then - unit_price = new_unit_price - elseif new_limited and not old_limited then - unit_price = old_unit_price - else - unit_price = min(old_unit_price, new_unit_price) - end - - aux_merchant_buy[item_id] = Aux.util.join({ - unit_price, - tostring(old_limited or new_limited), - }, '#') - else - aux_merchant_buy[item_id] = Aux.util.join({ - new_unit_price, - tostring(new_limited), - }, '#') - end - end - end -end \ No newline at end of file diff --git a/scan_util.lua b/scan_util.lua index 7190691..ce52d76 100644 --- a/scan_util.lua +++ b/scan_util.lua @@ -277,7 +277,7 @@ m.filters = { amount = Aux.money.from_string(amount or '') or 0 if amount > 0 then return function(auction_record) - local vendor_price = Aux.merchant.info(auction_record.item_id) + local vendor_price = Aux.cache.merchant_info(auction_record.item_id) return vendor_price and vendor_price * auction_record.aux_quantity - auction_record.bid_price >= amount end else @@ -292,7 +292,7 @@ m.filters = { amount = Aux.money.from_string(amount or '') or 0 if amount > 0 then return function(auction_record) - local vendor_price = Aux.merchant.info(auction_record.item_id) + local vendor_price = Aux.cache.merchant_info(auction_record.item_id) return auction_record.buyout_price > 0 and vendor_price and vendor_price * auction_record.aux_quantity - auction_record.buyout_price >= amount end else @@ -559,7 +559,7 @@ function m.filter_from_string(filter_term) then return false, {}, 'Erroneous Exact Only Modifier' else - prettified:prepend(Aux.info.display_name(Aux.item_cache.item_id(blizzard_filter.name)) or Aux.gui.inline_color({216, 225, 211, 1})..'['..blizzard_filter.name..']|r') + prettified:prepend(Aux.info.display_name(Aux.cache.item_id(blizzard_filter.name)) or Aux.gui.inline_color({216, 225, 211, 1})..'['..blizzard_filter.name..']|r') end elseif blizzard_filter.name then if blizzard_filter.name == '' then @@ -648,7 +648,7 @@ function m.blizzard_query(filter) local item_info, class_index, subclass_index, slot_index if filter.exact then - local item_id = Aux.item_cache.item_id(filter.name) + local item_id = Aux.cache.item_id(filter.name) item_info = Aux.info.item(item_id) class_index = item_info and Aux.item_class_index(item_info.class) subclass_index = class_index and item_info.subclass and Aux.item_subclass_index(class_index, item_info.subclass) diff --git a/slash.lua b/slash.lua index 7657b95..15b68f6 100644 --- a/slash.lua +++ b/slash.lua @@ -17,10 +17,11 @@ function SlashCmdList.AUX(parameter) Aux.log('Merchant sell prices cleared.') elseif parameter == 'clear item cache' then aux_items = {} + aux_item_ids = {} aux_auctionable_items = {} Aux.log('Item cache cleared.') elseif parameter == 'populate wdb' then - Aux.item_cache.populate_wdb() + Aux.cache.populate_wdb() elseif parameter == 'tooltip daily' then aux_tooltip_daily = not aux_tooltip_daily Aux.log('Market value in tooltip '..(aux_tooltip_daily and 'enabled' or 'disabled')..'.') diff --git a/tooltip.lua b/tooltip.lua index 9502217..1b0e720 100644 --- a/tooltip.lua +++ b/tooltip.lua @@ -89,7 +89,7 @@ function private.extend_tooltip(tooltip, hyperlink, quantity) if aux_tooltip_vendor_buy then local color = {r=0.8, g=0.5, b=0.1} - local _, price, limited = Aux.merchant.info(item_id) + local _, price, limited = Aux.cache.merchant_info(item_id) if price then tooltip:AddLine('Vendor Buy '..(limited and '(limited): ' or ': ')..Aux.util.format_money(price), color.r, color.g, color.b) end @@ -97,7 +97,7 @@ function private.extend_tooltip(tooltip, hyperlink, quantity) if aux_tooltip_vendor_sell then local color = {r=0.8, g=0.5, b=0.1} - local price = Aux.merchant.info(item_id) + local price = Aux.cache.merchant_info(item_id) if price ~= 0 then tooltip:AddLine('Vendor Sell: '..(price and Aux.util.format_money(price) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b) end