refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-09-30 18:32:19 +02:00
parent 4414ccf084
commit f29cb9ae1d
36 changed files with 531 additions and 298 deletions
+26 -18
View File
@@ -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)