refactoring
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
module 'util'
|
||||
module 'core'
|
||||
|
||||
COLORS = {
|
||||
text = {enabled = {255, 254, 250, 1}, disabled = {147, 151, 139, 1}},
|
||||
|
||||
+23
-28
@@ -1,28 +1,11 @@
|
||||
module 'util'
|
||||
module 'core'
|
||||
|
||||
public.join = _g.join
|
||||
public.join = _g.table.concat
|
||||
|
||||
function public.replicate(count, value)
|
||||
if count > 0 then return value, replicate(count - 1, value) end
|
||||
end
|
||||
|
||||
do
|
||||
local value, charges
|
||||
local function mutator(n)
|
||||
return function(v)
|
||||
assert(charges == 0)
|
||||
value, charges = v, n
|
||||
return v
|
||||
end
|
||||
end
|
||||
for i=1,9 do public[join{replicate(i, 'x')}] = mutator(i) end
|
||||
function public.accessor.__()
|
||||
assert(charges > 0)
|
||||
charges = charges - 1
|
||||
return value
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local state
|
||||
local function f()
|
||||
@@ -67,14 +50,12 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
function public.call(f, ...)
|
||||
temp(arg)
|
||||
function public.call(f, ...) temp=arg
|
||||
if f then return f(unpack(arg)) end
|
||||
end
|
||||
|
||||
function public.index(t, ...)
|
||||
function public.index(t, ...) temp=arg
|
||||
for i=1,arg.n do t = t and t[arg[i]] end
|
||||
recycle(arg)
|
||||
return t
|
||||
end
|
||||
|
||||
@@ -106,10 +87,9 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
function public.expand(array, ...)
|
||||
function public.expand(array, ...) temp=arg
|
||||
local t = t
|
||||
for i=1,arg.n do t[arg[i]] = array[i] end
|
||||
recycle(arg)
|
||||
return t
|
||||
end
|
||||
|
||||
@@ -120,10 +100,25 @@ function public.copy(t)
|
||||
return setmetatable(copy, getmetatable(t))
|
||||
end
|
||||
|
||||
function public.select(i, ...)
|
||||
temp(arg)
|
||||
function public.select(i, ...) temp=arg
|
||||
while i > 1 do i = i - 1; tremove(arg, i) end
|
||||
return tremove(arg, 1), unpack(temp)
|
||||
return tremove(arg, 1), unpack(arg)
|
||||
end
|
||||
|
||||
function public.collect(t, ...) temp=arg
|
||||
local T = T
|
||||
for _, v in t do
|
||||
tinsert(T, arg[v])
|
||||
end
|
||||
return T
|
||||
end
|
||||
|
||||
function public.hashset(t)
|
||||
local set = _m.t
|
||||
for _, v in t do
|
||||
set[v] = true
|
||||
end
|
||||
return set
|
||||
end
|
||||
|
||||
function public.size(t)
|
||||
|
||||
+10
-7
@@ -285,10 +285,11 @@ function public.parse_query_string(str)
|
||||
|
||||
local i = 1
|
||||
while parts[i] do
|
||||
if x(operator(parts[i])) then
|
||||
tinsert(post_filter, __)
|
||||
elseif x(filters[parts[i]]) then
|
||||
local input_type = __.input_type
|
||||
local operator = operator(parts[i])
|
||||
if operator then
|
||||
tinsert(post_filter, operator)
|
||||
elseif filters[parts[i]] then
|
||||
local input_type = filters[parts[i]].input_type
|
||||
if input_type ~= '' then
|
||||
if not parts[i + 1] or not parse_parameter(input_type, parts[i + 1]) then
|
||||
if parts[i] == 'item' then
|
||||
@@ -494,8 +495,10 @@ function blizzard_query(components)
|
||||
local query = {name=filters.name and filters.name[2]}
|
||||
|
||||
local item_info, class_index, subclass_index, slot_index
|
||||
if filters.exact and x(cache.item_id(filters.name[2])) and x(info.item(__)) then
|
||||
item_info = __
|
||||
local item_id = 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)
|
||||
class_index = info.item_class_index(item_info.class)
|
||||
subclass_index = info.item_subclass_index(class_index or 0, item_info.subclass)
|
||||
slot_index = info.item_slot_index(class_index or 0, subclass_index or 0, item_info.slot)
|
||||
@@ -510,7 +513,7 @@ function blizzard_query(components)
|
||||
query.slot = slot_index
|
||||
query.quality = item_info.quality
|
||||
else
|
||||
for _, key in {'min_level', 'max_level', 'class', 'subclass', 'slot', 'usable', 'quality'} do
|
||||
for key in set 'min_level' 'max_level' 'class' 'subclass' 'slot' 'usable' 'quality' do
|
||||
query[key] = index(filters[key], 2)
|
||||
end
|
||||
end
|
||||
|
||||
+2
-2
@@ -176,7 +176,7 @@ end
|
||||
|
||||
function public.set_shopping_tooltip(slot)
|
||||
local index1, index2 = inventory_index(slot)
|
||||
local tooltips = {}
|
||||
local tooltips = tt
|
||||
if index1 then
|
||||
local tooltip = tooltip(function(tt) tt:SetInventoryItem('player', index1) end)
|
||||
if getn(tooltip) > 0 then
|
||||
@@ -273,7 +273,7 @@ function public.tooltip(mutator)
|
||||
mutator(AuxTooltip)
|
||||
AuxTooltip:Show()
|
||||
|
||||
local tooltip = {}
|
||||
local tooltip = t
|
||||
for i=1,AuxTooltip:NumLines() do
|
||||
tinsert(tooltip, {
|
||||
left_text = _g['AuxTooltipTextLeft'..i]:GetText(),
|
||||
|
||||
+4
-3
@@ -80,7 +80,7 @@ function public.to_string(money, pad, trim, decimal_points, color, no_color)
|
||||
|
||||
local text
|
||||
if trim then
|
||||
local parts = {}
|
||||
local parts = tt
|
||||
if gold > 0 then
|
||||
tinsert(parts, format_number(gold, false, nil, color)..gold_text)
|
||||
end
|
||||
@@ -113,8 +113,9 @@ function public.to_string(money, pad, trim, decimal_points, color, no_color)
|
||||
end
|
||||
|
||||
function public.from_string(value)
|
||||
if xx(tonumber(value)) and __ >= 0 then
|
||||
return __ * COPPER_PER_GOLD
|
||||
local number = tonumber(value)
|
||||
if number and number >= 0 then
|
||||
return number * COPPER_PER_GOLD
|
||||
end
|
||||
|
||||
-- remove any colors
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module 'persistence'
|
||||
|
||||
_g.aux_datasets = {}
|
||||
_g.aux_datasets = t
|
||||
|
||||
do
|
||||
local realm, faction
|
||||
@@ -15,7 +15,7 @@ end
|
||||
|
||||
function public.load_dataset()
|
||||
local dataset_key = dataset_key
|
||||
_g.aux_datasets[dataset_key] = _g.aux_datasets[dataset_key] or {}
|
||||
_g.aux_datasets[dataset_key] = _g.aux_datasets[dataset_key] or t
|
||||
return _g.aux_datasets[dataset_key]
|
||||
end
|
||||
|
||||
@@ -64,8 +64,7 @@ function public.write(schema, obj)
|
||||
end
|
||||
|
||||
function public.read_list(schema, str)
|
||||
if str == '' then return {} end
|
||||
|
||||
if str == '' then return t end
|
||||
local separator = schema[2]
|
||||
local element_type = schema[3]
|
||||
local parts = split(str, separator)
|
||||
@@ -85,7 +84,7 @@ end
|
||||
|
||||
function public.read_record(schema, str)
|
||||
local separator = schema[2]
|
||||
local record = {}
|
||||
local record = t
|
||||
local parts = split(str, separator)
|
||||
for i=3,getn(schema) do
|
||||
local key, type = next(schema[i])
|
||||
@@ -96,7 +95,7 @@ end
|
||||
|
||||
function public.write_record(schema, record)
|
||||
local separator = schema[2]
|
||||
local parts = {}
|
||||
local parts = tt
|
||||
for i=3,getn(schema) do
|
||||
local key, type = next(schema[i])
|
||||
tinsert(parts, write(type, record[key]))
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ function public.find(auction_record, status_bar, on_abort, on_failure, on_succes
|
||||
return auction_info and auction_info.search_signature == auction_record.search_signature
|
||||
end
|
||||
|
||||
local queries = {}
|
||||
tinsert(queries, {})
|
||||
local queries = t
|
||||
tinsert(queries, t)
|
||||
|
||||
if auction_record.blizzard_query then
|
||||
|
||||
|
||||
+5
-5
@@ -1,10 +1,10 @@
|
||||
module 'sorting'
|
||||
|
||||
public.LT = {}
|
||||
public.EQ = {}
|
||||
public.GT = {}
|
||||
public()
|
||||
|
||||
function public.compare(a, b, desc)
|
||||
LT, EQ, GT = t, t, t
|
||||
|
||||
function compare(a, b, desc)
|
||||
if a < b then
|
||||
return desc and GT or LT
|
||||
elseif a > b then
|
||||
@@ -14,7 +14,7 @@ function public.compare(a, b, desc)
|
||||
end
|
||||
end
|
||||
|
||||
function public.multi_lt(xs, ys)
|
||||
function multi_lt(xs, ys)
|
||||
local i = 1
|
||||
while true do
|
||||
if xs[i] and ys[i] and xs[i] ~= ys[i] then
|
||||
|
||||
Reference in New Issue
Block a user