big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-21 11:51:11 +02:00
parent 2fe6ff2556
commit c08c990ff3
3 changed files with 210 additions and 203 deletions
+2 -4
View File
@@ -25,12 +25,10 @@ end
do
local modules = {}
local function module_env(name) aux_module(name) return getfenv() end
local function module_env(name) aux_module(name) return m end
function public.module(name)
local env = module_env(name)
if not modules[name] then
env.import(temp-{modules='', core='', util=''})
end
if not modules[name] then env.import(temp-{['']='modules', ['']='core', ['']='util'}) end
setfenv(2, env)
modules[name] = true
end
+64 -55
View File
@@ -1,46 +1,52 @@
local type, setmetatable, unpack, mask, g = type, setmetatable, unpack, bit.band, getfenv(0)
local type, setmetatable, setfenv, unpack, mask, g = type, setmetatable, setfenv, unpack, bit.band, getfenv(0)
local PRIVATE, PUBLIC, GETTER, SETTER, MUTABLE = 0, 1, 2, 4, 8
local MODIFIER = {private=PRIVATE, public=PUBLIC, getter=GETTER, setter=SETTER, mutable=MUTABLE}
local MASK = {private=MUTABLE+GETTER+SETTER, public=MUTABLE+GETTER+SETTER, getter=PRIVATE+PUBLIC+SETTER, setter=PRIVATE+PUBLIC+GETTER, mutable=PRIVATE+PUBLIC}
local import, declarator_mt, env_mt, interface_mt, lock_mt
local initialize_declarator, error
local _modules, _metadata, _data, _getters, _setters, _imports, _declarators, _declarator_state = setmetatable({}, lock_mt), {}, {}, {}, {}, {}, {}, {}
local import, initialize_declarator, error, modules_mt, module_mt, env_mt, interface_mt, declarator_mt
local _state, _lock_metatables = {}, {}
function error(message, ...) g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), 3) end
function import(imports, t) for k, v in t do imports[type(k) == 'number' and v or k] = v end end
--function lock_metatable()
-- local mt = {__metatable=false}
-- tinsert(mt, _lock_metatables)
-- return mt
--end
declarator_mt = {__metatable=false}
do
local function define_property(self, key, t)
local getter, setter = t.get, t.set
_metadata[self][key] = mask(PRIVATE+PUBLIC, _declarator_state[self])
+ (getter ~= nil and (type(getter) == 'function' or error('Getter "%s" is not a function.', key)) and GETTER or 0)
+ (setter ~= nil and (type(setter) == 'function' or error('Setter "%s" is not a function.', key)) and SETTER or 0)
_getters[self][key], _setters[self][key] = getter, setter
local state, getter, setter = _state[self], t.get, t.set
state.metadata[key] = mask(PRIVATE+PUBLIC, state.modifiers)
+ (getter ~= nil and (type(getter) == 'function' or error('Getter must be a function.')) and GETTER or 0)
+ (setter ~= nil and (type(setter) == 'function' or error('Setter must be function.')) and SETTER or 0)
state.getters[key], state.setters[key] = getter, setter
end
function declarator_mt.__index(self, key)
local modifier = MODIFIER[key]
local state, modifier = _state[self], MODIFIER[key]
if not modifier then return function(t) define_property(self, key, t) end end
_declarator_state[self] = modifier + mask(MASK[key], _declarator_state[self])
state.modifiers = modifier + mask(MASK[key], state.modifiers)
return self
end
end
function declarator_mt.__newindex(self, key, value)
local modifiers = _declarator_state[self]
local state = _state[self]
local modifiers = state.modifiers
if modifiers then error('Field "%s" already exists.', key) end
_metadata[self][key] = modifiers
state.metadata[key] = modifiers
if mask(GETTER+SETTER, modifiers) == 0 then
_data[self][key] = value
state.data[self][key] = value
elseif type(value) == 'function' or error('Getters/setters must be functions.') then
_getters[self][key], _setters[self][key] = value, value
state.getters[key], state.setters[key] = value, value
end
end
do
local function index(access, default)
return function(self, key)
local modifiers = _metadata[self][key] or 0
local state = _state[self]
local modifiers = state.modifiers
if mask(access+GETTER+SETTER, modifiers) == access then
return _data[self][key]
return state.data[key]
elseif mask(access+GETTER, modifiers) == access+GETTER then
return _getters[self][key]()
return state.getters[key]()
else
return default[key] or error('No field "%s".', key)
end
@@ -48,46 +54,46 @@ do
end
env_mt = {__metatable=false, __index=index(PRIVATE, g)}
function env_mt.__newindex(self, key, value)
if not _metadata[self][key] then
_metadata[self][key] = PRIVATE
elseif mask(SETTER, _metadata[self][key]) ~= 0 then
return _setters[self][key](value)
elseif mask(MUTABLE, _metadata[self][key]) == 0 then
local state = _state[self]
if not state.metadata[key] then
state.metadata[key] = PRIVATE
elseif mask(SETTER, state.metadata[key]) ~= 0 then
return state.setters[key](value)
elseif mask(MUTABLE, state.metadata[key]) == 0 then
error('Field "%s" is immutable.', key)
end
_data[self][key] = value
state.data[key] = value
end
interface_mt = {__metatable=false, __index=index(PUBLIC, {})}
function interface_mt.__newindex(self, key, value)
if mask(PUBLIC+SETTER, _metadata[self][key]) == PUBLIC+SETTER then
return _setters[self][key](value)
elseif mask(PUBLIC+MUTABLE, _metadata[self][key]) == PUBLIC+MUTABLE or error('Field "%s" is immutable.', key) then
_data[self][key] = value
local state = _state[self]
if mask(PUBLIC+SETTER, state.metadata[key]) == PUBLIC+SETTER then
return state.setters[key][key](value)
elseif mask(PUBLIC+MUTABLE, state.metadata[key]) == PUBLIC+MUTABLE or error('Field "%s" is immutable.', key) then
state.data[key] = value
end
end
end
lock_mt = {}
function g.aux_module(name)
if not _modules[name] then
local metadata, data, getters, setters, imports, declarator, env, interface
imports, declarator, env, interface = {}, setmetatable({}, declarator_mt), setmetatable({}, env_mt), setmetatable({}, interface_mt)
metadata = setmetatable({g=PRIVATE, m=PRIVATE, import=PRIVATE, private=GETTER, public=GETTER, getter=GETTER, setter=GETTER, mutable=GETTER}, lock_mt)
data = {g=g, m=env, import=function(t) import(imports, t) end}
getters = {
private=function() _declarator_state[declarator] = PRIVATE return declarator end, public=function() _declarator_state[declarator] = PUBLIC return declarator end,
getter=function() _declarator_state[declarator] = GETTER return declarator end, setter=function() _declarator_state[declarator] = SETTER return declarator end,
mutable=function() _declarator_state[declarator] = MUTABLE return declarator end,
if not _state[name] then
local state, declarator, env, interface, imports
env, interface, declarator, imports = setmetatable({}, env_mt), setmetatable({}, interface_mt), setmetatable({}, declarator_mt), {}
state = {
name = name, env = env, interface = interface, declarator = declarator, imports = {}, declarator_state = 0,
metadata={_g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=GETTER, public=GETTER, getter=GETTER, setter=GETTER, mutable=GETTER},
data = {_g=g, _m=env, _i=interface, import=function(t) import(imports, t) end},
getters = {
private=function() state.modifiers = PRIVATE return declarator end, public=function() state.modifiers = PUBLIC return declarator end,
getter=function() state.modifiers = GETTER return declarator end, setter=function() state.modifiers = SETTER return declarator end,
mutable=function() state.modifiers = MUTABLE return declarator end,
},
setters = {},
}
setters = {}
_metadata[name], _metadata[declarator], _metadata[env], _metadata[interface] = metadata, metadata, metadata, metadata
_data[name], _data[declarator], _data[env], _data[interface] = data, data, data, data
_getters[name], _getters[declarator], _getters[env], _getters[interface] = getters, getters, getters, getters
_setters[name], _setters[declarator], _setters[env], _setters[interface] = setters, setters, setters, setters
_modules[name], _imports[name], _declarators[name] = {env, interface}, imports, declarator
_state[name], _state[env], _state[interface], _state[declarator] = state, state, state, state
end
local env, interface = unpack(_modules[name])
setfenv(2, env)
return interface
local state = (_state[name])
setfenv(2, state.env)
return state
end
local frame = CreateFrame 'Frame'
frame:RegisterEvent 'PLAYER_LOGIN'
@@ -95,21 +101,24 @@ frame:SetScript('OnEvent', function()
lock_mt.__newindex = function() error 'Cannot change modules after the loading phase.' end
local count = 0
local t0 = GetTime()
for name in _modules do
local declarator = _declarators[name]
for import, v in _imports[name] do
if not _modules[import] then error('Invalid import "%s" in module "%s".', import, name) end
if v == '' then
local data = _data[import]
for key, modifiers in _metadata[import] do
for name, module in _state do
local data, metadata, getters, setters = module.data, module.metadata, module.getters, module.setters
for alias, name in _imports[name] do
local import = _state[name]
if not import then error('Import failed. No module "%s".', name) end
local import_data, import_getters, import_setters = import.data
if alias == '' then
for key, modifiers in import.metadata do
if mask(PUBLIC, modifiers) ~= 0 then
if mask(GETTER+SETTER, modifiers) ~= 0 then
count = count + 1
_declarator_state[declarator] = modifiers
declarator[key] = data[key]
end
end
else
declarator[v] = import
declarator[alias] = module.interface
end
end
end
+144 -144
View File
@@ -10,30 +10,30 @@ scan_id = 0
selected_item = nil
refresh = nil
function m.LOAD()
m.create_frames()
function LOAD()
create_frames()
end
function m.OPEN()
m.frame:Show()
function OPEN()
frame:Show()
m.deposit:SetText('Deposit: '..money.to_string(0, nil, nil, nil, gui.inline_color.text.enabled))
deposit:SetText('Deposit: '..money.to_string(0, nil, nil, nil, gui.inline_color.text.enabled))
m.set_unit_start_price(0)
m.set_unit_buyout_price(0)
set_unit_start_price(0)
set_unit_buyout_price(0)
m.update_inventory_records()
update_inventory_records()
m.refresh = true
refresh = true
end
function m.CLOSE()
m.selected_item = nil
m.frame:Hide()
function CLOSE()
selected_item = nil
frame:Hide()
end
function m.USE_ITEM(item_info)
m.select_item(item_info.item_key)
function USE_ITEM(item_info)
select_item(item_info.item_key)
end
function default_settings()
@@ -47,7 +47,7 @@ function default_settings()
end
function read_settings(item_key)
item_key = item_key or m.selected_item.key
item_key = item_key or selected_item.key
local dataset = persistence.load_dataset()
dataset.post = dataset.post or {}
@@ -55,13 +55,13 @@ function read_settings(item_key)
if dataset.post[item_key] then
settings = persistence.read(settings_schema, dataset.post[item_key])
else
settings = m.default_settings()
settings = default_settings()
end
return settings
end
function write_settings(settings, item_key)
item_key = item_key or m.selected_item.key
item_key = item_key or selected_item.key
local dataset = persistence.load_dataset()
dataset.post = dataset.post or {}
@@ -70,50 +70,50 @@ function write_settings(settings, item_key)
end
function get_unit_start_price()
local money_text = m.unit_start_price:GetText()
local money_text = unit_start_price:GetText()
return money.from_string(money_text) or 0
end
function set_unit_start_price(amount)
m.unit_start_price:SetText(money.to_string(amount, true, nil, 3))
unit_start_price:SetText(money.to_string(amount, true, nil, 3))
end
function get_unit_buyout_price()
local money_text = m.unit_buyout_price:GetText()
local money_text = unit_buyout_price:GetText()
return money.from_string(money_text) or 0
end
function set_unit_buyout_price(amount)
m.unit_buyout_price:SetText(money.to_string(amount, true, nil, 3))
unit_buyout_price:SetText(money.to_string(amount, true, nil, 3))
end
function update_inventory_listing()
if not ACTIVE then return end
item_listing.populate(m.item_listing, values(filter(m.inventory_records, function(record)
local settings = m.read_settings(record.key)
return record.aux_quantity > 0 and (not settings.hidden or m.show_hidden_checkbox:GetChecked())
item_listing.populate(item_listing, values(filter(inventory_records, function(record)
local settings = read_settings(record.key)
return record.aux_quantity > 0 and (not settings.hidden or show_hidden_checkbox:GetChecked())
end)))
end
function update_auction_listing()
if not ACTIVE then return end
local auction_rows = {}
if m.selected_item then
local unit_start_price = m.get_unit_start_price()
local unit_buyout_price = m.get_unit_buyout_price()
if selected_item then
local unit_start_price = get_unit_start_price()
local unit_buyout_price = get_unit_buyout_price()
for i, auction_record in m.existing_auctions[m.selected_item.key] or {} do
for i, auction_record in existing_auctions[selected_item.key] or {} do
local blizzard_bid_undercut, buyout_price_undercut = m.undercut(auction_record, m.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))
buyout_price_undercut = money.from_string(money.to_string(buyout_price_undercut, true, nil, 3))
local stack_blizzard_bid_undercut, stack_buyout_price_undercut = m.undercut(auction_record, m.stack_size_slider:GetValue(), true)
local stack_blizzard_bid_undercut, stack_buyout_price_undercut = undercut(auction_record, stack_size_slider:GetValue(), true)
stack_blizzard_bid_undercut = money.from_string(money.to_string(stack_blizzard_bid_undercut, true, nil, 3))
stack_buyout_price_undercut = money.from_string(money.to_string(stack_buyout_price_undercut, true, nil, 3))
local stack_size = m.stack_size_slider:GetValue()
local historical_value = history.value(m.selected_item.key)
local stack_size = stack_size_slider:GetValue()
local historical_value = history.value(selected_item.key)
local bid_color
if blizzard_bid_undercut < unit_start_price and stack_blizzard_bid_undercut < unit_start_price then
@@ -165,45 +165,45 @@ function update_auction_listing()
)
end)
end
m.auction_listing:SetData(auction_rows)
auction_listing:SetData(auction_rows)
end
function public.select_item(item_key)
for _, inventory_record in filter(m.inventory_records, function(record) return record.aux_quantity > 0 end) do
for _, inventory_record in filter(inventory_records, function(record) return record.aux_quantity > 0 end) do
if inventory_record.key == item_key then
m.set_item(inventory_record)
set_item(inventory_record)
break
end
end
end
function price_update()
if m.selected_item then
local settings = m.read_settings()
if selected_item then
local settings = read_settings()
local start_price_input = m.get_unit_start_price()
local start_price_input = get_unit_start_price()
settings.start_price = start_price_input
local historical_value = history.value(m.selected_item.key)
m.start_price_percentage:SetText(historical_value and auction_listing.percentage_historical(round(start_price_input / historical_value * 100)) or '---')
local historical_value = history.value(selected_item.key)
start_price_percentage:SetText(historical_value and auction_listing.percentage_historical(round(start_price_input / historical_value * 100)) or '---')
local buyout_price_input = m.get_unit_buyout_price()
local buyout_price_input = get_unit_buyout_price()
settings.buyout_price = buyout_price_input
local historical_value = history.value(m.selected_item.key)
m.buyout_price_percentage:SetText(historical_value and auction_listing.percentage_historical(round(buyout_price_input / historical_value * 100)) or '---')
local historical_value = history.value(selected_item.key)
buyout_price_percentage:SetText(historical_value and auction_listing.percentage_historical(round(buyout_price_input / historical_value * 100)) or '---')
m.write_settings(settings)
write_settings(settings)
end
end
function post_auctions()
if m.selected_item then
local unit_start_price = m.get_unit_start_price()
local unit_buyout_price = m.get_unit_buyout_price()
local stack_size = m.stack_size_slider:GetValue()
if selected_item then
local unit_start_price = get_unit_start_price()
local unit_buyout_price = get_unit_buyout_price()
local stack_size = stack_size_slider:GetValue()
local stack_count
stack_count = m.stack_count_slider:GetValue()
local duration = UIDropDownMenu_GetSelectedValue(m.duration_dropdown)
local key = m.selected_item.key
stack_count = stack_count_slider:GetValue()
local duration = UIDropDownMenu_GetSelectedValue(duration_dropdown)
local key = selected_item.key
local duration_code
if duration == DURATION_4 then
@@ -224,18 +224,18 @@ function post_auctions()
function(posted)
local new_auction_record
for i=1,posted do
new_auction_record = m.record_auction(key, stack_size, unit_start_price, unit_buyout_price, duration_code, UnitName('player'))
new_auction_record = record_auction(key, stack_size, unit_start_price, unit_buyout_price, duration_code, UnitName('player'))
end
m.update_inventory_records()
m.selected_item = nil
for _, record in m.inventory_records do
update_inventory_records()
selected_item = nil
for _, record in inventory_records do
if record.key == key then
m.set_item(record)
set_item(record)
end
end
m.refresh = true
refresh = true
end
)
end
@@ -243,27 +243,27 @@ end
function validate_parameters()
if not m.selected_item then
m.post_button:Disable()
if not selected_item then
post_button:Disable()
return
end
if m.get_unit_buyout_price() > 0 and m.get_unit_start_price() > m.get_unit_buyout_price() then
m.post_button:Disable()
if get_unit_buyout_price() > 0 and get_unit_start_price() > get_unit_buyout_price() then
post_button:Disable()
return
end
if m.get_unit_start_price() == 0 then
m.post_button:Disable()
if get_unit_start_price() == 0 then
post_button:Disable()
return
end
if m.stack_count_slider:GetValue() == 0 then
m.post_button:Disable()
if stack_count_slider:GetValue() == 0 then
post_button:Disable()
return
end
m.post_button:Enable()
post_button:Enable()
end
function update_item_configuration()
@@ -294,30 +294,30 @@ function update_item_configuration()
historical_value_button:Show()
hide_checkbox:Show()
m.item.texture:SetTexture(m.selected_item.texture)
m.item.name:SetText('['..m.selected_item.name..']')
local color = ITEM_QUALITY_COLORS[m.selected_item.quality]
m.item.name:SetTextColor(color.r, color.g, color.b)
if m.selected_item.aux_quantity > 1 then
m.item.count:SetText(m.selected_item.aux_quantity)
item.texture:SetTexture(selected_item.texture)
item.name:SetText('['..selected_item.name..']')
local color = ITEM_QUALITY_COLORS[selected_item.quality]
item.name:SetTextColor(color.r, color.g, color.b)
if selected_item.aux_quantity > 1 then
item.count:SetText(selected_item.aux_quantity)
else
m.item.count:SetText()
item.count:SetText()
end
m.stack_size_slider.editbox:SetNumber(m.stack_size_slider:GetValue())
m.stack_count_slider.editbox:SetNumber(m.stack_count_slider:GetValue())
stack_size_slider.editbox:SetNumber(stack_size_slider:GetValue())
stack_count_slider.editbox:SetNumber(stack_count_slider:GetValue())
do
local deposit_factor = neutral_faction() and 0.25 or 0.05
local stack_size = m.stack_size_slider:GetValue()
local stack_size = stack_size_slider:GetValue()
local stack_count
stack_count = m.stack_count_slider:GetValue()
local deposit = floor(m.selected_item.unit_vendor_price * deposit_factor * (m.selected_item.max_charges and 1 or stack_size)) * stack_count * UIDropDownMenu_GetSelectedValue(m.duration_dropdown) / 120
stack_count = stack_count_slider:GetValue()
local deposit = floor(selected_item.unit_vendor_price * deposit_factor * (selected_item.max_charges and 1 or stack_size)) * stack_count * UIDropDownMenu_GetSelectedValue(duration_dropdown) / 120
m.deposit:SetText('Deposit: '..money.to_string(deposit, nil, nil, nil, gui.inline_color.text.enabled))
end
m.refresh_button:Enable()
refresh_button:Enable()
end
end
@@ -334,14 +334,14 @@ function undercut(record, stack_size, stack)
end
function quantity_update(max_count)
if m.selected_item then
local max_stack_count = m.selected_item.max_charges and m.selected_item.availability[m.stack_size_slider:GetValue()] or floor(m.selected_item.availability[0] / m.stack_size_slider:GetValue())
m.stack_count_slider:SetMinMaxValues(1, max_stack_count)
if selected_item then
local max_stack_count = selected_item.max_charges and selected_item.availability[stack_size_slider:GetValue()] or floor(selected_item.availability[0] / stack_size_slider:GetValue())
stack_count_slider:SetMinMaxValues(1, max_stack_count)
if max_count then
m.stack_count_slider:SetValue(max_stack_count)
stack_count_slider:SetValue(max_stack_count)
end
end
m.refresh = true
refresh = true
end
function unit_vendor_price(item_key)
@@ -369,51 +369,51 @@ function unit_vendor_price(item_key)
end
function update_historical_value_button()
if m.selected_item then
local historical_value = history.value(m.selected_item.key)
m.historical_value_button.amount = historical_value
m.historical_value_button:SetText(historical_value and money.to_string(historical_value, true, nil, 3) or '---')
if selected_item then
local historical_value = history.value(selected_item.key)
historical_value_button.amount = historical_value
historical_value_button:SetText(historical_value and money.to_string(historical_value, true, nil, 3) or '---')
end
end
function set_item(item)
local settings = m.read_settings(item.key)
local settings = read_settings(item.key)
item.unit_vendor_price = m.unit_vendor_price(item.key)
item.unit_vendor_price = unit_vendor_price(item.key)
if not item.unit_vendor_price then
settings.hidden = 1
m.write_settings(settings, item.key)
m.refresh = true
write_settings(settings, item.key)
refresh = true
return
end
scan.abort(m.scan_id)
scan.abort(scan_id)
m.selected_item = item
selected_item = item
UIDropDownMenu_Initialize(m.duration_dropdown, m.initialize_duration_dropdown) -- TODO, wtf, why is this needed
UIDropDownMenu_SetSelectedValue(m.duration_dropdown, settings.duration)
UIDropDownMenu_Initialize(duration_dropdown, initialize_duration_dropdown) -- TODO, wtf, why is this needed
UIDropDownMenu_SetSelectedValue(duration_dropdown, settings.duration)
m.hide_checkbox:SetChecked(settings.hidden)
hide_checkbox:SetChecked(settings.hidden)
m.stack_size_slider:SetMinMaxValues(1, m.selected_item.max_charges or m.selected_item.max_stack)
m.stack_size_slider:SetValue(settings.stack_size)
m.quantity_update(true)
stack_size_slider:SetMinMaxValues(1, selected_item.max_charges or selected_item.max_stack)
stack_size_slider:SetValue(settings.stack_size)
quantity_update(true)
m.unit_start_price:SetText(money.to_string(settings.start_price, true, nil, 3, nil, true))
m.unit_buyout_price:SetText(money.to_string(settings.buyout_price, true, nil, 3, nil, true))
unit_start_price:SetText(money.to_string(settings.start_price, true, nil, 3, nil, true))
unit_buyout_price:SetText(money.to_string(settings.buyout_price, true, nil, 3, nil, true))
if not m.existing_auctions[m.selected_item.key] then
m.refresh_entries()
if not existing_auctions[selected_item.key] then
refresh_entries()
end
m.write_settings(settings, item.key)
m.refresh = true
write_settings(settings, item.key)
refresh = true
end
function update_inventory_records()
m.inventory_records = {}
m.refresh = true
inventory_records = {}
refresh = true
local auction_candidate_map = {}
@@ -456,37 +456,37 @@ function update_inventory_records()
end
end
m.inventory_records = {}
inventory_records = {}
for _, auction_candidate in auction_candidate_map do
tinsert(m.inventory_records, auction_candidate)
tinsert(inventory_records, auction_candidate)
end
sort(m.inventory_records, function(a, b) return a.name < b.name end)
m.refresh = true
sort(inventory_records, function(a, b) return a.name < b.name end)
refresh = true
end
function refresh_entries()
if m.selected_item then
local item_id, suffix_id = m.selected_item.item_id, m.selected_item.suffix_id
if selected_item then
local item_id, suffix_id = selected_item.item_id, selected_item.suffix_id
local item_key = item_id..':'..suffix_id
m.existing_auctions[item_key] = nil
existing_auctions[item_key] = nil
local query = scan_util.item_query(item_id)
m.status_bar:update_status(0,0)
m.status_bar:set_text('Scanning auctions...')
status_bar:update_status(0,0)
status_bar:set_text('Scanning auctions...')
m.scan_id = scan.start{
scan_id = scan.start{
type = 'list',
ignore_owner = true,
queries = { query },
on_page_loaded = function(page, total_pages)
m.status_bar:update_status(100 * (page - 1) / total_pages, 0) -- TODO
m.status_bar:set_text(format('Scanning Page %d / %d', page, total_pages))
status_bar:update_status(100 * (page - 1) / total_pages, 0) -- TODO
status_bar:set_text(format('Scanning Page %d / %d', page, total_pages))
end,
on_auction = function(auction_record)
if auction_record.item_key == item_key then
m.record_auction(
record_auction(
auction_record.item_key,
auction_record.aux_quantity,
auction_record.unit_blizzard_bid,
@@ -497,25 +497,25 @@ function refresh_entries()
end
end,
on_abort = function()
m.existing_auctions[item_key] = nil
m.update_historical_value_button()
m.status_bar:update_status(100, 100)
m.status_bar:set_text('Scan aborted')
existing_auctions[item_key] = nil
update_historical_value_button()
status_bar:update_status(100, 100)
status_bar:set_text('Scan aborted')
end,
on_complete = function()
m.existing_auctions[item_key] = m.existing_auctions[item_key] or {}
m.refresh = true
m.status_bar:update_status(100, 100)
m.status_bar:set_text('Scan complete')
existing_auctions[item_key] = existing_auctions[item_key] or {}
refresh = true
status_bar:update_status(100, 100)
status_bar:set_text('Scan complete')
end,
}
end
end
function record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price, duration, owner)
m.existing_auctions[key] = m.existing_auctions[key] or {}
existing_auctions[key] = existing_auctions[key] or {}
local entry
for _, existing_entry in m.existing_auctions[key] do
for _, existing_entry in 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 is_player(owner) == existing_entry.own then
entry = existing_entry
end
@@ -530,7 +530,7 @@ function record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price,
own = is_player(owner),
count = 0,
}
tinsert(m.existing_auctions[key], entry)
tinsert(existing_auctions[key], entry)
end
entry.count = entry.count + 1
@@ -539,26 +539,26 @@ function record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price,
end
function on_update()
if m.refresh then
m.refresh = false
m.price_update()
m.update_historical_value_button()
m.update_item_configuration()
m.update_inventory_listing()
m.update_auction_listing()
if refresh then
refresh = false
price_update()
update_historical_value_button()
update_item_configuration()
update_inventory_listing()
update_auction_listing()
end
m.validate_parameters()
validate_parameters()
end
function initialize_duration_dropdown()
local function on_click()
UIDropDownMenu_SetSelectedValue(m.duration_dropdown, this.value)
local settings = m.read_settings()
UIDropDownMenu_SetSelectedValue(duration_dropdown, this.value)
local settings = read_settings()
settings.duration = this.value
m.write_settings(settings)
m.refresh = true
write_settings(settings)
refresh = true
end
UIDropDownMenu_AddButton{