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