refactoring
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
local m, public, private = aux.module'cache'
|
||||
|
||||
local MIN_ITEM_ID, MAX_ITEM_ID = 1, 30000
|
||||
private.MIN_ITEM_ID = 1
|
||||
private.MAX_ITEM_ID = 30000
|
||||
|
||||
local items_schema = {'record', '#', {name='string'}, {quality='number'}, {level='number'}, {class='string'}, {subclass='string'}, {slot='string'}, {max_stack='number'}, {texture='string'}}
|
||||
local merchant_buy_schema = {'record', '#', {unit_price='number'}, {limited='boolean'} }
|
||||
|
||||
@@ -156,10 +158,10 @@ function private.merchant_sell_scan()
|
||||
end
|
||||
|
||||
function private.scan_wdb(item_id)
|
||||
item_id = item_id or MIN_ITEM_ID
|
||||
item_id = item_id or m.MIN_ITEM_ID
|
||||
|
||||
local processed = 0
|
||||
while processed <= 100 and item_id <= MAX_ITEM_ID do
|
||||
while processed <= 100 and item_id <= m.MAX_ITEM_ID do
|
||||
local itemstring = 'item:'..item_id
|
||||
local name, _, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring)
|
||||
if name and not aux_item_ids[strlower(name)] then
|
||||
@@ -183,7 +185,7 @@ function private.scan_wdb(item_id)
|
||||
item_id = item_id + 1
|
||||
end
|
||||
|
||||
if item_id <= MAX_ITEM_ID then
|
||||
if item_id <= m.MAX_ITEM_ID then
|
||||
local t0 = GetTime()
|
||||
aux.control.as_soon_as(function() return GetTime() - t0 > 0.1 end, m.scan_wdb, item_id)
|
||||
else
|
||||
@@ -192,9 +194,9 @@ function private.scan_wdb(item_id)
|
||||
end
|
||||
|
||||
function public.populate_wdb(item_id)
|
||||
item_id = item_id or MIN_ITEM_ID
|
||||
item_id = item_id or m.MIN_ITEM_ID
|
||||
|
||||
if item_id > MAX_ITEM_ID then
|
||||
if item_id > m.MAX_ITEM_ID then
|
||||
aux.log('Cache populated.')
|
||||
return
|
||||
end
|
||||
|
||||
@@ -22,8 +22,6 @@ local m, public, private = unpack(addon)
|
||||
--for notnil in {maybenil} do TODO
|
||||
--end
|
||||
|
||||
-- ipairs TODO
|
||||
|
||||
private.modules = { aux }
|
||||
function public.module(name)
|
||||
local module = aux_module()
|
||||
|
||||
@@ -194,7 +194,7 @@ do
|
||||
end
|
||||
|
||||
function self.update_tabs()
|
||||
for _, tab in ipairs(self.tabs) do
|
||||
for _, tab in self.tabs do
|
||||
if tab.group.selected == tab.id then
|
||||
tab.text:SetTextColor(unpack(m.config.label_color.enabled))
|
||||
tab:Disable()
|
||||
|
||||
+3
-3
@@ -107,7 +107,7 @@ function private.update_auction_listing()
|
||||
local unit_start_price = m.get_unit_start_price()
|
||||
local unit_buyout_price = m.get_unit_buyout_price()
|
||||
|
||||
for i, auction_record in ipairs(m.existing_auctions[m.selected_item.key] or {}) do
|
||||
for i, auction_record in m.existing_auctions[m.selected_item.key] or {} do
|
||||
|
||||
local blizzard_bid_undercut, buyout_price_undercut = m.undercut(auction_record, m.stack_size_slider:GetValue())
|
||||
blizzard_bid_undercut = aux.money.from_string(aux.money.to_string(blizzard_bid_undercut, true, nil, 3))
|
||||
@@ -234,7 +234,7 @@ function private.post_auctions()
|
||||
|
||||
m.update_inventory_records()
|
||||
m.selected_item = nil
|
||||
for _, record in ipairs(m.inventory_records) do
|
||||
for _, record in m.inventory_records do
|
||||
if record.key == key then
|
||||
m.set_item(record)
|
||||
end
|
||||
@@ -520,7 +520,7 @@ end
|
||||
function private.record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price, duration, owner)
|
||||
m.existing_auctions[key] = m.existing_auctions[key] or {}
|
||||
local entry
|
||||
for _, existing_entry in ipairs(m.existing_auctions[key]) do
|
||||
for _, existing_entry in m.existing_auctions[key] do
|
||||
if unit_blizzard_bid == existing_entry.unit_blizzard_bid and unit_buyout_price == existing_entry.unit_buyout_price and aux_quantity == existing_entry.stack_size and duration == existing_entry.duration and aux.is_player(owner) == existing_entry.own then
|
||||
entry = existing_entry
|
||||
end
|
||||
|
||||
+1
-1
@@ -142,7 +142,7 @@ do
|
||||
end
|
||||
|
||||
function public.join(parts, separator)
|
||||
local str = parts[1]
|
||||
local str = parts[1] or ''
|
||||
for i=2,getn(parts) do
|
||||
if not parts[i] then break end
|
||||
str = str..separator..parts[i]
|
||||
|
||||
+4
-4
@@ -415,7 +415,7 @@ function public.queries(query_string)
|
||||
local parts = aux.util.split(query_string, ';')
|
||||
|
||||
local queries = {}
|
||||
for _, str in ipairs(parts) do
|
||||
for _, str in parts do
|
||||
str = aux.util.trim(str)
|
||||
|
||||
local query, _, error = m.query(str)
|
||||
@@ -463,7 +463,7 @@ function private.suggestions(components)
|
||||
|
||||
-- classes
|
||||
if not blizzard_filters.class then
|
||||
for _, class in ipairs({ GetAuctionItemClasses() }) do
|
||||
for _, class in { GetAuctionItemClasses() } do
|
||||
tinsert(suggestions, class)
|
||||
end
|
||||
end
|
||||
@@ -471,7 +471,7 @@ function private.suggestions(components)
|
||||
-- subclasses
|
||||
local class_index = blizzard_filters.class and aux.info.item_class_index(blizzard_filters.class)
|
||||
if class_index and not blizzard_filters.subclass then
|
||||
for _, subclass in ipairs({ GetAuctionItemSubClasses(class_index) }) do
|
||||
for _, subclass in { GetAuctionItemSubClasses(class_index) } do
|
||||
tinsert(suggestions, subclass)
|
||||
end
|
||||
end
|
||||
@@ -479,7 +479,7 @@ function private.suggestions(components)
|
||||
-- slots
|
||||
local subclass_index = class_index and blizzard_filters.subclass and aux.info.item_subclass_index(class_index, blizzard_filters.subclass)
|
||||
if subclass_index and not blizzard_filters.slot then
|
||||
for _, invtype in ipairs({ GetAuctionInvTypes(class_index, aux.info.item_subclass_index(class_index, blizzard_filters.subclass)) }) do
|
||||
for _, invtype in { GetAuctionInvTypes(class_index, aux.info.item_subclass_index(class_index, blizzard_filters.subclass)) } do
|
||||
tinsert(suggestions, getglobal(invtype))
|
||||
end
|
||||
end
|
||||
|
||||
+5
-5
@@ -310,7 +310,7 @@ function public.tooltip(setter)
|
||||
end
|
||||
|
||||
function private.item_charges(tooltip)
|
||||
for _, line in ipairs(tooltip) do
|
||||
for _, line in tooltip do
|
||||
local pattern = '^'..gsub(gsub(ITEM_SPELL_CHARGES_P1, '%%d', '(%%d+)'), '%%%d+%$d', '(%%d+)')..'$'
|
||||
|
||||
local _, _, left_charges_string = strfind(line.left_text or '', pattern)
|
||||
@@ -350,7 +350,7 @@ function public.max_item_charges(item_id)
|
||||
end
|
||||
|
||||
function public.durability(tooltip)
|
||||
for _, line in ipairs(tooltip) do
|
||||
for _, line in tooltip do
|
||||
local pattern = '^'..gsub(gsub(DURABILITY_TEMPLATE, '%%d', '(%%d+)'), '%%%d+%$d', '(%%d+)')..'$'
|
||||
local _, _, left_durability_string, left_max_durability_string = strfind(line.left_text or '', pattern)
|
||||
local _, _, right_durability_string, right_max_durability_string = strfind(line.right_text or '', pattern)
|
||||
@@ -393,7 +393,7 @@ function public.item(item_id, suffix_id)
|
||||
end
|
||||
|
||||
function public.item_class_index(item_class)
|
||||
for i, class in ipairs({ GetAuctionItemClasses() }) do
|
||||
for i, class in { GetAuctionItemClasses() } do
|
||||
if strupper(class) == strupper(item_class) then
|
||||
return i
|
||||
end
|
||||
@@ -401,7 +401,7 @@ function public.item_class_index(item_class)
|
||||
end
|
||||
|
||||
function public.item_subclass_index(class_index, item_subclass)
|
||||
for i, subclass in ipairs({ GetAuctionItemSubClasses(class_index) }) do
|
||||
for i, subclass in { GetAuctionItemSubClasses(class_index) } do
|
||||
if strupper(subclass) == strupper(item_subclass) then
|
||||
return i
|
||||
end
|
||||
@@ -409,7 +409,7 @@ function public.item_subclass_index(class_index, item_subclass)
|
||||
end
|
||||
|
||||
function public.item_slot_index(class_index, subclass_index, slot_name)
|
||||
for i, slot in ipairs({ GetAuctionInvTypes(class_index, subclass_index) }) do
|
||||
for i, slot in { GetAuctionInvTypes(class_index, subclass_index) } do
|
||||
if strupper(getglobal(slot)) == strupper(slot_name) then
|
||||
return i
|
||||
end
|
||||
|
||||
@@ -91,7 +91,6 @@ function public.write_record(schema, record)
|
||||
local parts = {}
|
||||
for i=3,getn(schema) do
|
||||
local key, type = next(schema[i])
|
||||
aux.log(type, record[key], m.write(type, record[key]))
|
||||
tinsert(parts, m.write(type, record[key]))
|
||||
end
|
||||
return aux.util.join(parts, separator)
|
||||
|
||||
Reference in New Issue
Block a user