From 71c367d8b6c30cbeb5f9279c6270dd2b9e280eab Mon Sep 17 00:00:00 2001 From: moh Date: Sun, 5 Jun 2016 02:34:26 +0200 Subject: [PATCH 1/2] Added support for multiple characters --- Aux-AddOn.toc | 2 +- cache.lua | 1 + core.lua | 7 +++++- slash.lua | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/Aux-AddOn.toc b/Aux-AddOn.toc index 2b4340d..952765b 100644 --- a/Aux-AddOn.toc +++ b/Aux-AddOn.toc @@ -1,7 +1,7 @@ ## Interface: 11200 ## Title: Aux ## SavedVariablesPerCharacter: aux_ignore_owner, aux_recent_searches, aux_favorite_searches, aux_price_per_unit, aux_tooltip_daily, aux_tooltip_vendor_buy, aux_tooltip_vendor_sell, aux_tooltip_disenchant_value, aux_tooltip_disenchant_distribution, aux_tooltip_disenchant_source -## SavedVariables: aux_datasets, aux_items, aux_item_ids, aux_auctionable_items, aux_merchant_buy, aux_merchant_sell +## SavedVariables: aux_datasets, aux_items, aux_item_ids, aux_auctionable_items, aux_merchant_buy, aux_merchant_sell, aux_characters slash.lua core.xml diff --git a/cache.lua b/cache.lua index 886dda0..c90d1bf 100644 --- a/cache.lua +++ b/cache.lua @@ -8,6 +8,7 @@ aux_item_ids = {} aux_auctionable_items = {} aux_merchant_buy = {} aux_merchant_sell = {} +aux_characters = {} local items_schema = {'record', '#', {name='string'}, {quality='number'}, {level='number'}, {class='string'}, {subclass='string'}, {slot='string'}, {max_stack='number'}, {texture='string'}} local merchant_buy_schema = {'record', '#', {unit_price='number'}, {limited='boolean'}} diff --git a/core.lua b/core.lua index 50a93fe..0f7a3bd 100644 --- a/core.lua +++ b/core.lua @@ -423,7 +423,12 @@ function Aux.show_elements(elements) end function Aux.is_player(name) - return UnitName('player') == name -- TODO support multiple chars + for i,v in ipairs(aux_characters) do + if aux_characters[i] == name then + return true + end + end + return UnitName('player') == name end function Aux.unmodified() diff --git a/slash.lua b/slash.lua index 1830445..0a6f402 100644 --- a/slash.lua +++ b/slash.lua @@ -1,5 +1,26 @@ +local function strsplit(delimiter, text) + local list = {} + local pos = 1 + if strfind("", delimiter, 1) then -- this would result in endless loops + error("delimiter matches empty string!") + end + while 1 do + local first, last = strfind(text, delimiter, pos) + if first then -- found? + tinsert(list, strsub(text, pos, first-1)) + pos = last+1 + else + tinsert(list, strsub(text, pos)) + break + end + end + return list +end + SLASH_AUX1 = '/aux' function SlashCmdList.AUX(command) + if not command then return end + local arguments = strsplit(" ", command) if command == 'clear history' then Aux.persistence.load_dataset().history = nil Aux.log('History cleared.') @@ -43,5 +64,46 @@ function SlashCmdList.AUX(command) elseif command == 'ignore owner' then aux_ignore_owner = not aux_ignore_owner Aux.log('Ignoring of owner '..(aux_ignore_owner and 'enabled' or 'disabled')..'.') - end + elseif arguments[1] == 'addchar' and arguments[2] then + arguments[2] = strupper(strsub(arguments[2], 1, 1))..strsub(arguments[2], 2) -- make sure we get name starting from upper case + for i,v in ipairs(aux_characters) do + if (aux_characters[i] == arguments[2]) then + return + end + end + table.insert(aux_characters, arguments[2]) + Aux.log('Character "'..arguments[2]..'" added.') + elseif arguments[1] == 'delchar' and arguments[2] then + arguments[2] = strupper(strsub(arguments[2], 1, 1))..strsub(arguments[2], 2) -- make sure we get name starting from upper case + for i,v in ipairs(aux_characters) do + if (aux_characters[i] == arguments[2]) then + table.remove(aux_characters, i) + Aux.log('Character "'..arguments[2]..'" removed.') + break + end + end + elseif command == 'chars' then + local chars = nil + local num = table.getn(aux_characters); + for i,v in ipairs(aux_characters) do + if( i ~= num) then + if chars ~= nil then + chars = chars .. v .. ", "; + else + chars = v .. ", "; + end + else + if chars ~= nil then + chars = chars .. v; + else + chars = v; + end + end + end + if num > 0 then + Aux.log('Your characters: "'..chars..'".') + else + Aux.log('You don\'t have any additional characters. Type "/aux addchar NAME" to add one.') + end + end end \ No newline at end of file From 9e9a2c1d8e271a08a5e6187fc11dda4da6acfcb8 Mon Sep 17 00:00:00 2001 From: moh Date: Sun, 5 Jun 2016 21:05:20 +0200 Subject: [PATCH 2/2] Using built in split function now instead. Support for adding/removing multiple characters at once --- slash.lua | 58 +++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/slash.lua b/slash.lua index 0a6f402..6099971 100644 --- a/slash.lua +++ b/slash.lua @@ -1,26 +1,7 @@ -local function strsplit(delimiter, text) - local list = {} - local pos = 1 - if strfind("", delimiter, 1) then -- this would result in endless loops - error("delimiter matches empty string!") - end - while 1 do - local first, last = strfind(text, delimiter, pos) - if first then -- found? - tinsert(list, strsub(text, pos, first-1)) - pos = last+1 - else - tinsert(list, strsub(text, pos)) - break - end - end - return list -end - SLASH_AUX1 = '/aux' function SlashCmdList.AUX(command) if not command then return end - local arguments = strsplit(" ", command) + local arguments = Aux.util.split(command, " ") if command == 'clear history' then Aux.persistence.load_dataset().history = nil Aux.log('History cleared.') @@ -65,21 +46,34 @@ function SlashCmdList.AUX(command) aux_ignore_owner = not aux_ignore_owner Aux.log('Ignoring of owner '..(aux_ignore_owner and 'enabled' or 'disabled')..'.') elseif arguments[1] == 'addchar' and arguments[2] then - arguments[2] = strupper(strsub(arguments[2], 1, 1))..strsub(arguments[2], 2) -- make sure we get name starting from upper case - for i,v in ipairs(aux_characters) do - if (aux_characters[i] == arguments[2]) then - return + local exists = false + for i=2, table.getn(arguments) do + exists = false + if arguments[i] ~= "" then + arguments[i] = strupper(strsub(arguments[i], 1, 1))..strsub(arguments[i], 2) -- force uppercase + for i_aux,v in ipairs(aux_characters) do + if (aux_characters[i_aux] == arguments[i]) then + exists = true + break + end + end + if not exists then + table.insert(aux_characters, arguments[i]) + Aux.log('Character "'..arguments[i]..'" added.') + end end end - table.insert(aux_characters, arguments[2]) - Aux.log('Character "'..arguments[2]..'" added.') elseif arguments[1] == 'delchar' and arguments[2] then - arguments[2] = strupper(strsub(arguments[2], 1, 1))..strsub(arguments[2], 2) -- make sure we get name starting from upper case - for i,v in ipairs(aux_characters) do - if (aux_characters[i] == arguments[2]) then - table.remove(aux_characters, i) - Aux.log('Character "'..arguments[2]..'" removed.') - break + for i=2, table.getn(arguments) do + if arguments[i] ~= "" then + arguments[i] = strupper(strsub(arguments[i], 1, 1))..strsub(arguments[i], 2) + for i_aux,v in ipairs(aux_characters) do + if (aux_characters[i_aux] == arguments[i]) then + table.remove(aux_characters, i_aux) + Aux.log('Character "'..arguments[i]..'" removed.') + break + end + end end end elseif command == 'chars' then