a lot of refactoring, performance issue fixed

This commit is contained in:
Manuel Simon Hirsig
2016-08-03 18:14:18 +02:00
parent 02ee8f7c6c
commit b374c7946f
16 changed files with 453 additions and 501 deletions
+55 -76
View File
@@ -3,22 +3,6 @@ local m, public, private = Aux.module'util'
function public.pass()
end
function public.sum(...)
local x = 0
for i=1,arg.n do
x = x + arg[i]
end
return x
end
function public.product(...)
local x = 0
for i=1,arg.n do
x = x * arg[i]
end
return x
end
function public.id(x)
return x
end
@@ -104,7 +88,7 @@ function public.inventory()
end
if bag <= 4 then
return { bag, slot }, m.bag_type(bag)
return {bag, slot}, m.bag_type(bag)
end
end
end
@@ -136,18 +120,9 @@ function public.without_sound(f)
SetCVar('MasterSoundEffects', orig)
end
function public.iter(array)
local i = 0
return function()
local ret = {iter(array, i)}
i = ret[1]
return ret[2]
end
end
function public.any(xs, p)
local holds = false
for _, x in ipairs(xs) do
for _, x in xs do
holds = holds or p(x)
end
return holds
@@ -155,7 +130,7 @@ end
function public.all(xs, p)
local holds = true
for _, x in ipairs(xs) do
for _, x in xs do
holds = holds and p(x)
end
return holds
@@ -173,9 +148,9 @@ end
function public.filter(xs, p)
local ys = {}
for _, x in xs do
for k, x in xs do
if p(x) then
tinsert(ys, x)
ys[k] = x
end
end
return ys
@@ -183,18 +158,16 @@ end
function public.map(xs, f)
local ys = {}
for _, x in xs do
tinsert(ys, f(x))
for k, x in xs do
ys[k] = f(x)
end
return ys
end
function public.take(n, xs)
local ys = {}
for i=1,n do
if xs[i] then
tinsert(ys, xs[i])
end
for i=1,min(n, getn(xs)) do
tinsert(ys, xs[i])
end
return ys
end
@@ -224,40 +197,46 @@ function public.group_by(tables, equal)
return groups
end
function public.set(...)
local set = {}
for i=1,arg.n do
set[arg[i]] = true
do
local mt = {
__call = function(self)
return
end,
}
local methods = {}
function methods:add(key)
self[key] = true
end
return set
end
function public.set_add(set, key)
set[key] = true
end
function public.set_remove(set, key)
set[key] = nil
end
function public.set_contains(set, key)
return set[key] ~= nil
end
function public.set_size(set)
local size = 0
for _,_ in set do
size = size + 1
function methods:remove(key)
self[key] = nil
end
return size
end
function public.set_to_array(set)
local array = {}
for element, _ in set do
tinsert(array, element)
function methods:size()
local size = 0
for _,_ in self do
size = size + 1
end
return size
end
function methods:elements()
local elements = {}
for element, _ in self do
tinsert(elements, element)
end
return elements
end
function public.set(...)
local self = {}
for i=1,arg.n do
set[arg[i]] = true
end
return setmetatable(self, mt)
end
return array
end
function public.join(array, separator)
@@ -271,14 +250,6 @@ function public.join(array, separator)
return str
end
function public.tokenize(str)
local tokens = {}
for token in string.gfind(str, '%S+') do
tinsert(tokens, token)
end
return tokens
end
function public.split(str, separator)
local array = {}
@@ -297,6 +268,14 @@ function public.split(str, separator)
end
end
function public.tokenize(str)
local tokens = {}
for token in string.gfind(str, '%S+') do
tinsert(tokens, token)
end
return tokens
end
function public.format_money(money, exact, color)
color = color or '|r'
@@ -319,15 +298,15 @@ function public.format_money(money, exact, color)
local fmt = GSC_START
if g > 0 then
gsc = gsc..string.format(fmt, GSC_GOLD, g)
gsc = gsc..format(fmt, GSC_GOLD, g)
fmt = GSC_PART
end
if s > 0 or c > 0 then
gsc = gsc..string.format(fmt, GSC_SILVER, s)
gsc = gsc..format(fmt, GSC_SILVER, s)
fmt = GSC_PART
end
if c > 0 then
gsc = gsc..string.format(fmt, GSC_COPPER, c)
gsc = gsc..format(fmt, GSC_COPPER, c)
end
if gsc == '' then
gsc = GSC_NONE
+1 -1
View File
@@ -457,7 +457,7 @@ function private.suggestions(components)
tinsert(suggestions, 'not')
tinsert(suggestions, 'tt')
for filter, _ in pairs(m.filters) do
for filter, _ in m.filters do
tinsert(suggestions, strlower(filter))
end
+45 -37
View File
@@ -2,35 +2,41 @@ local m, public, private = Aux.module'info'
local TOOLTIP_LENGTH = 30
function public.inventory_index(slot)
local inventory_index_map = {
INVTYPE_AMMO = {0},
INVTYPE_HEAD = {1},
INVTYPE_NECK = {2},
INVTYPE_SHOULDER = {3},
INVTYPE_BODY = {4},
INVTYPE_CHEST = {5},
INVTYPE_ROBE = {5},
INVTYPE_WAIST = {6},
INVTYPE_LEGS = {7},
INVTYPE_FEET = {8},
INVTYPE_WRIST = {9},
INVTYPE_HAND = {10},
INVTYPE_FINGER = {11, 12},
INVTYPE_TRINKET = {13, 14},
INVTYPE_CLOAK = {15},
INVTYPE_2HWEAPON = {16, 17},
INVTYPE_WEAPONMAINHAND = {16, 17},
INVTYPE_WEAPON = {16, 17},
INVTYPE_WEAPONOFFHAND = {16, 17},
INVTYPE_HOLDABLE = {16, 17},
INVTYPE_SHIELD = {16, 17},
INVTYPE_RANGED = {18},
INVTYPE_RANGEDRIGHT = {18},
INVTYPE_TABARD = {19},
}
CreateFrame('GameTooltip', 'AuxTooltip', nil, 'GameTooltipTemplate')
AuxTooltip:SetScript('OnTooltipAddMoney', function()
this.money = arg1
end)
return unpack(inventory_index_map[slot] or {})
do
local inventory_index_map = {
INVTYPE_AMMO = {0},
INVTYPE_HEAD = {1},
INVTYPE_NECK = {2},
INVTYPE_SHOULDER = {3},
INVTYPE_BODY = {4},
INVTYPE_CHEST = {5},
INVTYPE_ROBE = {5},
INVTYPE_WAIST = {6},
INVTYPE_LEGS = {7},
INVTYPE_FEET = {8},
INVTYPE_WRIST = {9},
INVTYPE_HAND = {10},
INVTYPE_FINGER = {11, 12},
INVTYPE_TRINKET = {13, 14},
INVTYPE_CLOAK = {15},
INVTYPE_2HWEAPON = {16, 17},
INVTYPE_WEAPONMAINHAND = {16, 17},
INVTYPE_WEAPON = {16, 17},
INVTYPE_WEAPONOFFHAND = {16, 17},
INVTYPE_HOLDABLE = {16, 17},
INVTYPE_SHIELD = {16, 17},
INVTYPE_RANGED = {18},
INVTYPE_RANGEDRIGHT = {18},
INVTYPE_TABARD = {19},
}
function public.inventory_index(slot)
return unpack(inventory_index_map[slot] or {})
end
end
function public.container_item(bag, slot)
@@ -44,7 +50,7 @@ function public.container_item(bag, slot)
local item_info = m.item(item_id, suffix_id, unique_id, enchant_id)
local texture, count, locked, quality, readable, lootable = GetContainerItemInfo(bag, slot) -- quality not working?
local tooltip = m.tooltip(function(tt) tt:SetBagItem(bag, slot) end)
local tooltip, tooltip_money = m.tooltip(function(tt) tt:SetBagItem(bag, slot) end)
local max_charges = m.max_item_charges(item_id)
local charges = max_charges and m.item_charges(tooltip)
local aux_quantity = charges or count
@@ -74,6 +80,7 @@ function public.container_item(bag, slot)
lootable = lootable,
tooltip = tooltip,
tooltip_money = tooltip_money,
max_charges = max_charges,
charges = charges,
aux_quantity = aux_quantity,
@@ -110,7 +117,7 @@ function public.auction(index, query_type)
local name, texture, count, quality, usable, level, start_price, min_increment, buyout_price, high_bid, high_bidder, owner, sale_status = GetAuctionItemInfo(query_type, index)
local duration = GetAuctionItemTimeLeft(query_type, index)
local tooltip = m.tooltip(function(tt) tt:SetAuctionItem(query_type, index) end)
local tooltip, tooltip_money = m.tooltip(function(tt) tt:SetAuctionItem(query_type, index) end)
local max_charges = m.max_item_charges(item_id)
local charges = max_charges and m.item_charges(tooltip)
local aux_quantity = charges or count
@@ -155,6 +162,7 @@ function public.auction(index, query_type)
usable = usable,
tooltip = tooltip,
tooltip_money = tooltip_money,
max_charges = max_charges,
charges = charges,
aux_quantity = aux_quantity,
@@ -223,7 +231,7 @@ end
function public.tooltip_find(pattern, tooltip)
local count = 0
for _, line in ipairs(tooltip) do
for _, line in tooltip do
if line.left_text and strfind(line.left_text, pattern) then
count = count + 1
end
@@ -236,7 +244,7 @@ function public.tooltip_find(pattern, tooltip)
end
function public.load_tooltip(frame, tooltip)
for _, line in ipairs(tooltip) do
for _, line in tooltip do
if line.right_text then
frame:AddDoubleLine(line.left_text, line.right_text, line.left_color[1], line.left_color[2], line.left_color[3], line.right_color[1], line.right_color[2], line.right_color[3])
else
@@ -249,14 +257,14 @@ function public.load_tooltip(frame, tooltip)
end
end
function public.display_name(item_id, plain, uncolored)
function public.display_name(item_id, no_brackets, no_color)
local item_info = Aux.info.item(item_id)
if item_info then
local name = item_info.name
if not plain then
if not no_brackets then
name = '['..name..']'
end
if not uncolored then
if not no_color then
name = ({GetItemQualityColor(item_info.quality)})[4]..name..FONT_COLOR_CODE_CLOSE
end
return name
@@ -280,7 +288,7 @@ function public.tooltip(setter)
setter(AuxTooltip)
AuxTooltip:Show()
local tooltip = { money=AuxTooltip.money }
local tooltip = {}
for i = 1,TOOLTIP_LENGTH do
local left_text = getglobal('AuxTooltipTextLeft'..i):GetText()
local left_color = { getglobal('AuxTooltipTextLeft'..i):GetTextColor() }
@@ -298,7 +306,7 @@ function public.tooltip(setter)
end
end
return tooltip
return tooltip, AuxTooltip.money
end
function private.item_charges(tooltip)