module refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-09-23 09:07:56 +02:00
parent 1344ae0d23
commit 240589eef1
32 changed files with 525 additions and 499 deletions
+23 -23
View File
@@ -20,19 +20,19 @@ do
end
end
function read_settings(item_key)
function private.read_settings(item_key)
item_key = item_key or selected_item.key
return data[item_key] and persistence.read(settings_schema, data[item_key]) or default_settings
end
function write_settings(settings, item_key)
function private.write_settings(settings, item_key)
item_key = item_key or selected_item.key
data[item_key] = persistence.write(settings_schema, settings)
end
local scan_id, inventory_records, existing_auctions = 0, t, t
function refresh_button_click()
function private.refresh_button_click()
aux.scan.abort(scan_id)
refresh_entries()
refresh = true
@@ -69,25 +69,25 @@ function USE_ITEM(item_info)
select_item(item_info.item_key)
end
function get_unit_start_price()
function private.get_unit_start_price()
local money_text = unit_start_price:GetText()
return aux.money.from_string(money_text) or 0
end
function set_unit_start_price(amount)
function private.set_unit_start_price(amount)
unit_start_price:SetText(aux.money.to_string(amount, true, nil, 3, nil, true))
end
function get_unit_buyout_price()
function private.get_unit_buyout_price()
local money_text = unit_buyout_price:GetText()
return aux.money.from_string(money_text) or 0
end
function set_unit_buyout_price(amount)
function private.set_unit_buyout_price(amount)
unit_buyout_price:SetText(aux.money.to_string(amount, true, nil, 3, nil, true))
end
function update_inventory_listing()
function private.update_inventory_listing()
if not ACTIVE then return end
item_listing.populate(inventory_listing, values(filter(copy(inventory_records), function(record)
local settings = read_settings(record.key)
@@ -95,7 +95,7 @@ function update_inventory_listing()
end)))
end
function update_auction_listing()
function private.update_auction_listing()
if not ACTIVE then return end
local auction_rows = t
if selected_item then
@@ -177,7 +177,7 @@ function public.select_item(item_key)
end
end
function price_update()
function private.price_update()
if selected_item then
local settings = read_settings()
@@ -195,7 +195,7 @@ function price_update()
end
end
function post_auctions()
function private.post_auctions()
if selected_item then
local unit_start_price = get_unit_start_price()
local unit_buyout_price = get_unit_buyout_price()
@@ -239,7 +239,7 @@ function post_auctions()
end
end
function validate_parameters()
function private.validate_parameters()
if not selected_item then
post_button:Disable()
return
@@ -259,7 +259,7 @@ function validate_parameters()
post_button:Enable()
end
function update_item_configuration()
function private.update_item_configuration()
if not selected_item then
refresh_button:Disable()
@@ -314,7 +314,7 @@ function update_item_configuration()
end
end
function undercut(record, stack_size, stack)
function private.undercut(record, stack_size, stack)
local start_price = round(record.unit_blizzard_bid * (stack and record.stack_size or stack_size))
local buyout_price = round(record.unit_buyout_price * (stack and record.stack_size or stack_size))
if not record.own then
@@ -324,7 +324,7 @@ function undercut(record, stack_size, stack)
return start_price / stack_size, buyout_price / stack_size
end
function quantity_update(max_count)
function private.quantity_update(max_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)
@@ -335,7 +335,7 @@ function quantity_update(max_count)
refresh = true
end
function unit_vendor_price(item_key)
function private.unit_vendor_price(item_key)
for slot in info.inventory do auto[slot] = true
local item_info = info.container_item(unpack(slot))
if item_info and item_info.item_key == item_key then
@@ -355,7 +355,7 @@ function unit_vendor_price(item_key)
end
end
function update_historical_value_button()
function private.update_historical_value_button()
if selected_item then
local historical_value = history.value(selected_item.key)
historical_value_button.amount = historical_value
@@ -363,7 +363,7 @@ function update_historical_value_button()
end
end
function set_item(item)
function private.set_item(item)
local settings = read_settings(item.key)
item.unit_vendor_price = unit_vendor_price(item.key)
@@ -398,7 +398,7 @@ function set_item(item)
refresh = true
end
function update_inventory_records()
function private.update_inventory_records()
local auctionable_map = tt
for slot in info.inventory do auto[slot] = true
for item_info in present(info.container_item(unpack(slot))) do
@@ -436,7 +436,7 @@ function update_inventory_records()
refresh = true
end
function refresh_entries()
function private.refresh_entries()
if selected_item then
local item_id, suffix_id = selected_item.item_id, selected_item.suffix_id
local item_key = item_id .. ':' .. suffix_id
@@ -481,7 +481,7 @@ function refresh_entries()
end
end
function record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price, duration, owner)
function private.record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price, duration, owner)
existing_auctions[key] = existing_auctions[key] or t
local entry
for _, record in existing_auctions[key] do
@@ -497,7 +497,7 @@ function record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price,
return entry
end
function on_update()
function private.on_update()
if refresh then
refresh = false
price_update()
@@ -509,7 +509,7 @@ function on_update()
validate_parameters()
end
function initialize_duration_dropdown()
function private.initialize_duration_dropdown()
local function on_click()
UIDropDownMenu_SetSelectedValue(duration_dropdown, this.value)
local settings = read_settings()