module refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-10-14 01:55:38 +02:00
parent 2660b44861
commit cc7139c0e2
30 changed files with 326 additions and 343 deletions
+29 -29
View File
@@ -19,13 +19,13 @@ TAB 'Post'
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'}}
function private.default_settings.get()
function get_default_settings()
return T('duration', DURATION_8 , 'stack_size', 1, 'start_price', 0, 'buyout_price', 0, 'hidden', false)
end
do
local data
function private.data.get()
function get_data()
if not data then
local dataset = persistence.dataset
data = dataset.post or t
@@ -35,19 +35,19 @@ do
end
end
function private.read_settings(item_key)
function 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 private.write_settings(settings, item_key)
function 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 private.refresh_button_click()
function refresh_button_click()
scan.abort(scan_id)
refresh_entries()
refresh = true
@@ -55,14 +55,14 @@ end
do
local item
function private.selected_item.get() return item end
function private.selected_item.set(v) item = v end
function get_selected_item() return item end
function set_selected_item(v) item = v end
end
do
local c = 0
function private.refresh.get() return c end
function private.refresh.set(v) c = v end
function get_refresh() return c end
function set_refresh(v) c = v end
end
function OPEN()
@@ -80,25 +80,25 @@ function USE_ITEM(item_info)
select_item(item_info.item_key)
end
function private.get_unit_start_price()
function get_unit_start_price()
local money_text = unit_start_price:GetText()
return money.from_string(money_text) or 0
end
function private.set_unit_start_price(amount)
function set_unit_start_price(amount)
unit_start_price:SetText(money.to_string(amount, true, nil, 3, nil, true))
end
function private.get_unit_buyout_price()
function get_unit_buyout_price()
local money_text = unit_buyout_price:GetText()
return money.from_string(money_text) or 0
end
function private.set_unit_buyout_price(amount)
function set_unit_buyout_price(amount)
unit_buyout_price:SetText(money.to_string(amount, true, nil, 3, nil, true))
end
function private.update_inventory_listing()
function 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)
@@ -106,7 +106,7 @@ function private.update_inventory_listing()
end)))
end
function private.update_auction_listing()
function update_auction_listing()
if not ACTIVE then return end
local auction_rows = t
if selected_item then
@@ -188,7 +188,7 @@ function public.select_item(item_key)
end
end
function private.price_update()
function price_update()
if selected_item then
local settings = read_settings()
@@ -206,7 +206,7 @@ function private.price_update()
end
end
function private.post_auctions()
function post_auctions()
if selected_item then
local unit_start_price = get_unit_start_price()
local unit_buyout_price = get_unit_buyout_price()
@@ -250,7 +250,7 @@ function private.post_auctions()
end
end
function private.validate_parameters()
function validate_parameters()
if not selected_item then
post_button:Disable()
return
@@ -270,7 +270,7 @@ function private.validate_parameters()
post_button:Enable()
end
function private.update_item_configuration()
function update_item_configuration()
if not selected_item then
refresh_button:Disable()
@@ -325,7 +325,7 @@ function private.update_item_configuration()
end
end
function private.undercut(record, stack_size, stack)
function 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
@@ -335,7 +335,7 @@ function private.undercut(record, stack_size, stack)
return start_price / stack_size, buyout_price / stack_size
end
function private.quantity_update(max_count)
function 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)
@@ -346,7 +346,7 @@ function private.quantity_update(max_count)
refresh = true
end
function private.unit_vendor_price(item_key)
function 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
@@ -366,7 +366,7 @@ function private.unit_vendor_price(item_key)
end
end
function private.update_historical_value_button()
function update_historical_value_button()
if selected_item then
local historical_value = history.value(selected_item.key)
historical_value_button.amount = historical_value
@@ -374,7 +374,7 @@ function private.update_historical_value_button()
end
end
function private.set_item(item)
function set_item(item)
local settings = read_settings(item.key)
item.unit_vendor_price = unit_vendor_price(item.key)
@@ -409,7 +409,7 @@ function private.set_item(item)
refresh = true
end
function private.update_inventory_records()
function 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
@@ -447,7 +447,7 @@ function private.update_inventory_records()
refresh = true
end
function private.refresh_entries()
function 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
@@ -492,7 +492,7 @@ function private.refresh_entries()
end
end
function private.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)
existing_auctions[key] = existing_auctions[key] or t
local entry
for _, record in existing_auctions[key] do
@@ -508,7 +508,7 @@ function private.record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyou
return entry
end
function private.on_update()
function on_update()
if refresh then
refresh = false
price_update()
@@ -520,7 +520,7 @@ function private.on_update()
validate_parameters()
end
function private.initialize_duration_dropdown()
function initialize_duration_dropdown()
local function on_click()
UIDropDownMenu_SetSelectedValue(duration_dropdown, this.value)
local settings = read_settings()
+18 -18
View File
@@ -7,7 +7,7 @@ local listing = require 'aux.gui.listing'
local item_listing = require 'aux.gui.item_listing'
local search_tab = require 'aux.tabs.search'
private.frame = CreateFrame('Frame', nil, AuxFrame)
frame = CreateFrame('Frame', nil, AuxFrame)
frame:SetAllPoints()
frame:SetScript('OnUpdate', on_update)
frame:Hide()
@@ -41,12 +41,12 @@ do
local label = gui.label(checkbox, gui.font_size.small)
label:SetPoint('LEFT', checkbox, 'RIGHT', 4, 1)
label:SetText('Show hidden items')
private.show_hidden_checkbox = checkbox
show_hidden_checkbox = checkbox
end
gui.horizontal_line(frame.inventory, -48)
private.inventory_listing = item_listing.create(
inventory_listing = item_listing.create(
frame.inventory,
function()
if arg1 == 'LeftButton' then
@@ -62,7 +62,7 @@ private.inventory_listing = item_listing.create(
end
)
private.auction_listing = listing.CreateScrollingTable(frame.auctions)
auction_listing = listing.CreateScrollingTable(frame.auctions)
auction_listing:SetColInfo{
{ name='Auctions', width=.12, align='CENTER' },
{ name='Left', width=.1, align='CENTER' },
@@ -87,7 +87,7 @@ auction_listing:SetHandler('OnClick', function(table, row_data, column, button)
end)
do
private.status_bar = gui.status_bar(frame)
status_bar = gui.status_bar(frame)
status_bar:SetWidth(265)
status_bar:SetHeight(25)
status_bar:SetPoint('TOPLEFT', AuxFrame.content, 'BOTTOMLEFT', 0, -6)
@@ -99,17 +99,17 @@ do
btn:SetPoint('TOPLEFT', status_bar, 'TOPRIGHT', 5, 0)
btn:SetText('Post')
btn:SetScript('OnClick', post_auctions)
private.post_button = btn
post_button = btn
end
do
local btn = gui.button(frame.parameters)
btn:SetPoint('TOPLEFT', post_button, 'TOPRIGHT', 5, 0)
btn:SetText('Refresh')
btn:SetScript('OnClick', refresh_button_click)
private.refresh_button = btn
refresh_button = btn
end
do
private.item = gui.item(frame.parameters)
item = gui.item(frame.parameters)
item:SetPoint('TOPLEFT', 10, -6)
item.button:SetScript('OnEnter', function()
if selected_item then
@@ -149,7 +149,7 @@ do
slider.editbox:SetNumeric(true)
slider.editbox:SetMaxLetters(3)
slider.label:SetText('Stack Size')
private.stack_size_slider = slider
stack_size_slider = slider
end
do
local slider = gui.slider(frame.parameters)
@@ -172,7 +172,7 @@ do
end)
slider.editbox:SetNumeric(true)
slider.label:SetText('Stack Count')
private.stack_count_slider = slider
stack_count_slider = slider
end
do
local dropdown = gui.dropdown(frame.parameters)
@@ -185,12 +185,12 @@ do
dropdown:SetScript('OnShow', function()
UIDropDownMenu_Initialize(this, initialize_duration_dropdown)
end)
private.duration_dropdown = dropdown
duration_dropdown = dropdown
end
do
local label = gui.label(frame.parameters, gui.font_size.medium)
label:SetPoint('LEFT', duration_dropdown, 'RIGHT', 25, 0)
private.deposit = label
deposit = label
end
do
local checkbox = gui.checkbox(frame.parameters)
@@ -204,7 +204,7 @@ do
local label = gui.label(checkbox, gui.font_size.small)
label:SetPoint('LEFT', checkbox, 'RIGHT', 4, 1)
label:SetText('Hide this item')
private.hide_checkbox = checkbox
hide_checkbox = checkbox
end
do
local editbox = gui.editbox(frame.parameters)
@@ -237,9 +237,9 @@ do
label:SetPoint('LEFT', editbox, 'RIGHT', 8, 0)
label:SetWidth(50)
label:SetJustifyH('CENTER')
private.start_price_percentage = label
start_price_percentage = label
end
private.unit_start_price = editbox
unit_start_price = editbox
end
do
local editbox = gui.editbox(frame.parameters)
@@ -272,9 +272,9 @@ do
label:SetPoint('LEFT', editbox, 'RIGHT', 8, 0)
label:SetWidth(50)
label:SetJustifyH('CENTER')
private.buyout_price_percentage = label
buyout_price_percentage = label
end
private.unit_buyout_price = editbox
unit_buyout_price = editbox
end
do
local btn = gui.button(frame.parameters, 14)
@@ -291,5 +291,5 @@ do
local label = gui.label(btn, gui.font_size.small)
label:SetPoint('BOTTOMLEFT', btn, 'TOPLEFT', -2, 1)
label:SetText('Historical Value')
private.historical_value_button = btn
historical_value_button = btn
end