savedvariables refactoring

This commit is contained in:
Manuel Simon Hirsig
2017-03-18 12:24:20 +01:00
parent 57543230f3
commit 1829ce6374
10 changed files with 89 additions and 86 deletions
+4 -27
View File
@@ -12,7 +12,6 @@ local scan = require 'aux.core.scan'
local search_tab = require 'aux.tabs.search'
_G.aux_scale = 1
_G.aux_characters = {}
function M.set_p(v)
inspect(nil, v)
@@ -163,31 +162,10 @@ do
end
end
function M.is_player(name)
local key = GetCVar'realmName'
return name and index(aux_characters, key, name) and true or false
end
function LOAD2()
local key = GetCVar'realmName'
aux_characters[key] = aux_characters[key] or {}
for char, lastSeen in aux_characters[key] do
if GetTime() - lastSeen > 60 * 60 * 24 * 30 then
aux_characters[key][char] = nil
end
end
aux_characters[key][UnitName'player'] = GetTime()
AuxFrame:SetScale(aux_scale)
end
function M.neutral_faction()
return not UnitFactionGroup'npc'
end
function M.min_bid_increment(current_bid)
return max(1, floor(current_bid / 100) * 5)
end
function AUCTION_HOUSE_SHOW()
AuctionFrame:Hide()
AuxFrame:Show()
@@ -210,11 +188,10 @@ end
do
local last_owner_page_requested
function GetOwnerAuctionItems(...)
temp(arg)
local page = arg[1]
last_owner_page_requested = page
return orig.GetOwnerAuctionItems(unpack(arg))
function GetOwnerAuctionItems(index)
local page = index
last_owner_page_requested = index
return orig.GetOwnerAuctionItems(index)
end
function AUCTION_OWNED_LIST_UPDATE()
current_owner_page = last_owner_page_requested or 0
+1 -1
View File
@@ -3,7 +3,7 @@
## Title: aux
## Notes: Auction House replacement
## SavedVariablesPerCharacter: aux_tooltip_value, aux_tooltip_daily, aux_tooltip_merchant_buy, aux_tooltip_merchant_sell, aux_tooltip_disenchant_value, aux_tooltip_disenchant_distribution
## SavedVariables: aux_scale, aux_datasets, aux_items, aux_item_ids, aux_auctionable_items, aux_merchant_buy, aux_merchant_sell, aux_characters, aux_recent_searches, aux_favorite_searches, aux_post_bid, aux_ignore_owner
## SavedVariables: aux, aux_scale, aux_post_bid, aux_ignore_owner, aux_items, aux_item_ids, aux_auctionable_items, aux_merchant_buy, aux_merchant_sell
libs\inspect.lua
libs\module.lua
+16
View File
@@ -39,6 +39,22 @@ function LOAD()
end)
end
do
local characters = empty
function M.is_player(name)
return characters[name] and true or false
end
function LOAD2()
characters = persistence.realm'characters'
for k, v in characters do
if GetTime() > v + 60 * 60 * 24 * 30 then
characters[k] = nil
end
end
characters[UnitName'player'] = GetTime()
end
end
do
local sell_scan_queued, incomplete_buy_data
function on_merchant_show()
+2 -10
View File
@@ -9,16 +9,8 @@ local history_schema = {'tuple', '#', {next_push='number'}, {daily_min_buyout='n
local value_cache = {}
do
local cache
function get_data()
if not cache then
local dataset = persistence.dataset
cache = dataset.history or T
dataset.history = cache
end
return cache
end
function LOAD2()
data = persistence.faction'history'
end
do
+4 -3
View File
@@ -10,6 +10,7 @@ local history = require 'aux.core.history'
local gui = require 'aux.gui'
local search_tab = require 'aux.tabs.search'
local tooltip = require 'aux.core.tooltip'
local cache = require 'aux.core.cache'
local price_per_unit = false
@@ -139,7 +140,7 @@ M.search_columns = {
width = .13,
align = 'CENTER',
fill = function(cell, record)
cell.text:SetText(is_player(record.owner) and (color.yellow(record.owner)) or (record.owner or '?'))
cell.text:SetText(cache.is_player(record.owner) and (color.yellow(record.owner)) or (record.owner or '?'))
end,
cmp = function(record_a, record_b, desc)
if not record_a.owner and not record_b.owner then
@@ -428,7 +429,7 @@ M.bids_columns = {
width = .13,
align = 'CENTER',
fill = function(cell, record)
cell.text:SetText(is_player(record.owner) and (color.yellow(record.owner)) or (record.owner or '?'))
cell.text:SetText(cache.is_player(record.owner) and (color.yellow(record.owner)) or (record.owner or '?'))
end,
cmp = function(record_a, record_b, desc)
if not record_a.owner and not record_b.owner then
@@ -693,7 +694,7 @@ local methods = {
local totalAuctions, totalPlayerAuctions = 0, 0
for _, childInfo in info.children do
totalAuctions = totalAuctions + childInfo.count
if is_player(childInfo.record.owner) then
if cache.is_player(childInfo.record.owner) then
totalPlayerAuctions = totalPlayerAuctions + childInfo.count
end
end
+8 -15
View File
@@ -11,6 +11,7 @@ local scan_util = require 'aux.util.scan'
local post = require 'aux.core.post'
local scan = require 'aux.core.scan'
local history = require 'aux.core.history'
local cache = require 'aux.core.cache'
local item_listing = require 'aux.gui.item_listing'
local al = require 'aux.gui.auction_listing'
@@ -25,16 +26,8 @@ function get_default_settings()
return O('duration', DURATION_8, 'start_price', 0, 'buyout_price', 0, 'hidden', false)
end
do
local data
function get_data()
if not data then
local dataset = persistence.dataset
data = dataset.post or T
dataset.post = data
end
return data
end
function LOAD2()
data = persistence.faction'post'
end
function read_settings(item_key)
@@ -333,7 +326,7 @@ function update_item_configuration()
stack_count_slider.editbox:SetNumber(stack_count_slider:GetValue())
do
local deposit_factor = neutral_faction() and .25 or .05
local deposit_factor = UnitFactionGroup'npc' and .25 or .05
local stack_size, stack_count = stack_size_slider:GetValue(), stack_count_slider:GetValue()
local amount = floor(selected_item.unit_vendor_price * deposit_factor * (selected_item.max_charges and 1 or stack_size)) * stack_count * UIDropDownMenu_GetSelectedValue(duration_dropdown) / 120
deposit:SetText('Deposit: ' .. money.to_string(amount, nil, nil, nil, color.text.enabled))
@@ -518,12 +511,12 @@ function record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price,
do
local entry
for _, record in bid_records[key] do
if unit_blizzard_bid == record.unit_price and aux_quantity == record.stack_size and duration == record.duration and is_player(owner) == record.own then
if unit_blizzard_bid == record.unit_price and aux_quantity == record.stack_size and duration == record.duration and cache.is_player(owner) == record.own then
entry = record
end
end
if not entry then
entry = O('stack_size', aux_quantity, 'unit_price', unit_blizzard_bid, 'duration', duration, 'own', is_player(owner), 'count', 0)
entry = O('stack_size', aux_quantity, 'unit_price', unit_blizzard_bid, 'duration', duration, 'own', cache.is_player(owner), 'count', 0)
tinsert(bid_records[key], entry)
end
entry.count = entry.count + 1
@@ -533,12 +526,12 @@ function record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price,
do
local entry
for _, record in buyout_records[key] do
if unit_buyout_price == record.unit_price and aux_quantity == record.stack_size and duration == record.duration and is_player(owner) == record.own then
if unit_buyout_price == record.unit_price and aux_quantity == record.stack_size and duration == record.duration and cache.is_player(owner) == record.own then
entry = record
end
end
if not entry then
entry = O('stack_size', aux_quantity, 'unit_price', unit_buyout_price, 'duration', duration, 'own', is_player(owner), 'count', 0)
entry = O('stack_size', aux_quantity, 'unit_price', unit_buyout_price, 'duration', duration, 'own', cache.is_player(owner), 'count', 0)
tinsert(buyout_records[key], entry)
end
entry.count = entry.count + 1
+2 -1
View File
@@ -4,6 +4,7 @@ local info = require 'aux.util.info'
local filter_util = require 'aux.util.filter'
local scan_util = require 'aux.util.scan'
local scan = require 'aux.core.scan'
local cache = require 'aux.core.cache'
function LOAD()
new_search()
@@ -368,7 +369,7 @@ do
function find_auction(record)
local search = current_search
if not search.table:ContainsRecord(record) or is_player(record.owner) then
if not search.table:ContainsRecord(record) or cache.is_player(record.owner) then
return
end
+17 -15
View File
@@ -2,14 +2,16 @@ module 'aux.tabs.search'
local filter_util = require 'aux.util.filter'
local gui = require 'aux.gui'
local persistence = require 'aux.util.persistence'
_G.aux_favorite_searches = {}
_G.aux_recent_searches = {}
function LOAD2()
recent_searches, favorite_searches = persistence.realm'recent_searches', persistence.realm'favorite_searches'
end
function update_search_listings()
local favorite_search_rows = T
for i = 1, getn(aux_favorite_searches) do
local search = aux_favorite_searches[i]
for i = 1, getn(favorite_searches) do
local search = favorite_searches[i]
local name = strsub(search.prettified, 1, 250)
tinsert(favorite_search_rows, O(
'cols', A(O('value', search.auto_buy and color.red'X' or ''), O('value', name)),
@@ -20,8 +22,8 @@ function update_search_listings()
favorite_searches_listing:SetData(favorite_search_rows)
local recent_search_rows = T
for i = 1, getn(aux_recent_searches) do
local search = aux_recent_searches[i]
for i = 1, getn(recent_searches) do
local search = recent_searches[i]
local name = strsub(search.prettified, 1, 250)
tinsert(recent_search_rows, O(
'cols', A(O('value', name)),
@@ -33,12 +35,12 @@ function update_search_listings()
end
function new_recent_search(filter_string, prettified)
tinsert(aux_recent_searches, 1, O(
tinsert(recent_searches, 1, O(
'filter_string', filter_string,
'prettified', prettified
))
while getn(aux_recent_searches) > 50 do
tremove(aux_recent_searches)
while getn(recent_searches) > 50 do
tremove(recent_searches)
end
update_search_listings()
end
@@ -56,15 +58,15 @@ handlers = {
elseif button == 'RightButton' then
local u = update_search_listings
if st == recent_searches_listing then
tinsert(aux_favorite_searches, 1, data.search)
tinsert(favorite_searches, 1, data.search)
u(d)
elseif st == favorite_searches_listing then
local auto_buy = data.search.auto_buy
gui.menu(
(auto_buy and 'Disable' or 'Enable') .. ' Auto Buy', function() if auto_buy then data.search.auto_buy = nil else enable_auto_buy(data.search) end u() end,
'Move Up', function() move_up(aux_favorite_searches, data.index); u() end,
'Move Down', function() move_down(aux_favorite_searches, data.index); u() end,
'Delete', function() tremove(aux_favorite_searches, data.index); u() end
'Move Up', function() move_up(favorite_searches, data.index); u() end,
'Move Down', function() move_down(favorite_searches, data.index); u() end,
'Delete', function() tremove(favorite_searches, data.index); u() end
)
end
end
@@ -83,7 +85,7 @@ handlers = {
function get_auto_buy_validator()
local validators = T
for _, search in aux_favorite_searches do
for _, search in favorite_searches do
if search.auto_buy then
local queries, error = filter_util.queries(search.filter_string)
if queries then
@@ -101,7 +103,7 @@ end
function add_favorite(filter_string)
local queries, error = filter_util.queries(filter_string)
if queries then
tinsert(aux_favorite_searches, 1, O(
tinsert(favorite_searches, 1, O(
'filter_string', filter_string,
'prettified', join(map(queries, function(query) return query.prettified end), ';')
))
+4 -4
View File
@@ -126,8 +126,8 @@ function M.auction(index, query_type)
'link', link,
'itemstring', item_info.itemstring,
'item_key', item_id .. ':' .. suffix_id,
'search_signature', join(temp-A(item_id, suffix_id, enchant_id, start_price, buyout_price, bid_price, aux_quantity, duration, query_type == 'owner' and high_bidder or (high_bidder and 1 or 0), aux_ignore_owner and (is_player(owner) and 0 or 1) or (owner or '?')), ':'),
'sniping_signature', join(temp-A(item_id, suffix_id, enchant_id, start_price, buyout_price, aux_quantity, aux_ignore_owner and (is_player(owner) and 0 or 1) or (owner or '?')), ':'),
'search_signature', join(temp-A(item_id, suffix_id, enchant_id, start_price, buyout_price, bid_price, aux_quantity, duration, query_type == 'owner' and high_bidder or (high_bidder and 1 or 0), aux_ignore_owner and (cache.is_player(owner) and 0 or 1) or (owner or '?')), ':'),
'sniping_signature', join(temp-A(item_id, suffix_id, enchant_id, start_price, buyout_price, aux_quantity, aux_ignore_owner and (cache.is_player(owner) and 0 or 1) or (owner or '?')), ':'),
'name', name,
'texture', texture,
@@ -166,12 +166,12 @@ end
function M.bid_update(auction_record)
auction_record.high_bid = auction_record.bid_price
auction_record.blizzard_bid = auction_record.bid_price
auction_record.min_increment = min_bid_increment(auction_record.bid_price)
auction_record.min_increment = max(1, floor(auction_record.bid_price / 100) * 5)
auction_record.bid_price = auction_record.bid_price + auction_record.min_increment
auction_record.unit_blizzard_bid = auction_record.blizzard_bid / auction_record.aux_quantity
auction_record.unit_bid_price = auction_record.bid_price / auction_record.aux_quantity
auction_record.high_bidder = 1
auction_record.search_signature = join(temp-A(auction_record.item_id, auction_record.suffix_id, auction_record.enchant_id, auction_record.start_price, auction_record.buyout_price, auction_record.bid_price, auction_record.aux_quantity, auction_record.duration, 1, aux_ignore_owner and (is_player(auction_record.owner) and 0 or 1) or (auction_record.owner or '?')), ':')
auction_record.search_signature = join(temp-A(auction_record.item_id, auction_record.suffix_id, auction_record.enchant_id, auction_record.start_price, auction_record.buyout_price, auction_record.bid_price, auction_record.aux_quantity, auction_record.duration, 1, aux_ignore_owner and (cache.is_player(auction_record.owner) and 0 or 1) or (auction_record.owner or '?')), ':')
end
function M.set_tooltip(itemstring, owner, anchor)
+31 -10
View File
@@ -3,17 +3,38 @@ module 'aux.util.persistence'
include 'T'
include 'aux'
_G.aux_datasets = {}
_G.aux = {
player = {},
faction = {},
realm = {},
account = {},
}
do
local dataset
function M.get_dataset()
if not dataset then
local dataset_key = format('%s|%s', GetCVar'realmName', UnitFactionGroup'player')
dataset = aux_datasets[dataset_key] or T
aux_datasets[dataset_key] = dataset
end
return dataset
local cache = {account=aux.account}
function LOAD2()
do
local key = format('%s|%s', GetCVar'realmName', UnitName'player')
aux.player[key] = aux.player[key] or {}
cache.player = aux.player[key]
end
do
local key = format('%s|%s', GetCVar'realmName', UnitFactionGroup'player')
aux.faction[key] = aux.faction[key] or {}
cache.faction = aux.faction[key]
end
do
local key = GetCVar'realmName'
aux.realm[key] = aux.realm[key] or {}
cache.realm = aux.realm[key]
end
end
for scope in temp-S('player', 'faction', 'realm', 'account') do
local scope = scope
M[scope] = function(k)
cache[scope][k] = cache[scope][k]
return cache[scope][k]
end
end