refactoring
This commit is contained in:
+7
-7
@@ -56,11 +56,11 @@ do
|
|||||||
__newindex=function(_, _, value) return f(value) end, __unm=function(self) return self end,
|
__newindex=function(_, _, value) return f(value) end, __unm=function(self) return self end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
local temp, perm = modifier(function(t) transient[t] = true; return t end), modifier(function(t) transient[t] = nil; return t end)
|
local temp, perm = modifier(function(t) transient[t] = true; return setmetatable(t, nil) end), modifier(function(t) transient[t] = nil; return t end)
|
||||||
public.temp() -- TODO or 'auto' 'free' 'release' 'unlock'?
|
public.temp() -- TODO or 'auto' 'free' 'release'?
|
||||||
function accessor() return temp end
|
function accessor() return temp end
|
||||||
function mutator(t) return temp(t) end
|
function mutator(t) return temp(t) end
|
||||||
public.perm() -- TODO or 'persist' 'lock'??
|
public.perm()
|
||||||
function accessor() return perm end
|
function accessor() return perm end
|
||||||
function mutator(t) return perm(t) end
|
function mutator(t) return perm(t) end
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ do
|
|||||||
end
|
end
|
||||||
do
|
do
|
||||||
local mt = collector_mt(function(self, value)
|
local mt = collector_mt(function(self, value)
|
||||||
rawset(self, value, true)
|
self[value] = true
|
||||||
end)
|
end)
|
||||||
function public.accessor.set()
|
function public.accessor.set()
|
||||||
return setmetatable(t, mt)
|
return setmetatable(t, mt)
|
||||||
@@ -97,7 +97,7 @@ do
|
|||||||
local key
|
local key
|
||||||
local mt = collector_mt(function(self, value)
|
local mt = collector_mt(function(self, value)
|
||||||
if key ~= nil then
|
if key ~= nil then
|
||||||
rawset(self, key, value)
|
self[key] = value
|
||||||
key = nil
|
key = nil
|
||||||
else
|
else
|
||||||
key = value
|
key = value
|
||||||
@@ -298,7 +298,7 @@ do
|
|||||||
end
|
end
|
||||||
function ADDON_LOADED.Blizzard_CraftUI()
|
function ADDON_LOADED.Blizzard_CraftUI()
|
||||||
hook('CraftFrame_SetSelection', function(...) temp=arg
|
hook('CraftFrame_SetSelection', function(...) temp=arg
|
||||||
local results = {orig.CraftFrame_SetSelection(unpack(arg))}
|
local results = temp-{orig.CraftFrame_SetSelection(unpack(arg))}
|
||||||
local id = GetCraftSelectionIndex()
|
local id = GetCraftSelectionIndex()
|
||||||
local reagent_count = GetCraftNumReagents(id)
|
local reagent_count = GetCraftNumReagents(id)
|
||||||
local total_cost = 0
|
local total_cost = 0
|
||||||
@@ -325,7 +325,7 @@ do
|
|||||||
end
|
end
|
||||||
function ADDON_LOADED.Blizzard_TradeSkillUI()
|
function ADDON_LOADED.Blizzard_TradeSkillUI()
|
||||||
hook('TradeSkillFrame_SetSelection', function(...) temp=arg
|
hook('TradeSkillFrame_SetSelection', function(...) temp=arg
|
||||||
local results = {orig.TradeSkillFrame_SetSelection(unpack(arg))}
|
local results = temp-{orig.TradeSkillFrame_SetSelection(unpack(arg))}
|
||||||
local id = GetTradeSkillSelectionIndex()
|
local id = GetTradeSkillSelectionIndex()
|
||||||
local reagent_count = GetTradeSkillNumReagents(id)
|
local reagent_count = GetTradeSkillNumReagents(id)
|
||||||
local total_cost = 0
|
local total_cost = 0
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module 'auction_listing' import 'gui'
|
module 'auction_listing' import 'gui' 'sorting' 'history' 'money'
|
||||||
|
|
||||||
_g.aux_price_per_unit = false
|
_g.aux_price_per_unit = false
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -3,7 +3,7 @@ module 'post_tab' import 'scan' 'post' 'info'
|
|||||||
local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440
|
local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440
|
||||||
local settings_schema = {'record', '#', {stack_size='number'}, {duration='number'}, {start_price='number'}, {buyout_price='number'}, {hidden='boolean'}}
|
local settings_schema = {'record', '#', {stack_size='number'}, {duration='number'}, {start_price='number'}, {buyout_price='number'}, {hidden='boolean'}}
|
||||||
|
|
||||||
existing_auctions = {}
|
existing_auctions = t
|
||||||
mutable.inventory_records = nil
|
mutable.inventory_records = nil
|
||||||
mutable.scan_id = 0
|
mutable.scan_id = 0
|
||||||
mutable.selected_item = nil
|
mutable.selected_item = nil
|
||||||
@@ -35,7 +35,7 @@ function USE_ITEM(item_info)
|
|||||||
select_item(item_info.item_key)
|
select_item(item_info.item_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
function default_settings()
|
function accessor.default_settings()
|
||||||
return {
|
return {
|
||||||
duration = DURATION_8,
|
duration = DURATION_8,
|
||||||
stack_size = 1,
|
stack_size = 1,
|
||||||
@@ -48,13 +48,13 @@ end
|
|||||||
function read_settings(item_key)
|
function read_settings(item_key)
|
||||||
item_key = item_key or selected_item.key
|
item_key = item_key or selected_item.key
|
||||||
local dataset = persistence.load_dataset()
|
local dataset = persistence.load_dataset()
|
||||||
dataset.post = dataset.post or {}
|
dataset.post = dataset.post or t
|
||||||
|
|
||||||
local settings
|
local settings
|
||||||
if dataset.post[item_key] then
|
if dataset.post[item_key] then
|
||||||
settings = persistence.read(settings_schema, dataset.post[item_key])
|
settings = persistence.read(settings_schema, dataset.post[item_key])
|
||||||
else
|
else
|
||||||
settings = default_settings()
|
settings = default_settings
|
||||||
end
|
end
|
||||||
return settings
|
return settings
|
||||||
end
|
end
|
||||||
@@ -63,7 +63,7 @@ function write_settings(settings, item_key)
|
|||||||
item_key = item_key or selected_item.key
|
item_key = item_key or selected_item.key
|
||||||
|
|
||||||
local dataset = persistence.load_dataset()
|
local dataset = persistence.load_dataset()
|
||||||
dataset.post = dataset.post or {}
|
dataset.post = dataset.post or t
|
||||||
|
|
||||||
dataset.post[item_key] = persistence.write(settings_schema, settings)
|
dataset.post[item_key] = persistence.write(settings_schema, settings)
|
||||||
end
|
end
|
||||||
@@ -96,12 +96,12 @@ end
|
|||||||
|
|
||||||
function update_auction_listing()
|
function update_auction_listing()
|
||||||
if not ACTIVE then return end
|
if not ACTIVE then return end
|
||||||
local auction_rows = {}
|
local auction_rows = t
|
||||||
if selected_item then
|
if selected_item then
|
||||||
local unit_start_price = get_unit_start_price()
|
local unit_start_price = get_unit_start_price()
|
||||||
local unit_buyout_price = get_unit_buyout_price()
|
local unit_buyout_price = get_unit_buyout_price()
|
||||||
|
|
||||||
for i, auction_record in existing_auctions[selected_item.key] or {} do
|
for i, auction_record in existing_auctions[selected_item.key] or tt do
|
||||||
|
|
||||||
local blizzard_bid_undercut, buyout_price_undercut = undercut(auction_record, stack_size_slider:GetValue())
|
local blizzard_bid_undercut, buyout_price_undercut = undercut(auction_record, stack_size_slider:GetValue())
|
||||||
blizzard_bid_undercut = money.from_string(money.to_string(blizzard_bid_undercut, true, nil, 3))
|
blizzard_bid_undercut = money.from_string(money.to_string(blizzard_bid_undercut, true, nil, 3))
|
||||||
@@ -345,7 +345,7 @@ end
|
|||||||
|
|
||||||
function unit_vendor_price(item_key)
|
function unit_vendor_price(item_key)
|
||||||
|
|
||||||
for slot in info.inventory do
|
for slot in info.inventory do temp=slot
|
||||||
|
|
||||||
local item_info = info.container_item(unpack(slot))
|
local item_info = info.container_item(unpack(slot))
|
||||||
if item_info and item_info.item_key == item_key then
|
if item_info and item_info.item_key == item_key then
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module 'search_tab' import 'scan'
|
module 'search_tab' import 'scan' 'scan_util'
|
||||||
|
|
||||||
StaticPopupDialogs['AUX_SEARCH_TABLE_FULL'] = {
|
StaticPopupDialogs['AUX_SEARCH_TABLE_FULL'] = {
|
||||||
text = 'Table full!\nFurther results from this search will still be processed but no longer displayed in the table.',
|
text = 'Table full!\nFurther results from this search will still be processed but no longer displayed in the table.',
|
||||||
|
|||||||
+3
-3
@@ -19,14 +19,14 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local formal_parameters = {}
|
local formal_parameters = t
|
||||||
for i=1,9 do
|
for i=1,9 do
|
||||||
local key = '_'..i
|
local key = '_'..i
|
||||||
public[key] = {}
|
public[key] = t
|
||||||
formal_parameters[_m[key]] = i
|
formal_parameters[_m[key]] = i
|
||||||
end
|
end
|
||||||
local function helper(f, arg1, arg2)
|
local function helper(f, arg1, arg2)
|
||||||
local params = {}
|
local params = t
|
||||||
for i=1,arg1.n do
|
for i=1,arg1.n do
|
||||||
if formal_parameters[arg1[i]] then
|
if formal_parameters[arg1[i]] then
|
||||||
tinsert(params, arg2[formal_parameters[arg1[i]]])
|
tinsert(params, arg2[formal_parameters[arg1[i]]])
|
||||||
|
|||||||
+19
-22
@@ -33,7 +33,7 @@ do
|
|||||||
INVTYPE_TABARD = {19},
|
INVTYPE_TABARD = {19},
|
||||||
}
|
}
|
||||||
function public.inventory_index(slot)
|
function public.inventory_index(slot)
|
||||||
return unpack(inventory_index_map[slot] or {})
|
return unpack(inventory_index_map[slot] or tt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ function public.set_shopping_tooltip(slot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if tooltips[1] then
|
if tooltips[1] then
|
||||||
tinsert(tooltips[1], 1, {left_text='Currently Equipped', left_color={ 0.5, 0.5, 0.5 }})
|
tinsert(tooltips[1], 1, temp-object :left_text 'Currently Equipped' :left_color(temp-{.5, .5, .5}))
|
||||||
ShoppingTooltip1:SetOwner(GameTooltip, 'ANCHOR_BOTTOMRIGHT')
|
ShoppingTooltip1:SetOwner(GameTooltip, 'ANCHOR_BOTTOMRIGHT')
|
||||||
load_tooltip(ShoppingTooltip1, tooltips[1])
|
load_tooltip(ShoppingTooltip1, tooltips[1])
|
||||||
ShoppingTooltip1:Show()
|
ShoppingTooltip1:Show()
|
||||||
@@ -199,7 +199,7 @@ function public.set_shopping_tooltip(slot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if tooltips[2] then
|
if tooltips[2] then
|
||||||
tinsert(tooltips[2], 1, {left_text='Currently Equipped', left_color={ 0.5, 0.5, 0.5 }})
|
tinsert(tooltips[2], 1, temp-object :left_text 'Currently Equipped' :left_color(temp-{.5, .5, .5}))
|
||||||
ShoppingTooltip2:SetOwner(ShoppingTooltip1, 'ANCHOR_BOTTOMRIGHT')
|
ShoppingTooltip2:SetOwner(ShoppingTooltip1, 'ANCHOR_BOTTOMRIGHT')
|
||||||
load_tooltip(ShoppingTooltip2, tooltips[2])
|
load_tooltip(ShoppingTooltip2, tooltips[2])
|
||||||
ShoppingTooltip2:Show()
|
ShoppingTooltip2:Show()
|
||||||
@@ -237,7 +237,7 @@ function public.load_tooltip(frame, tooltip)
|
|||||||
frame:AddLine(line.left_text, line.left_color[1], line.left_color[2], line.left_color[3], true)
|
frame:AddLine(line.left_text, line.left_color[1], line.left_color[2], line.left_color[3], true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i =1,getn(tooltip) do -- TODO why is this needed?
|
for i=1,getn(tooltip) do -- TODO why is this needed?
|
||||||
_g[frame:GetName()..'TextLeft'..i]:SetJustifyH('LEFT')
|
_g[frame:GetName()..'TextLeft'..i]:SetJustifyH('LEFT')
|
||||||
_g[frame:GetName()..'TextRight'..i]:SetJustifyH('LEFT')
|
_g[frame:GetName()..'TextRight'..i]:SetJustifyH('LEFT')
|
||||||
end
|
end
|
||||||
@@ -357,24 +357,22 @@ end
|
|||||||
|
|
||||||
function public.item(item_id, suffix_id)
|
function public.item(item_id, suffix_id)
|
||||||
local itemstring = 'item:'..(item_id or 0)..':0:'..(suffix_id or 0)..':0'
|
local itemstring = 'item:'..(item_id or 0)..':0:'..(suffix_id or 0)..':0'
|
||||||
for name, itemstring, quality, level, class, subclass, max_stack, slot, texture in present(GetItemInfo(itemstring)) do
|
local name, itemstring, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring)
|
||||||
return {
|
return name and {
|
||||||
name = name,
|
name = name,
|
||||||
itemstring = itemstring,
|
itemstring = itemstring,
|
||||||
quality = quality,
|
quality = quality,
|
||||||
level = level,
|
level = level,
|
||||||
class = class,
|
class = class,
|
||||||
subclass = subclass,
|
subclass = subclass,
|
||||||
slot = slot,
|
slot = slot,
|
||||||
max_stack = max_stack,
|
max_stack = max_stack,
|
||||||
texture = texture,
|
texture = texture,
|
||||||
}
|
} or cache.item_info(item_id)
|
||||||
end
|
|
||||||
return cache.item_info(item_id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.item_class_index(item_class)
|
function public.item_class_index(item_class)
|
||||||
for i, class in {GetAuctionItemClasses()} do
|
for i, class in temp-{GetAuctionItemClasses()} do
|
||||||
if strupper(class) == strupper(item_class) then
|
if strupper(class) == strupper(item_class) then
|
||||||
return i, class
|
return i, class
|
||||||
end
|
end
|
||||||
@@ -382,7 +380,7 @@ function public.item_class_index(item_class)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function public.item_subclass_index(class_index, item_subclass)
|
function public.item_subclass_index(class_index, item_subclass)
|
||||||
for i, subclass in {GetAuctionItemSubClasses(class_index)} do
|
for i, subclass in temp-{GetAuctionItemSubClasses(class_index)} do
|
||||||
if strupper(subclass) == strupper(item_subclass) then
|
if strupper(subclass) == strupper(item_subclass) then
|
||||||
return i, subclass
|
return i, subclass
|
||||||
end
|
end
|
||||||
@@ -390,7 +388,7 @@ function public.item_subclass_index(class_index, item_subclass)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function public.item_slot_index(class_index, subclass_index, slot_name)
|
function public.item_slot_index(class_index, subclass_index, slot_name)
|
||||||
for i, slot in {GetAuctionInvTypes(class_index, subclass_index)} do
|
for i, slot in temp-{GetAuctionInvTypes(class_index, subclass_index)} do
|
||||||
if strupper(_g[slot]) == strupper(slot_name) then
|
if strupper(_g[slot]) == strupper(slot_name) then
|
||||||
return i, _g[slot]
|
return i, _g[slot]
|
||||||
end
|
end
|
||||||
@@ -424,7 +422,6 @@ function public.bag_type(bag)
|
|||||||
for link in present(GetInventoryItemLink('player', ContainerIDToInventoryID(bag))) do
|
for link in present(GetInventoryItemLink('player', ContainerIDToInventoryID(bag))) do
|
||||||
local item_id = parse_link(link)
|
local item_id = parse_link(link)
|
||||||
local item_info = item(item_id)
|
local item_info = item(item_id)
|
||||||
log(link, item_id, item_info, item_info.subclass)
|
|
||||||
return item_subclass_index(3, item_info.subclass)
|
return item_subclass_index(3, item_info.subclass)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
+10
-15
@@ -1,4 +1,4 @@
|
|||||||
module 'scan_util'
|
module 'scan_util' import 'info'
|
||||||
|
|
||||||
function public.find(auction_record, status_bar, on_abort, on_failure, on_success)
|
function public.find(auction_record, status_bar, on_abort, on_failure, on_success)
|
||||||
|
|
||||||
@@ -15,17 +15,13 @@ function public.find(auction_record, status_bar, on_abort, on_failure, on_succes
|
|||||||
local blizzard_query1 = copy(auction_record.blizzard_query)
|
local blizzard_query1 = copy(auction_record.blizzard_query)
|
||||||
blizzard_query1.first_page = auction_record.page
|
blizzard_query1.first_page = auction_record.page
|
||||||
blizzard_query1.last_page = auction_record.page
|
blizzard_query1.last_page = auction_record.page
|
||||||
tinsert(queries, {
|
tinsert(queries, -object :blizzard_query(blizzard_query1))
|
||||||
blizzard_query = blizzard_query1,
|
|
||||||
})
|
|
||||||
|
|
||||||
if auction_record.page > 0 then
|
if auction_record.page > 0 then
|
||||||
local blizzard_query2 = copy(auction_record.blizzard_query)
|
local blizzard_query2 = copy(auction_record.blizzard_query)
|
||||||
blizzard_query2.first_page = auction_record.page - 1
|
blizzard_query2.first_page = auction_record.page - 1
|
||||||
blizzard_query2.last_page = auction_record.page - 1
|
blizzard_query2.last_page = auction_record.page - 1
|
||||||
tinsert(queries, {
|
tinsert(queries, -object :blizzard_query(blizzard_query2))
|
||||||
blizzard_query = blizzard_query1,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local item_query = item_query(auction_record.item_id, 1, 1)
|
local item_query = item_query(auction_record.item_id, 1, 1)
|
||||||
@@ -41,7 +37,7 @@ function public.find(auction_record, status_bar, on_abort, on_failure, on_succes
|
|||||||
queries = queries,
|
queries = queries,
|
||||||
on_scan_start = function()
|
on_scan_start = function()
|
||||||
status_bar:update_status(0, 0)
|
status_bar:update_status(0, 0)
|
||||||
status_bar:set_text('Searching auction...')
|
status_bar:set_text 'Searching auction...'
|
||||||
end,
|
end,
|
||||||
on_start_query = function(query_index)
|
on_start_query = function(query_index)
|
||||||
status_bar:update_status((query_index - 1) / getn(queries) * 100, 0)
|
status_bar:update_status((query_index - 1) / getn(queries) * 100, 0)
|
||||||
@@ -51,20 +47,20 @@ function public.find(auction_record, status_bar, on_abort, on_failure, on_succes
|
|||||||
found = true
|
found = true
|
||||||
ctrl.suspend()
|
ctrl.suspend()
|
||||||
status_bar:update_status(100, 100)
|
status_bar:update_status(100, 100)
|
||||||
status_bar:set_text('Auction found')
|
status_bar:set_text 'Auction found'
|
||||||
return on_success(auction_record.index)
|
return on_success(auction_record.index)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_abort = function()
|
on_abort = function()
|
||||||
if not found then
|
if not found then
|
||||||
status_bar:update_status(100, 100)
|
status_bar:update_status(100, 100)
|
||||||
status_bar:set_text('Auction not found')
|
status_bar:set_text 'Auction not found'
|
||||||
return on_abort()
|
return on_abort()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_complete = function()
|
on_complete = function()
|
||||||
status_bar:update_status(100, 100)
|
status_bar:update_status(100, 100)
|
||||||
status_bar:set_text('Auction not found')
|
status_bar:set_text 'Auction not found'
|
||||||
return on_failure()
|
return on_failure()
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
@@ -78,9 +74,8 @@ function public.item_query(item_id, first_page, last_page)
|
|||||||
local query = filter_util.query(item_info.name..'/exact')
|
local query = filter_util.query(item_info.name..'/exact')
|
||||||
query.blizzard_query.first_page = first_page
|
query.blizzard_query.first_page = first_page
|
||||||
query.blizzard_query.last_page = last_page
|
query.blizzard_query.last_page = last_page
|
||||||
return {
|
return -object
|
||||||
validator = query.validator,
|
:validator(query.validator)
|
||||||
blizzard_query = query.blizzard_query,
|
:blizzard_query(query.blizzard_query)
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user