refactoring
This commit is contained in:
+6
-1
@@ -1,4 +1,9 @@
|
||||
aux 'core'
|
||||
aux_util_color = module
|
||||
|
||||
include (green_t)
|
||||
include (aux)
|
||||
include (aux_util)
|
||||
include (aux_control)
|
||||
|
||||
local COLORS = {
|
||||
text = {enabled = {255, 254, 250, 1}, disabled = {147, 151, 139, 1}},
|
||||
|
||||
+9
-1
@@ -1,4 +1,12 @@
|
||||
aux 'completion' local filter_util = aux.filter_util
|
||||
aux_completion = module
|
||||
|
||||
include (green_t)
|
||||
include (aux)
|
||||
include (aux_util)
|
||||
include (aux_control)
|
||||
include (aux_util_color)
|
||||
|
||||
local filter_util = aux_filter_util
|
||||
|
||||
function public:complete_filter()
|
||||
if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution
|
||||
|
||||
+34
-21
@@ -1,29 +1,42 @@
|
||||
aux 'core'
|
||||
aux_util = module
|
||||
|
||||
include (green_t)
|
||||
include (aux)
|
||||
|
||||
do
|
||||
local state = setmetatable({}, { __mode='k' })
|
||||
|
||||
function class(object, ...)
|
||||
local interface = {}
|
||||
for i = 1, arg.n do
|
||||
local key = arg[i]
|
||||
interface[key] = function(self, ...)
|
||||
local object = state[self]
|
||||
return object[key](object, unpack(arg))
|
||||
end
|
||||
end
|
||||
return function()
|
||||
local proxy = setmetatable({}, { __metatable=false, __index=interface })
|
||||
state[proxy] = setmetatable({}, { __index=object })
|
||||
return proxy
|
||||
local classes, interfaces, objects = {}, {}, setmetatable({}, { __mode='k' })
|
||||
local private_mt = { __metatable=false }
|
||||
function private_mt:__newindex(k, v)
|
||||
classes[self][k] = v
|
||||
end
|
||||
local public_mt = { __metatable=false }
|
||||
function public_mt:__newindex(k, v)
|
||||
classes[self][k] = v
|
||||
interfaces[self][k] = function(self, ...)
|
||||
return classes[self][k](objects[self][k], unpack(arg))
|
||||
end
|
||||
end
|
||||
local proxy_mt = { __metatable=false }
|
||||
function proxy_mt:__call()
|
||||
local proxy = setmetatable({}, { __metatable=false, __index=interfaces[self] })
|
||||
objects[proxy] = setmetatable({}, { __index=classes[self] })
|
||||
return proxy
|
||||
end
|
||||
function public.class()
|
||||
local class, interface = {}, {}
|
||||
local private, public, proxy = setmetatable({}, private_mt), setmetatable({}, public_mt), setmetatable({}, proxy_mt)
|
||||
classes[private], classes[public], classes[proxy] = class, class, class
|
||||
interfaces[public], interfaces[proxy] = interface, interface
|
||||
return private, public, proxy
|
||||
end
|
||||
end
|
||||
|
||||
-- alternatively rely on module encapsulation, modifier "method" to declare methods
|
||||
|
||||
do
|
||||
local _state = setmetatable(t, T('__mode', 'kv'))
|
||||
local __index = function(self, key)
|
||||
return _state[self].handler({ public=self, private=_state[self].state }, key)
|
||||
local __index = function(self, k)
|
||||
return _state[self].handler({ public=self, private=_state[self].state }, k)
|
||||
end
|
||||
function public.index_function(state, handler) -- TODO rename table-accessor, use predicate to stop
|
||||
local state, self = { handler=handler, state=state }, t
|
||||
@@ -89,7 +102,7 @@ function public.modified.get()
|
||||
end
|
||||
|
||||
function public.copy(t)
|
||||
local copy = _E.t
|
||||
local copy = _M.t
|
||||
for k, v in t do copy[k] = v end
|
||||
table.setn(copy, getn(t))
|
||||
return setmetatable(copy, getmetatable(t))
|
||||
@@ -106,13 +119,13 @@ function public.key(value, t)
|
||||
end
|
||||
|
||||
function public.keys(t)
|
||||
local keys = _E.t
|
||||
local keys = _M.t
|
||||
for k in t do tinsert(keys, k) end
|
||||
return keys
|
||||
end
|
||||
|
||||
function public.values(t)
|
||||
local values = _E.t
|
||||
local values = _M.t
|
||||
for _, v in t do tinsert(values, v) end
|
||||
return values
|
||||
end
|
||||
|
||||
+26
-18
@@ -1,4 +1,12 @@
|
||||
aux 'filter_util' local info = aux.info
|
||||
aux_filter_util = module
|
||||
|
||||
include (green_t)
|
||||
include (aux)
|
||||
include (aux_util)
|
||||
include (aux_control)
|
||||
include (aux_util_color)
|
||||
|
||||
local info = aux_info
|
||||
|
||||
function private.default_filter(str)
|
||||
return {
|
||||
@@ -116,7 +124,7 @@ public.filters = {
|
||||
input_type = 'number',
|
||||
validator = function(pct)
|
||||
return function(auction_record)
|
||||
return aux.history.value(auction_record.item_key) and auction_record.unit_bid_price / aux.history.value(auction_record.item_key) * 100 <= pct
|
||||
return aux_history.value(auction_record.item_key) and auction_record.unit_bid_price / aux_history.value(auction_record.item_key) * 100 <= pct
|
||||
end
|
||||
end
|
||||
},
|
||||
@@ -126,8 +134,8 @@ public.filters = {
|
||||
validator = function(pct)
|
||||
return function(auction_record)
|
||||
return auction_record.unit_buyout_price > 0
|
||||
and aux.history.value(auction_record.item_key)
|
||||
and auction_record.unit_buyout_price / aux.history.value(auction_record.item_key) * 100 <= pct
|
||||
and aux_history.value(auction_record.item_key)
|
||||
and auction_record.unit_buyout_price / aux_history.value(auction_record.item_key) * 100 <= pct
|
||||
end
|
||||
end
|
||||
},
|
||||
@@ -136,7 +144,7 @@ public.filters = {
|
||||
input_type = 'money',
|
||||
validator = function(amount)
|
||||
return function(auction_record)
|
||||
return aux.history.value(auction_record.item_key) and aux.history.value(auction_record.item_key) * auction_record.aux_quantity - auction_record.bid_price >= amount
|
||||
return aux_history.value(auction_record.item_key) and aux_history.value(auction_record.item_key) * auction_record.aux_quantity - auction_record.bid_price >= amount
|
||||
end
|
||||
end
|
||||
},
|
||||
@@ -145,7 +153,7 @@ public.filters = {
|
||||
input_type = 'money',
|
||||
validator = function(amount)
|
||||
return function(auction_record)
|
||||
return auction_record.buyout_price > 0 and aux.history.value(auction_record.item_key) and aux.history.value(auction_record.item_key) * auction_record.aux_quantity - auction_record.buyout_price >= amount
|
||||
return auction_record.buyout_price > 0 and aux_history.value(auction_record.item_key) and aux_history.value(auction_record.item_key) * auction_record.aux_quantity - auction_record.buyout_price >= amount
|
||||
end
|
||||
end
|
||||
},
|
||||
@@ -154,7 +162,7 @@ public.filters = {
|
||||
input_type = 'money',
|
||||
validator = function(amount)
|
||||
return function(auction_record)
|
||||
local disenchant_value = aux.disenchant.value(auction_record.slot, auction_record.quality, auction_record.level)
|
||||
local disenchant_value = aux_disenchant.value(auction_record.slot, auction_record.quality, auction_record.level)
|
||||
return disenchant_value and disenchant_value - auction_record.bid_price >= amount
|
||||
end
|
||||
end
|
||||
@@ -164,7 +172,7 @@ public.filters = {
|
||||
input_type = 'money',
|
||||
validator = function(amount)
|
||||
return function(auction_record)
|
||||
local disenchant_value = aux.disenchant.value(auction_record.slot, auction_record.quality, auction_record.level)
|
||||
local disenchant_value = aux_disenchant.value(auction_record.slot, auction_record.quality, auction_record.level)
|
||||
return auction_record.buyout_price > 0 and disenchant_value and disenchant_value - auction_record.buyout_price >= amount
|
||||
end
|
||||
end
|
||||
@@ -174,7 +182,7 @@ public.filters = {
|
||||
input_type = 'money',
|
||||
validator = function(amount)
|
||||
return function(auction_record)
|
||||
local vendor_price = aux.cache.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
|
||||
end
|
||||
@@ -184,7 +192,7 @@ public.filters = {
|
||||
input_type = 'money',
|
||||
validator = function(amount)
|
||||
return function(auction_record)
|
||||
local vendor_price = aux.cache.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
|
||||
end
|
||||
@@ -261,7 +269,7 @@ end
|
||||
|
||||
function private.parse_parameter(input_type, str)
|
||||
if input_type == 'money' then
|
||||
local money = aux.money.from_string(str)
|
||||
local money = aux_money.from_string(str)
|
||||
return money and money > 0 and money or nil
|
||||
elseif input_type == 'number' then
|
||||
local number = tonumber(str)
|
||||
@@ -352,7 +360,7 @@ function public.query(filter_string)
|
||||
blizzard_query = blizzard_query(filter),
|
||||
validator = validator(filter),
|
||||
prettified = prettified_filter_string(filter),
|
||||
}, _E.suggestions(filter)
|
||||
}, _M.suggestions(filter)
|
||||
end
|
||||
|
||||
function public.queries(filter_string)
|
||||
@@ -427,8 +435,8 @@ function public.filter_string(components)
|
||||
elseif component[1] == 'filter' then
|
||||
query_builder.append(component[2])
|
||||
for parameter in present(component[3]) do
|
||||
if aux.filter_util.filters[component[2]].input_type == 'money' then
|
||||
parameter = aux.money.to_string(aux.money.from_string(parameter), nil, true, nil, nil, true)
|
||||
if aux_filter_util.filters[component[2]].input_type == 'money' then
|
||||
parameter = aux_money.to_string(aux_money.from_string(parameter), nil, true, nil, nil, true)
|
||||
end
|
||||
query_builder.append(parameter)
|
||||
end
|
||||
@@ -445,7 +453,7 @@ function private.prettified_filter_string(filter)
|
||||
if component[1] == 'blizzard' then
|
||||
if component[2] == 'name' then
|
||||
if filter.blizzard.exact then
|
||||
prettified.append(info.display_name(aux.cache.item_id(component[4])) or color.blizzard('[' .. component[4] .. ']'))
|
||||
prettified.append(info.display_name(aux_cache.item_id(component[4])) or color.blizzard('[' .. component[4] .. ']'))
|
||||
elseif component[4] ~= '' then
|
||||
prettified.append(color.blizzard(component[4]))
|
||||
end
|
||||
@@ -460,10 +468,10 @@ function private.prettified_filter_string(filter)
|
||||
end
|
||||
for parameter in present(component[3]) do
|
||||
if component[2] == 'item' then
|
||||
prettified.append(info.display_name(aux.cache.item_id(parameter)) or color.label.enabled('[' .. parameter .. ']'))
|
||||
prettified.append(info.display_name(aux_cache.item_id(parameter)) or color.label.enabled('[' .. parameter .. ']'))
|
||||
else
|
||||
if filters[component[2]].input_type == 'money' then
|
||||
prettified.append(aux.money.to_string(aux.money.from_string(parameter), nil, true, nil, inline_color.label.enabled))
|
||||
prettified.append(aux_money.to_string(aux_money.from_string(parameter), nil, true, nil, inline_color.label.enabled))
|
||||
else
|
||||
prettified.append(color.label.enabled(parameter))
|
||||
end
|
||||
@@ -490,7 +498,7 @@ function private.blizzard_query(filter)
|
||||
local filters = filter.blizzard
|
||||
local query = T('name', filters.name and filters.name[2])
|
||||
local item_info, class_index, subclass_index, slot_index
|
||||
local item_id = filters.name and aux.cache.item_id(filters.name[2])
|
||||
local item_id = filters.name and aux_cache.item_id(filters.name[2])
|
||||
item_info = item_id and info.item(item_id)
|
||||
if filters.exact and item_info then
|
||||
item_info = info.item(item_id)
|
||||
|
||||
+8
-2
@@ -1,4 +1,10 @@
|
||||
aux 'info'
|
||||
aux_info = module
|
||||
|
||||
include (green_t)
|
||||
include (aux)
|
||||
include (aux_util)
|
||||
include (aux_control)
|
||||
include (aux_util_color)
|
||||
|
||||
CreateFrame('GameTooltip', 'AuxTooltip', nil, 'GameTooltipTemplate')
|
||||
AuxTooltip:SetScript('OnTooltipAddMoney', function()
|
||||
@@ -365,7 +371,7 @@ function public.item(item_id, suffix_id)
|
||||
'slot', slot,
|
||||
'max_stack', max_stack,
|
||||
'texture', texture
|
||||
) or aux.cache.item_info(item_id)
|
||||
) or aux_cache.item_info(item_id)
|
||||
end
|
||||
|
||||
function public.item_class_index(item_class)
|
||||
|
||||
+7
-1
@@ -1,4 +1,10 @@
|
||||
aux 'money'
|
||||
aux_money = module
|
||||
|
||||
include (green_t)
|
||||
include (aux)
|
||||
include (aux_util)
|
||||
include (aux_control)
|
||||
include (aux_util_color)
|
||||
|
||||
public.GOLD_TEXT = '|cffffd70ag|r'
|
||||
public.SILVER_TEXT = '|cffc7c7cfs|r'
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
aux 'persistence'
|
||||
aux_persistence = module
|
||||
|
||||
include (green_t)
|
||||
include (aux)
|
||||
include (aux_util)
|
||||
include (aux_control)
|
||||
include (aux_util_color)
|
||||
|
||||
aux_datasets = t
|
||||
|
||||
|
||||
+10
-2
@@ -1,4 +1,12 @@
|
||||
aux 'scan_util' local info , filter_util = aux.info, aux.filter_util
|
||||
aux_scan_util = module
|
||||
|
||||
include (green_t)
|
||||
include (aux)
|
||||
include (aux_util)
|
||||
include (aux_control)
|
||||
include (aux_util_color)
|
||||
|
||||
local info , filter_util = aux_info, aux_filter_util
|
||||
|
||||
function public.find(auction_record, status_bar, on_abort, on_failure, on_success)
|
||||
|
||||
@@ -31,7 +39,7 @@ function public.find(auction_record, status_bar, on_abort, on_failure, on_succes
|
||||
end
|
||||
|
||||
local found
|
||||
return aux.scan.start{
|
||||
return aux_scan.start{
|
||||
type = auction_record.query_type,
|
||||
queries = queries,
|
||||
on_scan_start = function()
|
||||
|
||||
+7
-1
@@ -1,4 +1,10 @@
|
||||
aux 'sorting'
|
||||
aux_sorting = module
|
||||
|
||||
include (green_t)
|
||||
include (aux)
|
||||
include (aux_util)
|
||||
include (aux_control)
|
||||
include (aux_util_color)
|
||||
|
||||
public.EQ = 0
|
||||
public.LT = 1
|
||||
|
||||
Reference in New Issue
Block a user