big refactoring
This commit is contained in:
+1
-1
@@ -6,10 +6,10 @@
|
||||
module.lua
|
||||
init.lua
|
||||
core.lua
|
||||
util\core.lua
|
||||
control.lua
|
||||
gui.lua
|
||||
|
||||
util\core.lua
|
||||
util\completion.lua
|
||||
util\persistence.lua
|
||||
util\sort.lua
|
||||
|
||||
+15
-15
@@ -16,14 +16,14 @@ _g.aux_characters = {}
|
||||
function LOAD()
|
||||
scan_wdb()
|
||||
|
||||
control.event_listener('MERCHANT_SHOW', on_merchant_show)
|
||||
control.event_listener('MERCHANT_CLOSED', on_merchant_closed)
|
||||
control.event_listener('MERCHANT_UPDATE', on_merchant_update)
|
||||
control.event_listener('BAG_UPDATE', on_bag_update)
|
||||
event_listener('MERCHANT_SHOW', on_merchant_show)
|
||||
event_listener('MERCHANT_CLOSED', on_merchant_closed)
|
||||
event_listener('MERCHANT_UPDATE', on_merchant_update)
|
||||
event_listener('BAG_UPDATE', on_bag_update)
|
||||
|
||||
CreateFrame('Frame', nil, MerchantFrame):SetScript('OnUpdate', merchant_on_update)
|
||||
|
||||
control.event_listener('NEW_AUCTION_UPDATE', function()
|
||||
event_listener('NEW_AUCTION_UPDATE', function()
|
||||
for info in present(info.auction_sell_item()) do
|
||||
for item_id in present(cache.item_id(info.name)) do
|
||||
_g.aux_merchant_sell[cache.item_id(info.name)] = info.vendor_price / (info.max_item_charges(item_id) or info.count)
|
||||
@@ -128,12 +128,12 @@ function merchant_buy_scan()
|
||||
unit_price = min(buy_info.unit_price, new_unit_price)
|
||||
end
|
||||
|
||||
g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
|
||||
_g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
|
||||
unit_price = unit_price,
|
||||
limited = buy_info.limited and new_limited,
|
||||
})
|
||||
else
|
||||
g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
|
||||
_g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
|
||||
unit_price = new_unit_price,
|
||||
limited = new_limited,
|
||||
})
|
||||
@@ -150,7 +150,7 @@ function merchant_sell_scan()
|
||||
for slot in inventory do
|
||||
local item_info = info.container_item(unpack(slot))
|
||||
if item_info then
|
||||
g.aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity
|
||||
_g.aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -162,9 +162,9 @@ function scan_wdb(item_id)
|
||||
while processed <= 100 and item_id <= 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 g.aux_item_ids[strlower(name)] then
|
||||
g.aux_item_ids[strlower(name)] = item_id
|
||||
g.aux_items[item_id] = persistence.write(items_schema, {
|
||||
if name and not _g.aux_item_ids[strlower(name)] then
|
||||
_g.aux_item_ids[strlower(name)] = item_id
|
||||
_g.aux_items[item_id] = persistence.write(items_schema, {
|
||||
name = name,
|
||||
quality = quality,
|
||||
level = level,
|
||||
@@ -176,7 +176,7 @@ function scan_wdb(item_id)
|
||||
})
|
||||
local tooltip = info.tooltip(function(tt) tt:SetHyperlink(itemstring) end)
|
||||
if info.auctionable(tooltip, quality) then
|
||||
tinsert(g.aux_auctionable_items, strlower(name))
|
||||
tinsert(_g.aux_auctionable_items, strlower(name))
|
||||
end
|
||||
processed = processed + 1
|
||||
end
|
||||
@@ -185,9 +185,9 @@ function scan_wdb(item_id)
|
||||
|
||||
if item_id <= MAX_ITEM_ID then
|
||||
local t0 = GetTime()
|
||||
control.thread(control.when, function() return GetTime() - t0 > 0.1 end, scan_wdb, item_id)
|
||||
thread(when, function() return GetTime() - t0 > 0.1 end, scan_wdb, item_id)
|
||||
else
|
||||
sort(g.aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
|
||||
sort(_g.aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -204,5 +204,5 @@ function public.populate_wdb(item_id)
|
||||
AuxTooltip:SetHyperlink('item:'..item_id)
|
||||
end
|
||||
|
||||
control.thread(populate_wdb, item_id + 1)
|
||||
thread(populate_wdb, item_id + 1)
|
||||
end
|
||||
+5
-5
@@ -8,7 +8,7 @@ function process()
|
||||
local stacking_complete
|
||||
|
||||
local send_signal, signal_received = signal()
|
||||
control.when(signal_received, function()
|
||||
when(signal_received, function()
|
||||
local slot = signal_received()[1]
|
||||
if slot then
|
||||
return post_auction(slot, process)
|
||||
@@ -37,13 +37,13 @@ function post_auction(slot, k)
|
||||
StartAuction(max(1, round(state.unit_start_price * item_info.aux_quantity)), round(state.unit_buyout_price * item_info.aux_quantity), state.duration)
|
||||
|
||||
local send_signal, signal_received = signal()
|
||||
control.when(signal_received, function()
|
||||
when(signal_received, function()
|
||||
state.posted = state.posted + 1
|
||||
return k()
|
||||
end)
|
||||
|
||||
local posted
|
||||
control.event_listener('CHAT_MSG_SYSTEM', function(kill)
|
||||
event_listener('CHAT_MSG_SYSTEM', function(kill)
|
||||
if arg1 == ERR_AUCTION_STARTED then
|
||||
send_signal()
|
||||
kill()
|
||||
@@ -56,7 +56,7 @@ end
|
||||
|
||||
function public.stop()
|
||||
if state then
|
||||
control.kill_thread(state.thread_id)
|
||||
kill_thread(state.thread_id)
|
||||
|
||||
local callback = state.callback
|
||||
local posted = state.posted
|
||||
@@ -72,7 +72,7 @@ end
|
||||
function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, callback)
|
||||
stop()
|
||||
|
||||
local thread_id = control.thread(process)
|
||||
local thread_id = thread(process)
|
||||
|
||||
state = {
|
||||
thread_id = thread_id,
|
||||
|
||||
+13
-13
@@ -9,7 +9,7 @@ do
|
||||
for _, old_state in {scan_states[params.type]} do
|
||||
abort(old_state.id)
|
||||
end
|
||||
local thread_id = control.thread(L(wait_for_callback, params.on_scan_start, scan))
|
||||
local thread_id = thread(L(wait_for_callback, params.on_scan_start, scan))
|
||||
scan_states[params.type] = {
|
||||
id = thread_id,
|
||||
params = params,
|
||||
@@ -21,7 +21,7 @@ do
|
||||
local aborted = {}
|
||||
for type, state in scan_states do
|
||||
if not scan_id or state.id == scan_id then
|
||||
control.kill_thread(state.id)
|
||||
kill_thread(state.id)
|
||||
scan_states[type] = nil
|
||||
tinsert(aborted, state)
|
||||
end
|
||||
@@ -38,7 +38,7 @@ do
|
||||
end
|
||||
|
||||
function getter.state()
|
||||
local _, state = next(filter(scan_states, function(state) return state.id == control.thread_id end))
|
||||
local _, state = next(filter(scan_states, function(state) return state.id == thread_id end))
|
||||
return state
|
||||
end
|
||||
end
|
||||
@@ -64,7 +64,7 @@ function wait_for_callback(...)
|
||||
send_signal()
|
||||
end
|
||||
|
||||
return control.when(signal_received, function() return k(unpack(signal_received())) end)
|
||||
return when(signal_received, function() return k(unpack(signal_received())) end)
|
||||
end
|
||||
|
||||
function total_pages(total_auctions)
|
||||
@@ -100,7 +100,7 @@ function process_query()
|
||||
end
|
||||
|
||||
function submit_query()
|
||||
control.when(function() return state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
|
||||
when(function() return state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
|
||||
call(state.params.on_submit_query)
|
||||
state.last_query_time = GetTime()
|
||||
if state.params.type == 'bidder' then
|
||||
@@ -153,9 +153,9 @@ function scan_page(i)
|
||||
|
||||
if call(state.params.auto_buy_validator, auction_info) then
|
||||
local send_signal, signal_received = signal()
|
||||
control.when(signal_received, recurse)
|
||||
when(signal_received, recurse)
|
||||
place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, L(send_signal, true))
|
||||
return control.thread(control.when, later(GetTime(), 10), L(send_signal, false))
|
||||
return thread(when, later(GetTime(), 10), L(send_signal, false))
|
||||
elseif not query.validator or query.validator(auction_info) then
|
||||
return wait_for_callback(state.params.on_auction, auction_info, function(removed)
|
||||
if removed then
|
||||
@@ -173,7 +173,7 @@ end
|
||||
function wait_for_results()
|
||||
local timeout = later(state.last_query_time, 10)
|
||||
local send_signal, signal_received = signal()
|
||||
control.when(signal_received, function()
|
||||
when(signal_received, function()
|
||||
if timeout() then
|
||||
return submit_query()
|
||||
else
|
||||
@@ -188,10 +188,10 @@ function wait_for_results()
|
||||
end
|
||||
end)
|
||||
|
||||
control.thread(control.when, timeout, send_signal)
|
||||
thread(when, timeout, send_signal)
|
||||
|
||||
if state.params.type == 'bidder' then
|
||||
return control.thread(control.when, function() return bids_loaded end, send_signal)
|
||||
return thread(when, function() return bids_loaded end, send_signal)
|
||||
elseif state.params.type == 'owner' then
|
||||
return wait_for_owner_results(send_signal)
|
||||
elseif state.params.type == 'list' then
|
||||
@@ -203,19 +203,19 @@ function wait_for_owner_results(send_signal)
|
||||
if state.page == current_owner_page then
|
||||
return send_signal()
|
||||
else
|
||||
return control.on_next_event('AUCTION_OWNED_LIST_UPDATE', send_signal)
|
||||
return on_next_event('AUCTION_OWNED_LIST_UPDATE', send_signal)
|
||||
end
|
||||
end
|
||||
|
||||
function wait_for_list_results(send_signal, signal_received)
|
||||
local updated, last_update
|
||||
control.event_listener('AUCTION_ITEM_LIST_UPDATE', function(kill)
|
||||
event_listener('AUCTION_ITEM_LIST_UPDATE', function(kill)
|
||||
kill(signal_received())
|
||||
last_update = GetTime()
|
||||
updated = true
|
||||
end)
|
||||
local ignore_owner = state.params.ignore_owner or _g.aux_ignore_owner
|
||||
return control.thread(control.when, function()
|
||||
return thread(when, function()
|
||||
-- short circuiting order important, owner_data_complete must be called iif an update has happened.
|
||||
local ok = updated and (ignore_owner or owner_data_complete('list')) or last_update and GetTime() - last_update > 5
|
||||
updated = false
|
||||
|
||||
@@ -53,7 +53,7 @@ end
|
||||
|
||||
function move_item(from_slot, to_slot, amount, k)
|
||||
if locked(from_slot) or locked(to_slot) then
|
||||
return control.wait(k)
|
||||
return wait(k)
|
||||
end
|
||||
|
||||
amount = min(max_stack(from_slot) - stack_size(to_slot), stack_size(from_slot), amount)
|
||||
@@ -63,7 +63,7 @@ function move_item(from_slot, to_slot, amount, k)
|
||||
SplitContainerItem(from_slot[1], from_slot[2], amount)
|
||||
PickupContainerItem(unpack(to_slot))
|
||||
|
||||
return control.when(function() return stack_size(to_slot) == expected_size end, k)
|
||||
return when(function() return stack_size(to_slot) == expected_size end, k)
|
||||
end
|
||||
|
||||
function process()
|
||||
@@ -105,7 +105,7 @@ end
|
||||
|
||||
function public.stop()
|
||||
if state then
|
||||
control.kill_thread(state.thread_id)
|
||||
kill_thread(state.thread_id)
|
||||
local callback, slot = state.callback, state.target_slot
|
||||
if slot and not matching_item(slot) then
|
||||
slot = nil
|
||||
@@ -118,7 +118,7 @@ end
|
||||
function public.start(item_key, size, callback)
|
||||
stop()
|
||||
|
||||
local thread_id = control.thread(process)
|
||||
local thread_id = thread(process)
|
||||
state = {
|
||||
thread_id = thread_id,
|
||||
item_key = item_key,
|
||||
|
||||
@@ -78,12 +78,12 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
public.orig = setmetatable({_g={}}, {__index=function(self, key) return self[_g][key] end})
|
||||
public.orig = setmetatable({[_g]={}}, {__index=function(self, key) return self[_g][key] end})
|
||||
function public.hook(name, handler, object)
|
||||
handler = handler or getfenv(2)[name]
|
||||
object = object or _g
|
||||
orig[object] = orig[object] or {}
|
||||
assert(not orig[object][name] '"'..name..'" is already hooked into.')
|
||||
assert(not orig[object][name], '"'..name..'" is already hooked into.')
|
||||
orig[object][name], object[name] = object[name], handler
|
||||
end
|
||||
|
||||
@@ -96,7 +96,7 @@ do
|
||||
PlaceAuctionBid(type, index, amount)
|
||||
if money >= amount then
|
||||
locked = true
|
||||
control.event_listener('CHAT_MSG_SYSTEM', function(kill)
|
||||
event_listener('CHAT_MSG_SYSTEM', function(kill)
|
||||
if arg1 == ERR_AUCTION_BID_PLACED then
|
||||
call(on_success)
|
||||
locked = false
|
||||
@@ -114,7 +114,7 @@ do
|
||||
if locked then return end
|
||||
locked = true
|
||||
CancelAuction(index)
|
||||
control.event_listener('CHAT_MSG_SYSTEM', function(kill)
|
||||
event_listener('CHAT_MSG_SYSTEM', function(kill)
|
||||
if arg1 == ERR_AUCTION_REMOVED then
|
||||
call(on_success)
|
||||
locked = false
|
||||
|
||||
@@ -31,6 +31,46 @@ public.config = {
|
||||
huge_font_size = 23,
|
||||
}
|
||||
|
||||
do
|
||||
local function index_handler(self, key)
|
||||
self.private.table = self.private.table[key]
|
||||
if getn(self.private.table) == 0 then
|
||||
return self.public
|
||||
else
|
||||
local color = copy(self.private.table)
|
||||
self.private.table = config.colors
|
||||
return self.private.callback(color)
|
||||
end
|
||||
end
|
||||
function color_accessor(callback)
|
||||
return function()
|
||||
return index_function({callback=callback, table=config.colors}, index_handler)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local mt = {
|
||||
__call = function(self, text)
|
||||
local r, g, b, a = unpack(self)
|
||||
if text then
|
||||
return format('|c%02X%02X%02X%02X', a, r*255, g*255, b*255)..text..FONT_COLOR_CODE_CLOSE
|
||||
else
|
||||
return r, g, b, a
|
||||
end
|
||||
end
|
||||
}
|
||||
public.getter.color = color_accessor(function(color)
|
||||
local r, g, b, a = unpack(color)
|
||||
return setmetatable({r/255, g/255, b/255, a}, mt)
|
||||
end)
|
||||
end
|
||||
|
||||
public.getter.inline_color = color_accessor(function(color)
|
||||
local r, g, b, a = unpack(color)
|
||||
return format('|c%02X%02X%02X%02X', a, r, g, b)
|
||||
end)
|
||||
|
||||
do
|
||||
local id = 0
|
||||
function public.getter.name() id = id + 1; return 'aux_frame'..id end
|
||||
@@ -62,47 +102,6 @@ end
|
||||
|
||||
function LOAD()
|
||||
import :_ 'util'
|
||||
|
||||
do
|
||||
local function index_handler(self, key)
|
||||
self.private.table = self.private.table[key]
|
||||
if getn(self.private.table) == 0 then
|
||||
return self.public
|
||||
else
|
||||
local color = copy(self.private.table)
|
||||
self.private.table = config.colors
|
||||
return self.private.callback(color)
|
||||
end
|
||||
end
|
||||
function color_accessor(callback)
|
||||
return function()
|
||||
return index_function({callback=callback, table=config.colors}, index_handler)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local mt = {
|
||||
__call = function(self, text)
|
||||
local r, g, b, a = unpack(self)
|
||||
if text then
|
||||
return format('|c%02X%02X%02X%02X', a, r*255, g*255, b*255)..text..FONT_COLOR_CODE_CLOSE
|
||||
else
|
||||
return r, g, b, a
|
||||
end
|
||||
end
|
||||
}
|
||||
public.getter.color = color_accessor(function(color)
|
||||
local r, g, b, a = unpack(color)
|
||||
return setmetatable({r/255, g/255, b/255, a}, mt)
|
||||
end)
|
||||
end
|
||||
|
||||
public.getter.inline_color = color_accessor(function(color)
|
||||
local r, g, b, a = unpack(color)
|
||||
return format('|c%02X%02X%02X%02X', a, r, g, b)
|
||||
end)
|
||||
|
||||
initialize_menu()
|
||||
initialize_dropdown()
|
||||
end
|
||||
@@ -415,7 +414,7 @@ function public.editbox(parent)
|
||||
-- editbox:Insert'<ksejfkj>' TODO use insert with special tags to determine cursor position
|
||||
-- or use an overlay with itemlinks
|
||||
if last_click and GetTime() - last_click.t < .5 and x == last_click.x and y == last_click.y then
|
||||
control.thread(function() editbox:HighlightText() end)
|
||||
thread(function() editbox:HighlightText() end)
|
||||
end
|
||||
last_click = {t=GetTime(), x=x, y=y}
|
||||
end)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function INIT()
|
||||
import :_ 'core' :_ 'util'
|
||||
import :_ 'core' :_ 'control' :_ 'util'
|
||||
end
|
||||
|
||||
module 'core'
|
||||
|
||||
+8
-7
@@ -17,15 +17,16 @@ function importer_mt.__call(self, arg1, arg2)
|
||||
name = arg2 or arg1
|
||||
state, module = _state[self], _modules[name]
|
||||
alias, state[self] = state[self] or name, nil
|
||||
if not module then return end
|
||||
if alias == '_' then
|
||||
for key, modifiers in module.metadata do
|
||||
if not state.metadata[key] and mask(PUBLIC, modifiers) ~= 0 then
|
||||
state.metadata[key], state.data[key], state.getters[key], state.setters[key] = modifiers, module.data[key], module.getters[key], module.setters[key]
|
||||
if module then
|
||||
if alias == '_' then
|
||||
for key, modifiers in module.metadata do
|
||||
if not state.metadata[key] and mask(PUBLIC, modifiers) ~= 0 then
|
||||
state.metadata[key], state.data[key], state.getters[key], state.setters[key] = modifiers, module.data[key], module.getters[key], module.setters[key]
|
||||
end
|
||||
end
|
||||
elseif not state.metadata[alias] then
|
||||
state.metadata[alias], state.data[alias] = PRIVATE, module.interface
|
||||
end
|
||||
elseif not state.metadata[alias] then
|
||||
state.metadata[alias], state.data[alias] = PRIVATE, module.interface
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -161,7 +161,7 @@ function start_real_time_scan(query, search, continuation)
|
||||
if search.auto_buy then
|
||||
ctrl.suspend()
|
||||
place_bid('list', auction_record.index, auction_record.buyout_price, L(ctrl.resume, true))
|
||||
control.thread(control.when, later(GetTime(), 10), L(ctrl.resume, false))
|
||||
thread(when, later(GetTime(), 10), L(ctrl.resume, false))
|
||||
else
|
||||
tinsert(new_records, auction_record)
|
||||
end
|
||||
@@ -257,7 +257,7 @@ function start_search(queries, continuation)
|
||||
if search.auto_buy then
|
||||
ctrl.suspend()
|
||||
place_bid('list', auction_record.index, auction_record.buyout_price, L(ctrl.resume, true))
|
||||
control.thread(control.when, later(GetTime(), 10), L(ctrl.resume, false))
|
||||
thread(when, later(GetTime(), 10), L(ctrl.resume, false))
|
||||
elseif getn(search.records) < 1000 then
|
||||
tinsert(search.records, auction_record)
|
||||
if getn(search.records) == 1000 then
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ module 'util'
|
||||
function public.copy(t)
|
||||
local copy = {}
|
||||
for k, v in t do copy[k] = v end
|
||||
setn(getn(t))
|
||||
table.setn(t, getn(t))
|
||||
return copy
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ do
|
||||
local realm, faction
|
||||
|
||||
function LOAD()
|
||||
control.thread(control.when, function() faction = UnitFactionGroup 'player' return faction end, function() end)
|
||||
thread(when, function() faction = UnitFactionGroup 'player' return faction end, function() end)
|
||||
realm = GetCVar 'realmName'
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user