refactoring
This commit is contained in:
+2
-2
@@ -5,7 +5,7 @@ include 'aux'
|
||||
|
||||
local filter_util = require 'aux.util.filter'
|
||||
|
||||
function public:complete_filter()
|
||||
function M:complete_filter()
|
||||
if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution
|
||||
return
|
||||
end
|
||||
@@ -27,7 +27,7 @@ function public:complete_filter()
|
||||
end
|
||||
end
|
||||
|
||||
function public.complete(options)
|
||||
function M.complete(options)
|
||||
return function(self)
|
||||
if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution
|
||||
return
|
||||
|
||||
+8
-8
@@ -23,7 +23,7 @@ function default_filter(str)
|
||||
}
|
||||
end
|
||||
|
||||
public.filters = {
|
||||
M.filters = {
|
||||
|
||||
['utilizable'] = {
|
||||
input_type = '',
|
||||
@@ -283,7 +283,7 @@ function parse_parameter(input_type, str)
|
||||
end
|
||||
end
|
||||
|
||||
function public.parse_filter_string(str)
|
||||
function M.parse_filter_string(str)
|
||||
local filter, post_filter = t, t
|
||||
local blizzard_filter_parser = blizzard_filter_parser()
|
||||
|
||||
@@ -330,7 +330,7 @@ function public.parse_filter_string(str)
|
||||
return T('components', filter, 'blizzard', blizzard_filter_parser(), 'post', post_filter)
|
||||
end
|
||||
|
||||
function public.query(filter_string)
|
||||
function M.query(filter_string)
|
||||
local filter, error, suggestions = parse_filter_string(filter_string)
|
||||
|
||||
if not filter then
|
||||
@@ -365,7 +365,7 @@ function public.query(filter_string)
|
||||
}, _M.suggestions(filter)
|
||||
end
|
||||
|
||||
function public.queries(filter_string)
|
||||
function M.queries(filter_string)
|
||||
local parts = split(filter_string, ';')
|
||||
local queries = t
|
||||
for _, str in parts do
|
||||
@@ -426,7 +426,7 @@ function suggestions(filter)
|
||||
return suggestions
|
||||
end
|
||||
|
||||
function public.filter_string(components)
|
||||
function M.filter_string(components)
|
||||
local query_builder = query_builder()
|
||||
|
||||
for _, component in components do
|
||||
@@ -488,11 +488,11 @@ function prettified_filter_string(filter)
|
||||
end
|
||||
end
|
||||
|
||||
function public.quote(name)
|
||||
function M.quote(name)
|
||||
return '<' .. name .. '>'
|
||||
end
|
||||
|
||||
function public.unquote(name)
|
||||
function M.unquote(name)
|
||||
return select(3, strfind(name, '^<(.*)>$')) or name
|
||||
end
|
||||
|
||||
@@ -562,7 +562,7 @@ function validator(filter)
|
||||
end
|
||||
end
|
||||
|
||||
function public.query_builder()
|
||||
function M.query_builder()
|
||||
local filter
|
||||
return T(
|
||||
'append', function(part)
|
||||
|
||||
+25
-25
@@ -37,12 +37,12 @@ do
|
||||
INVTYPE_RANGEDRIGHT = {18},
|
||||
INVTYPE_TABARD = {19},
|
||||
}
|
||||
function public.inventory_index(slot)
|
||||
function M.inventory_index(slot)
|
||||
return unpack(inventory_index_map[slot] or tt)
|
||||
end
|
||||
end
|
||||
|
||||
function public.container_item(bag, slot)
|
||||
function M.container_item(bag, slot)
|
||||
for link in present(GetContainerItemLink(bag, slot)) do
|
||||
|
||||
local item_id, suffix_id, unique_id, enchant_id = parse_link(link)
|
||||
@@ -86,7 +86,7 @@ function public.container_item(bag, slot)
|
||||
end
|
||||
end
|
||||
|
||||
function public.auction_sell_item()
|
||||
function M.auction_sell_item()
|
||||
for name, texture, count, quality, usable, vendor_price in GetAuctionSellItemInfo do
|
||||
return T(
|
||||
'name', name,
|
||||
@@ -99,7 +99,7 @@ function public.auction_sell_item()
|
||||
end
|
||||
end
|
||||
|
||||
function public.auction(index, query_type)
|
||||
function M.auction(index, query_type)
|
||||
query_type = query_type or 'list'
|
||||
|
||||
for link in present(GetAuctionItemLink(query_type, index)) do
|
||||
@@ -162,7 +162,7 @@ function public.auction(index, query_type)
|
||||
end
|
||||
end
|
||||
|
||||
function public.bid_update(auction_record)
|
||||
function M.bid_update(auction_record)
|
||||
auction_record.high_bid = auction_record.bid_price
|
||||
auction_record.blizzard_bid = auction_record.bid_price
|
||||
auction_record.min_increment = min_bid_increment(auction_record.bid_price)
|
||||
@@ -173,12 +173,12 @@ function public.bid_update(auction_record)
|
||||
auction_record.search_signature = join(temp-A(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 '?')), ':')
|
||||
end
|
||||
|
||||
function public.set_tooltip(itemstring, owner, anchor)
|
||||
function M.set_tooltip(itemstring, owner, anchor)
|
||||
GameTooltip:SetOwner(owner, anchor)
|
||||
GameTooltip:SetHyperlink(itemstring)
|
||||
end
|
||||
|
||||
function public.set_shopping_tooltip(slot)
|
||||
function M.set_shopping_tooltip(slot)
|
||||
local index1, index2 = inventory_index(slot)
|
||||
local tooltips = tt
|
||||
if index1 then
|
||||
@@ -211,7 +211,7 @@ function public.set_shopping_tooltip(slot)
|
||||
end
|
||||
end
|
||||
|
||||
function public.tooltip_match(entry, tooltip)
|
||||
function M.tooltip_match(entry, tooltip)
|
||||
return any(tooltip, function(line)
|
||||
local left_match = line.left_text and strupper(line.left_text) == strupper(entry)
|
||||
local right_match = line.right_text and strupper(line.right_text) == strupper(entry)
|
||||
@@ -219,7 +219,7 @@ function public.tooltip_match(entry, tooltip)
|
||||
end)
|
||||
end
|
||||
|
||||
function public.tooltip_find(pattern, tooltip)
|
||||
function M.tooltip_find(pattern, tooltip)
|
||||
local count = 0
|
||||
for _, line in tooltip do
|
||||
if line.left_text and strfind(line.left_text, pattern) then
|
||||
@@ -232,7 +232,7 @@ function public.tooltip_find(pattern, tooltip)
|
||||
return count
|
||||
end
|
||||
|
||||
function public.load_tooltip(frame, tooltip)
|
||||
function M.load_tooltip(frame, tooltip)
|
||||
frame:ClearLines()
|
||||
for _, line in tooltip do
|
||||
if line.right_text then
|
||||
@@ -247,7 +247,7 @@ function public.load_tooltip(frame, tooltip)
|
||||
end
|
||||
end
|
||||
|
||||
function public.display_name(item_id, no_brackets, no_color)
|
||||
function M.display_name(item_id, no_brackets, no_color)
|
||||
for item_info in present(item(item_id)) do
|
||||
local name = item_info.name
|
||||
if not no_brackets then
|
||||
@@ -260,7 +260,7 @@ function public.display_name(item_id, no_brackets, no_color)
|
||||
end
|
||||
end
|
||||
|
||||
function public.auctionable(tooltip, quality, lootable)
|
||||
function M.auctionable(tooltip, quality, lootable)
|
||||
local durability, max_durability = durability(tooltip)
|
||||
return not lootable
|
||||
and (not quality or quality < 6)
|
||||
@@ -271,7 +271,7 @@ function public.auctionable(tooltip, quality, lootable)
|
||||
and not (durability and durability < max_durability)
|
||||
end
|
||||
|
||||
function public.tooltip(setter)
|
||||
function M.tooltip(setter)
|
||||
AuxTooltip:SetOwner(UIParent, 'ANCHOR_NONE')
|
||||
AuxTooltip.money = 0
|
||||
setter(AuxTooltip)
|
||||
@@ -325,12 +325,12 @@ do
|
||||
|
||||
-- ... TODO
|
||||
}
|
||||
function public.max_item_charges(item_id)
|
||||
function M.max_item_charges(item_id)
|
||||
return data[item_id]
|
||||
end
|
||||
end
|
||||
|
||||
function public.durability(tooltip)
|
||||
function M.durability(tooltip)
|
||||
for _, line in tooltip do
|
||||
local pattern = '^' .. gsub(gsub(DURABILITY_TEMPLATE, '%%d', '(%%d+)'), '%%%d+%$d', '(%%d+)') .. '$'
|
||||
local _, _, left_durability_string, left_max_durability_string = strfind(line.left_text or '', pattern)
|
||||
@@ -343,21 +343,21 @@ function public.durability(tooltip)
|
||||
end
|
||||
end
|
||||
|
||||
function public.item_key(link)
|
||||
function M.item_key(link)
|
||||
local item_id, suffix_id = parse_link(link)
|
||||
return item_id .. ':' .. suffix_id
|
||||
end
|
||||
|
||||
function public.parse_link(link)
|
||||
function M.parse_link(link)
|
||||
local _, _, item_id, enchant_id, suffix_id, unique_id, name = strfind(link, '|c%x%x%x%x%x%x%x%x|Hitem:(%d*):(%d*):(%d*):(%d*)[:0-9]*|h%[(.-)%]|h|r')
|
||||
return tonumber(item_id) or 0, tonumber(suffix_id) or 0, tonumber(unique_id) or 0, tonumber(enchant_id) or 0, name
|
||||
end
|
||||
|
||||
function public.itemstring(item_id, suffix_id, unique_id, enchant_id)
|
||||
function M.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)
|
||||
function M.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 T(
|
||||
@@ -373,7 +373,7 @@ function public.item(item_id, suffix_id)
|
||||
) or cache.item_info(item_id)
|
||||
end
|
||||
|
||||
function public.item_class_index(item_class)
|
||||
function M.item_class_index(item_class)
|
||||
for i, class in temp-A(GetAuctionItemClasses()) do
|
||||
if strupper(class) == strupper(item_class) then
|
||||
return i, class
|
||||
@@ -381,7 +381,7 @@ function public.item_class_index(item_class)
|
||||
end
|
||||
end
|
||||
|
||||
function public.item_subclass_index(class_index, item_subclass)
|
||||
function M.item_subclass_index(class_index, item_subclass)
|
||||
for i, subclass in temp-A(GetAuctionItemSubClasses(class_index)) do
|
||||
if strupper(subclass) == strupper(item_subclass) then
|
||||
return i, subclass
|
||||
@@ -389,7 +389,7 @@ function public.item_subclass_index(class_index, item_subclass)
|
||||
end
|
||||
end
|
||||
|
||||
function public.item_slot_index(class_index, subclass_index, slot_name)
|
||||
function M.item_slot_index(class_index, subclass_index, slot_name)
|
||||
for i, slot in temp-A(GetAuctionInvTypes(class_index, subclass_index)) do
|
||||
if strupper(_G[slot]) == strupper(slot_name) then
|
||||
return i, _G[slot]
|
||||
@@ -397,7 +397,7 @@ function public.item_slot_index(class_index, subclass_index, slot_name)
|
||||
end
|
||||
end
|
||||
|
||||
function public.item_quality_index(item_quality)
|
||||
function M.item_quality_index(item_quality)
|
||||
for i = 0, 4 do
|
||||
local quality = _G['ITEM_QUALITY' .. i .. '_DESC']
|
||||
if strupper(item_quality) == strupper(quality) then
|
||||
@@ -406,7 +406,7 @@ function public.item_quality_index(item_quality)
|
||||
end
|
||||
end
|
||||
|
||||
function public.get_inventory()
|
||||
function M.get_inventory()
|
||||
local bag, slot = 0, 0
|
||||
return function()
|
||||
if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then
|
||||
@@ -419,7 +419,7 @@ function public.get_inventory()
|
||||
end
|
||||
end
|
||||
|
||||
function public.bag_type(bag)
|
||||
function M.bag_type(bag)
|
||||
if bag == 0 then return 1 end
|
||||
for link in present(GetInventoryItemLink('player', ContainerIDToInventoryID(bag))) do
|
||||
local item_id = parse_link(link)
|
||||
|
||||
+10
-10
@@ -3,25 +3,25 @@ module 'aux.util.money'
|
||||
include 'green_t'
|
||||
include 'aux'
|
||||
|
||||
public.GOLD_TEXT = '|cffffd70ag|r'
|
||||
public.SILVER_TEXT = '|cffc7c7cfs|r'
|
||||
public.COPPER_TEXT = '|cffeda55fc|r'
|
||||
M.GOLD_TEXT = '|cffffd70ag|r'
|
||||
M.SILVER_TEXT = '|cffc7c7cfs|r'
|
||||
M.COPPER_TEXT = '|cffeda55fc|r'
|
||||
|
||||
local COPPER_PER_GOLD = 10000
|
||||
local COPPER_PER_SILVER = 100
|
||||
|
||||
function public.to_gsc(money)
|
||||
function M.to_gsc(money)
|
||||
local gold = floor(money / COPPER_PER_GOLD)
|
||||
local silver = floor(mod(money, COPPER_PER_GOLD) / COPPER_PER_SILVER)
|
||||
local copper = mod(money, COPPER_PER_SILVER)
|
||||
return gold, silver, copper
|
||||
end
|
||||
|
||||
function public.from_gsc(gold, silver, copper)
|
||||
function M.from_gsc(gold, silver, copper)
|
||||
return gold * COPPER_PER_GOLD + silver * COPPER_PER_SILVER + copper
|
||||
end
|
||||
|
||||
function public.to_string2(money, exact, color)
|
||||
function M.to_string2(money, exact, color)
|
||||
color = color or FONT_COLOR_CODE_CLOSE
|
||||
|
||||
local TEXT_NONE = '0'
|
||||
@@ -59,12 +59,12 @@ function public.to_string2(money, exact, color)
|
||||
return str
|
||||
end
|
||||
|
||||
--function public.to_string(params) -- TODO
|
||||
--function M.to_string(params) -- TODO
|
||||
-- local gold, silver, copper = to_gsc(params.copper or 0 + )
|
||||
-- local settings = set(unpack(arg))
|
||||
--end
|
||||
|
||||
function public.to_string(money, pad, trim, decimal_points, color, no_color)
|
||||
function M.to_string(money, pad, trim, decimal_points, color, no_color)
|
||||
local is_negative = money < 0
|
||||
money = abs(money)
|
||||
local gold, silver, copper = to_gsc(money)
|
||||
@@ -115,7 +115,7 @@ function public.to_string(money, pad, trim, decimal_points, color, no_color)
|
||||
return text
|
||||
end
|
||||
|
||||
function public.from_string(value)
|
||||
function M.from_string(value)
|
||||
local number = tonumber(value)
|
||||
if number and number >= 0 then
|
||||
return number * COPPER_PER_GOLD
|
||||
@@ -139,7 +139,7 @@ function public.from_string(value)
|
||||
return from_gsc(gold or 0, silver or 0, copper or 0)
|
||||
end
|
||||
|
||||
function public.format_number(num, pad, decimal_padding, color)
|
||||
function M.format_number(num, pad, decimal_padding, color)
|
||||
local padding = pad and 2 + (decimal_padding and decimal_padding + 1 or 0) or 0
|
||||
num = format('%0' .. padding .. '.0' .. (decimal_padding or 0) .. 'f', num)
|
||||
if color then
|
||||
|
||||
@@ -7,7 +7,7 @@ _G.aux_datasets = t
|
||||
|
||||
do
|
||||
local dataset
|
||||
function public.get_dataset()
|
||||
function M.get_dataset()
|
||||
if not dataset then
|
||||
local dataset_key = format('%s|%s', GetCVar'realmName', UnitFactionGroup'player')
|
||||
dataset = aux_datasets[dataset_key] or t
|
||||
@@ -17,7 +17,7 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
function public.read(schema, str)
|
||||
function M.read(schema, str)
|
||||
if schema == 'string' then
|
||||
return str
|
||||
elseif schema == 'boolean' then
|
||||
@@ -33,7 +33,7 @@ function public.read(schema, str)
|
||||
end
|
||||
end
|
||||
|
||||
function public.write(schema, obj)
|
||||
function M.write(schema, obj)
|
||||
if schema == 'string' then
|
||||
return obj or ''
|
||||
elseif schema == 'boolean' then
|
||||
@@ -49,7 +49,7 @@ function public.write(schema, obj)
|
||||
end
|
||||
end
|
||||
|
||||
function public.read_list(schema, str)
|
||||
function M.read_list(schema, str)
|
||||
if str == '' then return t end
|
||||
local separator = schema[2]
|
||||
local element_type = schema[3]
|
||||
@@ -58,7 +58,7 @@ function public.read_list(schema, str)
|
||||
end)
|
||||
end
|
||||
|
||||
function public.write_list(schema, list)
|
||||
function M.write_list(schema, list)
|
||||
local separator = schema[2]
|
||||
local element_type = schema[3]
|
||||
local parts = map(copy(list), function(element)
|
||||
@@ -67,7 +67,7 @@ function public.write_list(schema, list)
|
||||
return join(parts, separator)
|
||||
end
|
||||
|
||||
function public.read_record(schema, str)
|
||||
function M.read_record(schema, str)
|
||||
local separator = schema[2]
|
||||
local record = t
|
||||
local parts = split(str, separator)
|
||||
@@ -78,7 +78,7 @@ function public.read_record(schema, str)
|
||||
return record
|
||||
end
|
||||
|
||||
function public.write_record(schema, record)
|
||||
function M.write_record(schema, record)
|
||||
local separator = schema[2]
|
||||
local parts = tt
|
||||
for i = 3 , getn(schema) do
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ local info = require 'aux.util.info'
|
||||
local filter_util = require 'aux.util.filter'
|
||||
local scan = require 'aux.core.scan'
|
||||
|
||||
function public.find(auction_record, status_bar, on_abort, on_failure, on_success)
|
||||
function M.find(auction_record, status_bar, on_abort, on_failure, on_success)
|
||||
|
||||
local function test(index)
|
||||
local auction_info = info.auction(index, auction_record.query_type)
|
||||
@@ -72,7 +72,7 @@ function public.find(auction_record, status_bar, on_abort, on_failure, on_succes
|
||||
}
|
||||
end
|
||||
|
||||
function public.item_query(item_id, first_page, last_page)
|
||||
function M.item_query(item_id, first_page, last_page)
|
||||
for item_info in present(info.item(item_id)) do
|
||||
local query = filter_util.query(item_info.name .. '/exact')
|
||||
query.blizzard_query.first_page = first_page
|
||||
|
||||
+5
-5
@@ -3,11 +3,11 @@ module 'aux.util.sort'
|
||||
include 'green_t'
|
||||
include 'aux'
|
||||
|
||||
public.EQ = 0
|
||||
public.LT = 1
|
||||
public.GT = 2
|
||||
M.EQ = 0
|
||||
M.LT = 1
|
||||
M.GT = 2
|
||||
|
||||
function public.compare(a, b, desc)
|
||||
function M.compare(a, b, desc)
|
||||
if a < b then
|
||||
return desc and GT or LT
|
||||
elseif a > b then
|
||||
@@ -17,7 +17,7 @@ function public.compare(a, b, desc)
|
||||
end
|
||||
end
|
||||
|
||||
public.multi_lt = vararg-function(arg)
|
||||
M.multi_lt = vararg-function(arg)
|
||||
for i = 1, getn(arg), 2 do
|
||||
if arg[i] and arg[i + 1] and arg[i] ~= arg[i + 1] then
|
||||
return arg[i] < arg[i + 1]
|
||||
|
||||
Reference in New Issue
Block a user