module refactoring

This commit is contained in:
Manuel Simon Hirsig
2017-11-25 17:53:39 +01:00
parent 6f71167e48
commit ab94acc2be
38 changed files with 402 additions and 453 deletions
+2 -3
View File
@@ -1,7 +1,6 @@
module 'aux.util.completion'
include 'aux'
local aux = require 'aux'
local filter_util = require 'aux.util.filter'
function M:complete_filter()
@@ -11,7 +10,7 @@ function M:complete_filter()
local filter_string = this:GetText()
local completed_filter_string = select(3, strfind(filter_string, '([^;]*)/[^/;]*$'))
local completed_filter_string = aux.select(3, strfind(filter_string, '([^;]*)/[^/;]*$'))
local _, suggestions = filter_util.query(completed_filter_string)
local start_index, _, current_modifier = strfind(filter_string, '([^/;]*)$')
+28 -30
View File
@@ -1,9 +1,7 @@
module 'aux.util.filter'
include 'aux'
local T = require 'T'
local aux = require 'aux'
local info = require 'aux.util.info'
local money = require 'aux.util.money'
local filter_util = require 'aux.util.filter'
@@ -15,7 +13,7 @@ function default_filter(str)
input_type = '',
validator = function()
return function(auction_record)
return any(auction_record.tooltip, function(entry)
return aux.any(auction_record.tooltip, function(entry)
return strfind(strlower(entry.left_text or ''), str, 1, true) or strfind(strlower(entry.right_text or ''), str, 1, true)
end)
end
@@ -186,7 +184,7 @@ M.filters = {
function operator(str)
local operator = str == 'not' and T.list('operator', 'not', 1)
for name in T.temp-T.set('and', 'or') do
local arity = select(3, strfind(str, '^' .. name .. '(%d*)$'))
local arity = aux.select(3, strfind(str, '^' .. name .. '(%d*)$'))
if arity then
arity = tonumber(arity)
operator = not (arity and arity < 2) and T.list('operator', name, arity)
@@ -203,7 +201,7 @@ do
return self
end
if self.exact then return end
local number = tonumber(select(3, strfind(str, '^(%d+)$')))
local number = tonumber(aux.select(3, strfind(str, '^(%d+)$')))
if number then
if number >= 1 and number <= 60 then
for _, key in ipairs(T.temp-T.list('min_level', 'max_level')) do
@@ -216,20 +214,20 @@ do
end
for _, parser in T.temp-T.list(
T.temp-T.list('class', info.item_class_index),
T.temp-T.list('subclass', T.vararg-function(arg) return info.item_subclass_index(index(self.class, 2) or 0, unpack(arg)) end),
T.temp-T.list('slot', T.vararg-function(arg) return info.item_slot_index(index(self.class, 2) == 2 and 2 or 0, index(self.subclass, 2) or 0, unpack(arg)) end),
T.temp-T.list('subclass', T.vararg-function(arg) return info.item_subclass_index(aux.index(self.class, 2) or 0, unpack(arg)) end),
T.temp-T.list('slot', T.vararg-function(arg) return info.item_slot_index(aux.index(self.class, 2) == 2 and 2 or 0, aux.index(self.subclass, 2) or 0, unpack(arg)) end),
T.temp-T.list('quality', info.item_quality_index)
) do
if not self[parser[1]] then
tinsert(parser, str)
local index, label = parser[2](select(3, unpack(parser)))
local index, label = parser[2](aux.select(3, unpack(parser)))
if index then
self[parser[1]] = T.list(label, index)
return T.list('blizzard', parser[1], label, index)
end
end
end
if not self[str] and (str == 'usable' or str == 'exact' and self.name and size(self) == 1) then
if not self[str] and (str == 'usable' or str == 'exact' and self.name and aux.size(self) == 1) then
self[str] = T.list(str, 1)
return T.list('blizzard', str, str, 1)
elseif i == 1 and strlen(str) <= 63 then
@@ -254,7 +252,7 @@ function parse_parameter(input_type, str)
elseif input_type == 'string' then
return str ~= '' and str or nil
elseif type(input_type) == 'table' then
return key(input_type, str)
return aux.key(input_type, str)
end
end
@@ -262,7 +260,7 @@ function M.parse_filter_string(str)
local filter, post_filter = T.acquire(), T.acquire()
local blizzard_filter_parser = blizzard_filter_parser()
local parts = str and map(split(str, '/'), function(part) return strlower(trim(part)) end) or T.acquire()
local parts = str and aux.map(aux.split(str, '/'), function(part) return strlower(aux.trim(part)) end) or T.acquire()
local i = 1
while parts[i] do
@@ -341,7 +339,7 @@ function M.query(filter_string)
end
function M.queries(filter_string)
local parts = split(filter_string, ';')
local parts = aux.split(filter_string, ';')
local queries = T.acquire()
for _, str in ipairs(parts) do
local query, _, error = query(str)
@@ -357,7 +355,7 @@ end
function suggestions(filter)
local suggestions = T.acquire()
if filter.blizzard.name and size(filter.blizzard) == 1 then tinsert(suggestions, 'exact') end
if filter.blizzard.name and aux.size(filter.blizzard) == 1 then tinsert(suggestions, 'exact') end
tinsert(suggestions, 'and'); tinsert(suggestions, 'or'); tinsert(suggestions, 'not'); tinsert(suggestions, 'tooltip')
@@ -370,14 +368,14 @@ function suggestions(filter)
-- subclasses
if not filter.blizzard.subclass then
for _, subclass in ipairs(T.temp-T.list(GetAuctionItemSubClasses(index(filter.blizzard.class, 2) or 0))) do
for _, subclass in ipairs(T.temp-T.list(GetAuctionItemSubClasses(aux.index(filter.blizzard.class, 2) or 0))) do
tinsert(suggestions, subclass)
end
end
-- slots
if not filter.blizzard.slot then
for _, invtype in ipairs(T.temp-T.list(GetAuctionInvTypes(index(filter.blizzard.class, 2) == 2 and 2 or 0, index(filter.blizzard.subclass, 2) or 0))) do
for _, invtype in ipairs(T.temp-T.list(GetAuctionInvTypes(aux.index(filter.blizzard.class, 2) == 2 and 2 or 0, aux.index(filter.blizzard.subclass, 2) or 0))) do
tinsert(suggestions, _G[invtype])
end
end
@@ -427,35 +425,35 @@ function prettified_filter_string(filter)
if component[1] == 'blizzard' then
if component[2] == 'name' then
if filter.blizzard.exact then
prettified.append(info.display_name(info.item_id(component[3])) or color.orange('[' .. component[3] .. ']'))
prettified.append(info.display_name(info.item_id(component[3])) or aux.color.orange('[' .. component[3] .. ']'))
elseif component[3] ~= '' then
prettified.append(color.label.enabled(component[3]))
prettified.append(aux.color.label.enabled(component[3]))
end
elseif component[2] ~= 'exact' then
prettified.append(color.orange(component[3]))
prettified.append(aux.color.orange(component[3]))
end
elseif component[1] == 'operator' then
prettified.append(color.orange(component[2] .. (component[2] ~= 'not' and tonumber(component[3]) or '')))
prettified.append(aux.color.orange(component[2] .. (component[2] ~= 'not' and tonumber(component[3]) or '')))
elseif component[1] == 'filter' then
if i == 1 or component[2] ~= 'tooltip' then
prettified.append(color.orange(component[2]))
prettified.append(aux.color.orange(component[2]))
end
local parameter = component[3]
if parameter then
if component[2] == 'item' then
prettified.append(info.display_name(info.item_id(parameter)) or color.label.enabled('[' .. parameter .. ']'))
prettified.append(info.display_name(info.item_id(parameter)) or aux.color.label.enabled('[' .. parameter .. ']'))
else
if filters[component[2]].input_type == 'money' then
prettified.append(money.to_string(money.from_string(parameter), nil, true, color.label.enabled))
prettified.append(money.to_string(money.from_string(parameter), nil, true, aux.color.label.enabled))
else
prettified.append(color.label.enabled(parameter))
prettified.append(aux.color.label.enabled(parameter))
end
end
end
end
end
if prettified.get() == '' then
return color.orange'<>'
return aux.color.orange'<>'
else
return prettified.get()
end
@@ -466,7 +464,7 @@ function M.quote(name)
end
function M.unquote(name)
return select(3, strfind(name, '^<(.*)>$')) or name
return aux.select(3, strfind(name, '^<(.*)>$')) or name
end
function blizzard_query(filter)
@@ -490,7 +488,7 @@ function blizzard_query(filter)
query.quality = item_info.quality
else
for key in T.temp-T.set('min_level', 'max_level', 'class', 'subclass', 'slot', 'usable', 'quality') do
query[key] = index(filters[key], 2)
query[key] = aux.index(filters[key], 2)
end
end
return query
@@ -520,15 +518,15 @@ function validator(filter)
if name == 'not' then
tinsert(stack, not args[1])
elseif name == 'and' then
tinsert(stack, all(args))
tinsert(stack, aux.all(args))
elseif name == 'or' then
tinsert(stack, any(args))
tinsert(stack, aux.any(args))
end
elseif type == 'filter' then
tinsert(stack, not not validators[i](record))
end
end
return all(stack)
return aux.all(stack)
end
end
+6 -7
View File
@@ -1,8 +1,7 @@
module 'aux.util.info'
include 'aux'
local T = require 'T'
local aux = require 'aux'
CreateFrame('GameTooltip', 'AuxTooltip', nil, 'GameTooltipTemplate')
AuxTooltip:SetScript('OnTooltipAddMoney', function()
@@ -125,8 +124,8 @@ function M.auction(index, query_type)
'link', link,
'itemstring', item_info.itemstring,
'item_key', item_id .. ':' .. suffix_id,
'search_signature', 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', 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_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 '?')), ':'),
'name', name,
'texture', texture,
@@ -170,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 = 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_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)
@@ -210,7 +209,7 @@ function M.set_shopping_tooltip(slot)
end
function M.tooltip_match(entry, tooltip)
return any(tooltip, function(line)
return aux.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)
return left_match or right_match
@@ -254,7 +253,7 @@ function M.display_name(item_id, no_brackets, no_color)
name = '[' .. name .. ']'
end
if not no_color then
name = select(4, GetItemQualityColor(item_info.quality)) .. name .. FONT_COLOR_CODE_CLOSE
name = aux.select(4, GetItemQualityColor(item_info.quality)) .. name .. FONT_COLOR_CODE_CLOSE
end
return name
end
+6 -7
View File
@@ -1,8 +1,7 @@
module 'aux.util.money'
include 'aux'
local T = require 'T'
local aux = require 'aux'
M.GOLD_TEXT = '|cffffd70ag|r'
M.SILVER_TEXT = '|cffc7c7cfs|r'
@@ -35,7 +34,7 @@ function M.to_string2(money, exact, color)
local NONE = '|cffa0a0a0' .. TEXT_NONE .. FONT_COLOR_CODE_CLOSE
if not exact and money >= COPPER_PER_GOLD then
money = round(money / COPPER_PER_SILVER) * COPPER_PER_SILVER
money = aux.round(money / COPPER_PER_SILVER) * COPPER_PER_SILVER
end
local g, s, c = to_gsc(money)
@@ -83,7 +82,7 @@ function M.to_string(money, pad, trim, color, no_color)
if copper > 0 or gold == 0 and silver == 0 then
tinsert(parts, format_number(copper, pad, color) .. copper_text)
end
text = join(parts, ' ')
text = aux.join(parts, ' ')
else
if gold > 0 then
text = format_number(gold, false, color) .. gold_text .. ' ' .. format_number(silver, pad, color) .. silver_text .. ' ' .. format_number(copper, pad, color) .. copper_text
@@ -109,9 +108,9 @@ function M.from_string(value)
value = gsub(gsub(strlower(value), '|c%x%x%x%x%x%x%x%x', ''), FONT_COLOR_CODE_CLOSE, '')
local gold = tonumber(select(3, strfind(value, '(%d*%.?%d+)g')))
local silver = tonumber(select(3, strfind(value, '(%d*%.?%d+)s')))
local copper = tonumber(select(3, strfind(value, '(%d*%.?%d+)c')))
local gold = tonumber(aux.select(3, strfind(value, '(%d*%.?%d+)g')))
local silver = tonumber(aux.select(3, strfind(value, '(%d*%.?%d+)s')))
local copper = tonumber(aux.select(3, strfind(value, '(%d*%.?%d+)c')))
if not gold and not silver and not copper then return end
value = gsub(value, '%d*%.?%d+g', '', 1)
+6 -7
View File
@@ -1,8 +1,7 @@
module 'aux.util.persistence'
include 'aux'
local T = require 'T'
local aux = require 'aux'
function M.read(schema, str)
if schema == 'string' then
@@ -40,7 +39,7 @@ function read_list(schema, str)
if str == '' then return T.acquire() end
local separator = schema[2]
local element_type = schema[3]
return map(split(str, separator), function(part)
return aux.map(aux.split(str, separator), function(part)
return read(element_type, part)
end)
end
@@ -48,16 +47,16 @@ end
function write_list(schema, list)
local separator = schema[2]
local element_type = schema[3]
local parts = map(T.temp-copy(list), function(element)
local parts = aux.map(T.temp-aux.copy(list), function(element)
return write(element_type, element)
end)
return join(parts, separator)
return aux.join(parts, separator)
end
function read_tuple(schema, str)
local separator = schema[2]
local tuple = T.acquire()
local parts = T.temp-split(str, separator)
local parts = T.temp-aux.split(str, separator)
for i = 3, getn(schema) do
local key, type = next(schema[i])
tuple[key] = read(type, parts[i - 2])
@@ -72,5 +71,5 @@ function write_tuple(schema, tuple)
local key, type = next(schema[i])
tinsert(parts, write(type, tuple[key]))
end
return join(parts, separator)
return aux.join(parts, separator)
end
+4 -6
View File
@@ -1,9 +1,7 @@
module 'aux.util.scan'
include 'aux'
local T = require 'T'
local aux = require 'aux'
local info = require 'aux.util.info'
local filter_util = require 'aux.util.filter'
local scan = require 'aux.core.scan'
@@ -18,20 +16,20 @@ function M.find(auction_record, status_bar, on_abort, on_failure, on_success)
local queries = T.list(T.acquire())
if auction_record.blizzard_query then
local blizzard_query1 = copy(auction_record.blizzard_query)
local blizzard_query1 = aux.copy(auction_record.blizzard_query)
blizzard_query1.first_page = auction_record.page
blizzard_query1.last_page = auction_record.page
tinsert(queries, T.map('blizzard_query', blizzard_query1))
if auction_record.page > 0 then
local blizzard_query2 = copy(auction_record.blizzard_query)
local blizzard_query2 = aux.copy(auction_record.blizzard_query)
blizzard_query2.first_page = auction_record.page - 1
blizzard_query2.last_page = auction_record.page - 1
tinsert(queries, T.map('blizzard_query', blizzard_query2))
end
local item_query = item_query(auction_record.item_id, 0, 0)
if not eq(auction_record.blizzard_query, item_query.blizzard_query) then
if not aux.eq(auction_record.blizzard_query, item_query.blizzard_query) then
tinsert(queries, item_query)
end
end
-2
View File
@@ -1,7 +1,5 @@
module 'aux.util.sort'
include 'aux'
local T = require 'T'
M.EQ = 0