diff --git a/README.md b/README.md index 9b78a01..34cc2da 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,12 @@ The most advanced auction house addOn for the 1.12 client with some features mor ## Slash Commands ### General +**/aux** (Lists the settings)
+**/aux scale _factor_** (Scales the aux GUI by _factor_)
**/aux ignore owner** (Disables waiting for owner names when scanning. Recommended)
**/aux post bid** (Adds a bid price listing to the post tab)
+**/aux crafting cost** (Toggles the crafting price information)
+**/aux post duration _hours_** (Sets the default auction duration to _2_/_8_/_24_ hours)
### Tooltip **/aux tooltip value**
**/aux tooltip daily**
diff --git a/aux-addon.lua b/aux-addon.lua index c2fb16a..1a93fbd 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -1,15 +1,7 @@ module 'aux' local T = require 'T' - -_G.aux_scale = 1 - -_G.aux = { - character = {}, - faction = {}, - realm = {}, - account = {}, -} +local post = require 'aux.tabs.post' M.print = T.vararg-function(arg) DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE .. ' ' .. join(map(arg, tostring), ' ')) @@ -53,41 +45,58 @@ do end) end -do - local cache = {} - function handle.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 handle.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 T.temp-T.set('character', 'faction', 'realm', 'account') do - local scope = scope - M[scope .. '_data'] = function(key, init) - if not cache[scope] then error('Cache for ' .. scope .. ' data not ready.', 2) end - cache[scope][key] = cache[scope][key] or {} - for k, v in init or T.empty do - if cache[scope][key][k] == nil then - cache[scope][key][k] = v - end - end - return cache[scope][key] - end - end +function handle.LOAD() + _G.aux = aux or {} + assign(aux, { + account = {}, + realm = {}, + faction = {}, + character = {}, + }) + M.account_data = assign(aux.account, { + scale = 1, + ignore_owner = true, + crafting_cost = true, + post_bid = false, + post_duration = post.DURATION_8, + }) + do + local key = format('%s|%s', GetCVar'realmName', UnitName'player') + aux.character[key] = aux.character[key] or {} + M.character_data = assign(aux.character[key], { + tooltip = { + value = true, + merchant_sell = false, + merchant_buy = false, + daily = false, + disenchant_value = false, + disenchant_distribution = false, + } + }) + end + do + local key = GetCVar'realmName' + aux.realm[key] = aux.realm[key] or {} + M.realm_data = assign(aux.realm[key], { + characters = {}, + recent_searches = {}, + favorite_searches = {}, + }) + end +end + +function handle.LOAD2() + local key = format('%s|%s', GetCVar'realmName', UnitFactionGroup'player') + aux.faction[key] = aux.faction[key] or {} + M.faction_data = assign(aux.faction[key], { + history = {}, + post = {}, + items = {}, + item_ids = {}, + auctionable_items = {}, + merchant_buy = {}, + merchant_sell = {}, + }) end tab_info = {} @@ -177,7 +186,7 @@ do end function handle.LOAD2() - frame:SetScale(aux_scale) + frame:SetScale(account_data.scale) end function AUCTION_HOUSE_SHOW() diff --git a/aux-addon.toc b/aux-addon.toc index 85f643e..82b078a 100644 --- a/aux-addon.toc +++ b/aux-addon.toc @@ -2,7 +2,7 @@ ## Author: shirsig ## Title: aux ## Notes: Auction House replacement -## SavedVariables: aux, aux_scale, aux_post_bid, aux_ignore_owner, aux_crafting_cost, aux_items, aux_item_ids, aux_auctionable_items, aux_merchant_buy, aux_merchant_sell +## SavedVariables: aux libs\package.lua libs\T.lua diff --git a/core/cache.lua b/core/cache.lua index ee2af63..563045c 100644 --- a/core/cache.lua +++ b/core/cache.lua @@ -10,12 +10,6 @@ local MAX_ITEM_ID = 30000 local items_schema = {'tuple', '#', {name='string'}, {quality='number'}, {level='number'}, {class='string'}, {subclass='string'}, {slot='string'}, {max_stack='number'}, {texture='string'}} local merchant_buy_schema = {'tuple', '#', {unit_price='number'}, {limited='boolean'}} -_G.aux_items = {} -_G.aux_item_ids = {} -_G.aux_auctionable_items = {} -_G.aux_merchant_buy = {} -_G.aux_merchant_sell = {} - function aux.handle.LOAD() scan_wdb() @@ -31,19 +25,19 @@ function aux.handle.LOAD() if data then local item_id = item_id(data.name) if item_id then - aux_merchant_sell[item_id] = data.vendor_price / (max_item_charges(item_id) or data.count) + aux.account_data.merchant_sell[item_id] = data.vendor_price / (max_item_charges(item_id) or data.count) end end end) end do - local characters = T.empty + local characters = {} function M.is_player(name) return not not characters[name] end - function aux.handle.LOAD2() - characters = aux.realm_data'characters' + function aux.handle.LOAD() + characters = aux.realm_data.characters for k, v in characters do if GetTime() > v + 60 * 60 * 24 * 30 then characters[k] = nil @@ -92,14 +86,14 @@ end function M.merchant_info(item_id) local buy_info - if aux_merchant_buy[item_id] then - buy_info = persistence.read(merchant_buy_schema, aux_merchant_buy[item_id]) + if aux.account_data.merchant_buy[item_id] then + buy_info = persistence.read(merchant_buy_schema, aux.account_data.merchant_buy[item_id]) end - return aux_merchant_sell[item_id], buy_info and buy_info.unit_price, buy_info and buy_info.limited + return aux.account_data.merchant_sell[item_id], buy_info and buy_info.unit_price, buy_info and buy_info.limited end function M.item_info(item_id) - local data_string = aux_items[item_id] + local data_string = aux.account_data.items[item_id] if data_string then local cached_data = persistence.read(items_schema, data_string) return T.map( @@ -117,7 +111,7 @@ function M.item_info(item_id) end function M.item_id(item_name) - return aux_item_ids[strlower(item_name)] + return aux.account_data.item_ids[strlower(item_name)] end function merchant_buy_scan() @@ -128,8 +122,8 @@ function merchant_buy_scan() if link then local item_id = parse_link(link) local new_unit_price, new_limited = price / count, stock >= 0 - if aux_merchant_buy[item_id] then - local buy_info = persistence.read(merchant_buy_schema, aux_merchant_buy[item_id]) + if aux.account_data.merchant_buy[item_id] then + local buy_info = persistence.read(merchant_buy_schema, aux.account_data.merchant_buy[item_id]) local unit_price if buy_info.limited and not new_limited then @@ -140,12 +134,12 @@ function merchant_buy_scan() unit_price = min(buy_info.unit_price, new_unit_price) end - aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, T.temp-T.map( + aux.account_data.merchant_buy[item_id] = persistence.write(merchant_buy_schema, T.temp-T.map( 'unit_price', unit_price, 'limited', buy_info.limited and new_limited )) else - aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, T.temp-T.map( + aux.account_data.merchant_buy[item_id] = persistence.write(merchant_buy_schema, T.temp-T.map( 'unit_price', new_unit_price, 'limited', new_limited )) @@ -163,7 +157,7 @@ function merchant_sell_scan() T.temp(slot) local item_info = T.temp-container_item(unpack(slot)) if item_info then - aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity + aux.account_data.merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity end end end @@ -175,9 +169,9 @@ function scan_wdb(item_id) 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) - if name and not aux_item_ids[strlower(name)] then - aux_item_ids[strlower(name)] = item_id - aux_items[item_id] = persistence.write(items_schema, T.temp-T.map( + if name and not aux.account_data.item_ids[strlower(name)] then + aux.account_data.item_ids[strlower(name)] = item_id + aux.account_data.items[item_id] = persistence.write(items_schema, T.temp-T.map( 'name', name, 'quality', quality, 'level', level, @@ -189,7 +183,7 @@ function scan_wdb(item_id) )) local tooltip = tooltip('link', itemstring) if auctionable(tooltip, quality) then - tinsert(aux_auctionable_items, strlower(name)) + tinsert(aux.account_data.auctionable_items, strlower(name)) end processed = processed + 1 end @@ -199,7 +193,7 @@ function scan_wdb(item_id) if item_id <= MAX_ITEM_ID then aux.thread(aux.when, aux.later(.5), scan_wdb, item_id) else - sort(aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end) + sort(aux.account_data.auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end) end end diff --git a/core/crafting.lua b/core/crafting.lua index 74cdeab..b00df11 100644 --- a/core/crafting.lua +++ b/core/crafting.lua @@ -8,7 +8,7 @@ local history = require 'aux.core.history' local search_tab = require 'aux.tabs.search' function aux.handle.LOAD() - if not aux_crafting_cost then + if not aux.account_data.crafting_cost then return end aux.event_listener('ADDON_LOADED', function() diff --git a/core/history.lua b/core/history.lua index e7b6649..140c77b 100644 --- a/core/history.lua +++ b/core/history.lua @@ -10,7 +10,7 @@ local history_schema = {'tuple', '#', {next_push='number'}, {daily_min_buyout='n local value_cache = {} function aux.handle.LOAD2() - data = aux.faction_data'history' + data = aux.faction_data.history end do diff --git a/core/scan.lua b/core/scan.lua index 23c1a6f..bab9f1a 100644 --- a/core/scan.lua +++ b/core/scan.lua @@ -139,7 +139,7 @@ function scan_page(i) end local auction_info = info.auction(i, get_state().params.type) - if auction_info and (auction_info.owner or get_state().params.ignore_owner or aux_ignore_owner) then + if auction_info and (auction_info.owner or get_state().params.ignore_owner or aux.account_data.ignore_owner) then auction_info.index = i auction_info.page = get_state().page auction_info.blizzard_query = get_query().blizzard_query @@ -198,7 +198,7 @@ function wait_for_list_results() updated = true end) local timeout = aux.later(5, get_state().last_list_query) - local ignore_owner = get_state().params.ignore_owner or aux_ignore_owner + local ignore_owner = get_state().params.ignore_owner or aux.account_data.ignore_owner return aux.when(function() if not last_update and timeout() then return true diff --git a/core/slash.lua b/core/slash.lua index 4574b90..5adb2f9 100644 --- a/core/slash.lua +++ b/core/slash.lua @@ -1,14 +1,9 @@ module 'aux.core.slash' +local T = require 'T' local aux = require 'aux' local info = require 'aux.util.info' - -function aux.handle.LOAD2() - tooltip_settings = aux.character_data'tooltip' -end - -_G.aux_ignore_owner = true -_G.aux_crafting_cost = true +local post = require 'aux.tabs.post' function status(enabled) return (enabled and aux.color.green'on' or aux.color.red'off') @@ -18,20 +13,23 @@ _G.SLASH_AUX1 = '/aux' function SlashCmdList.AUX(command) if not command then return end local arguments = aux.tokenize(command) - + local tooltip_settings = aux.character_data.tooltip if arguments[1] == 'scale' and tonumber(arguments[2]) then local scale = tonumber(arguments[2]) aux.frame:SetScale(scale) - _G.aux_scale = scale + aux.account_data.scale = scale elseif arguments[1] == 'ignore' and arguments[2] == 'owner' then - _G.aux_ignore_owner = not aux_ignore_owner - aux.print('ignore owner ' .. status(aux_ignore_owner)) + aux.account_data.ignore_owner = not aux.account_data.ignore_owner + aux.print('ignore owner ' .. status(aux.account_data.ignore_owner)) elseif arguments[1] == 'post' and arguments[2] == 'bid' then - _G.aux_post_bid = not aux_post_bid - aux.print('post bid ' .. status(aux_post_bid)) - elseif arguments[1] == 'crafting' and arguments[2] == 'cost' then - _G.aux_crafting_cost = not aux_crafting_cost - aux.print('crafting cost ' .. status(aux_crafting_cost)) + aux.account_data.post_bid = not aux.account_data.post_bid + aux.print('post bid ' .. status(aux.account_data.post_bid)) + elseif arguments[1] == 'post' and arguments[2] == 'duration' and T.map('2', post.DURATION_2, '8', post.DURATION_8, '24', post.DURATION_24)[arguments[3]] then + aux.account_data.post_duration = T.map('2', post.DURATION_2, '8', post.DURATION_8, '24', post.DURATION_24)[arguments[3]] + aux.print('post duration ' .. aux.color.blue(aux.account_data.post_duration / 60 .. 'h')) + elseif arguments[1] == 'crafting' and arguments[2] == 'cost' then + aux.account_data.crafting_cost = not aux.account_data.crafting_cost + aux.print('crafting cost ' .. status(aux.account_data.crafting_cost)) elseif arguments[1] == 'tooltip' and arguments[2] == 'value' then tooltip_settings.value = not tooltip_settings.value aux.print('tooltip value ' .. status(tooltip_settings.value)) @@ -51,18 +49,19 @@ function SlashCmdList.AUX(command) tooltip_settings.disenchant_distribution = not tooltip_settings.disenchant_distribution aux.print('tooltip disenchant distribution ' .. status(tooltip_settings.disenchant_distribution)) elseif arguments[1] == 'clear' and arguments[2] == 'item' and arguments[3] == 'cache' then - _G.aux_items = {} - _G.aux_item_ids = {} - _G.aux_auctionable_items = {} + aux.account_data.items = {} + aux.account_data.item_ids = {} + aux.account_data.auctionable_items = {} aux.print('Item cache cleared.') elseif arguments[1] == 'populate' and arguments[2] == 'wdb' then info.populate_wdb() else aux.print('Usage:') - aux.print('- scale [' .. aux.color.blue(aux_scale) .. ']') - aux.print('- ignore owner [' .. status(aux_ignore_owner) .. ']') - aux.print('- post bid [' .. status(aux_post_bid) .. ']') - aux.print('- crafting cost [' .. status(aux_crafting_cost) .. ']') + aux.print('- scale [' .. aux.color.blue(aux.account_data.scale) .. ']') + aux.print('- ignore owner [' .. status(aux.account_data.ignore_owner) .. ']') + aux.print('- post bid [' .. status(aux.account_data.post_bid) .. ']') + aux.print('- post duration [' .. aux.color.blue(aux.account_data.post_duration / 60 .. 'h') .. ']') + aux.print('- crafting cost [' .. status(aux.account_data.crafting_cost) .. ']') aux.print('- tooltip value [' .. status(tooltip_settings.value) .. ']') aux.print('- tooltip daily [' .. status(tooltip_settings.daily) .. ']') aux.print('- tooltip merchant buy [' .. status(tooltip_settings.merchant_buy) .. ']') diff --git a/core/tooltip.lua b/core/tooltip.lua index 766074f..c43365b 100644 --- a/core/tooltip.lua +++ b/core/tooltip.lua @@ -13,7 +13,7 @@ local UNKNOWN = GRAY_FONT_COLOR_CODE .. '?' .. FONT_COLOR_CODE_CLOSE local game_tooltip_hooks, game_tooltip_money = {}, 0 function aux.handle.LOAD() - settings = aux.character_data('tooltip', {value=true}) + settings = aux.character_data.tooltip do local inside_hook = false for name, f in game_tooltip_hooks do diff --git a/libs/package.lua b/libs/package.lua index 6664fe5..1339a82 100644 --- a/libs/package.lua +++ b/libs/package.lua @@ -30,5 +30,8 @@ function module(name) end function require(name) + if not interfaces[name] then + create_module(name) + end return interfaces[name] end \ No newline at end of file diff --git a/tabs/post/core.lua b/tabs/post/core.lua index 311ad00..d749c5b 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -16,21 +16,22 @@ local gui = require 'aux.gui' local tab = aux.tab 'Post' -local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440 local settings_schema = {'tuple', '#', {duration='number'}, {start_price='number'}, {buyout_price='number'}, {hidden='boolean'}} local scan_id, inventory_records, bid_records, buyout_records = 0, {}, {}, {} +M.DURATION_2, M.DURATION_8, M.DURATION_24 = 120, 480, 1440 + refresh = true selected_item = nil function get_default_settings() - return T.map('duration', DURATION_8, 'start_price', 0, 'buyout_price', 0, 'hidden', false) + return T.map('duration', aux.account_data.post_duration, 'start_price', 0, 'buyout_price', 0, 'hidden', false) end function aux.handle.LOAD2() - data = aux.faction_data'post' + data = aux.faction_data.post end function read_settings(item_key) @@ -206,7 +207,7 @@ function post_auctions() local key = selected_item.key local duration_code - if duration == DURATION_4 then + if duration == DURATION_2 then duration_code = 2 elseif duration == DURATION_8 then duration_code = 3 @@ -543,7 +544,7 @@ function initialize_duration_dropdown() end UIDropDownMenu_AddButton{ text = '2 Hours', - value = DURATION_4, + value = DURATION_2, func = on_click, } UIDropDownMenu_AddButton{ diff --git a/tabs/post/frame.lua b/tabs/post/frame.lua index 5ece704..60bebbf 100644 --- a/tabs/post/frame.lua +++ b/tabs/post/frame.lua @@ -312,7 +312,7 @@ do end function aux.handle.LOAD() - if not aux_post_bid then + if not aux.account_data.post_bid then frame.bid_listing:Hide() frame.buyout_listing:SetPoint('BOTTOMLEFT', frame.inventory, 'BOTTOMRIGHT', 2.5, 0) buyout_listing:SetColInfo{ diff --git a/tabs/search/frame.lua b/tabs/search/frame.lua index 75a9ee7..d319b09 100644 --- a/tabs/search/frame.lua +++ b/tabs/search/frame.lua @@ -268,7 +268,7 @@ do end do local editbox = gui.editbox(frame.filter) - editbox.complete_item = completion.complete(function() return aux_auctionable_items end) + editbox.complete_item = completion.complete(function() return aux.account_data.auctionable_items end) editbox:SetPoint('TOPLEFT', 14, -FILTER_SPACING) editbox:SetWidth(260) editbox.char = function() diff --git a/tabs/search/saved.lua b/tabs/search/saved.lua index 136ecb3..b2043a0 100644 --- a/tabs/search/saved.lua +++ b/tabs/search/saved.lua @@ -5,8 +5,8 @@ local aux = require 'aux' local filter_util = require 'aux.util.filter' local gui = require 'aux.gui' -function aux.handle.LOAD2() - recent_searches, favorite_searches = aux.realm_data'recent_searches', aux.realm_data'favorite_searches' +function aux.handle.LOAD() + recent_searches, favorite_searches = aux.realm_data.recent_searches, aux.realm_data.favorite_searches end function update_search_listings() diff --git a/util.lua b/util.lua index b59c814..9de2094 100644 --- a/util.lua +++ b/util.lua @@ -10,6 +10,15 @@ M.immutable = setmetatable(T.acquire(), { end }) +function M.assign(t1, t2) + for k, v in t2 do + if t1[k] == nil then + t1[k] = v + end + end + return t1 +end + function M.enum(n) if n > 0 then return immutable-{}, enum(n - 1) end end diff --git a/util/filter.lua b/util/filter.lua index a7f5283..f37c4db 100644 --- a/util/filter.lua +++ b/util/filter.lua @@ -282,7 +282,7 @@ function M.parse_filter_string(str) if input_type ~= '' then if not parts[i + 1] or not parse_parameter(input_type, parts[i + 1]) then if parts[i] == 'item' then - return nil, 'Invalid item name', aux_auctionable_items + return nil, 'Invalid item name', aux.account_data.auctionable_items elseif type(input_type) == 'table' then return nil, 'Invalid choice for ' .. parts[i], input_type else @@ -399,7 +399,7 @@ function suggestions(filter) -- item names if getn(filter.components) == 0 then - for _, name in ipairs(aux_auctionable_items) do + for _, name in ipairs(aux.account_data.auctionable_items) do tinsert(suggestions, name .. '/exact') end end diff --git a/util/info.lua b/util/info.lua index 16f39cb..76693dc 100644 --- a/util/info.lua +++ b/util/info.lua @@ -124,8 +124,8 @@ function M.auction(index, query_type) 'link', link, 'itemstring', item_info.itemstring, 'item_key', item_id .. ':' .. suffix_id, - 'search_signature', aux.join(T.temp-T.list(item_id, suffix_id, enchant_id, start_price, buyout_price, bid_price, aux_quantity, duration, query_type == 'owner' and high_bidder or (high_bidder and 1 or 0), aux_ignore_owner and (is_player(owner) and 0 or 1) or (owner or '?')), ':'), - 'sniping_signature', aux.join(T.temp-T.list(item_id, suffix_id, enchant_id, start_price, buyout_price, aux_quantity, aux_ignore_owner and (is_player(owner) and 0 or 1) or (owner or '?')), ':'), + 'search_signature', aux.join(T.temp-T.list(item_id, suffix_id, enchant_id, start_price, buyout_price, bid_price, aux_quantity, duration, query_type == 'owner' and high_bidder or (high_bidder and 1 or 0), aux.account_data.ignore_owner and (is_player(owner) and 0 or 1) or (owner or '?')), ':'), + 'sniping_signature', aux.join(T.temp-T.list(item_id, suffix_id, enchant_id, start_price, buyout_price, aux_quantity, aux.account_data.ignore_owner and (is_player(owner) and 0 or 1) or (owner or '?')), ':'), 'name', name, 'texture', texture, @@ -169,7 +169,7 @@ function M.bid_update(auction_record) auction_record.unit_blizzard_bid = auction_record.blizzard_bid / auction_record.aux_quantity auction_record.unit_bid_price = auction_record.bid_price / auction_record.aux_quantity auction_record.high_bidder = 1 - auction_record.search_signature = aux.join(T.temp-T.list(auction_record.item_id, auction_record.suffix_id, auction_record.enchant_id, auction_record.start_price, auction_record.buyout_price, auction_record.bid_price, auction_record.aux_quantity, auction_record.duration, 1, aux_ignore_owner and (is_player(auction_record.owner) and 0 or 1) or (auction_record.owner or '?')), ':') + auction_record.search_signature = aux.join(T.temp-T.list(auction_record.item_id, auction_record.suffix_id, auction_record.enchant_id, auction_record.start_price, auction_record.buyout_price, auction_record.bid_price, auction_record.aux_quantity, auction_record.duration, 1, aux.account_data.ignore_owner and (is_player(auction_record.owner) and 0 or 1) or (auction_record.owner or '?')), ':') end function M.set_tooltip(itemstring, owner, anchor)