diff --git a/addons/GearSwap/README.md b/addons/GearSwap/README.md index 650af8511..bf829f04c 100644 --- a/addons/GearSwap/README.md +++ b/addons/GearSwap/README.md @@ -1,6 +1,6 @@ Author: Byrth -Version: 0.930 +Version: 0.938 Date: 06/13/2017 @@ -9,27 +9,33 @@ GearSwap Abbreviation: gs Commands (<> indicates a field. You do not actually have to use <>s): -* gs c : Passes the to the self_command() user function. -* gs equip : Attempts to interpret the as an index of the sets table and equip that set. Will ignore "sets" if the string starts with it. +* gs c \ : Passes the to the self_command() user function. +* gs equip \ : Attempts to interpret the as an index of the sets table and equip that set. Will ignore "sets" if the string starts with it. ** gs equip naked : This equips the default set "naked," which is just a bunch of empty slots. If you remake sets (sets={}) in your get_sets(), this will not work. * gs debugmode : Activates GearSwap's Debug Mode, which prints out why specific gear equipping attempts failed, shows you when you're entering events, and enables the eval command. -** gs eval : This command evaluates the as Lua code in the global gearswap environment (not the user environment, which is in the user_env table). It is only available when debugmode is on. +** gs eval \ : This command evaluates the as Lua code in the global gearswap environment (not the user environment, which is in the user_env table). It is only available when debugmode is on. * gs showswaps : Shows when your gear successfully changes and what it changes to. -* gs load : (or l ) Attempts to load the first version of found, assuming it is a file path relative to 9 potential base directories, in this order: -** ..GearSwap/libs-dev/ -** ..GearSwap/libs/ -** GearSwap/data// -** GearSwap/data/common/ -** GearSwap/data/ -** APPDATA/Windower/GearSwap// -** APPDATA/Windower/GearSwap/common/ -** APPDATA/Windower/GearSwap/ -** ..Windower/addons/libs/ +* gs load \ : (or l ) Attempts to load the first version of found, assuming it is a file path relative to 9 potential base directories, in this order: + * ..GearSwap/libs-dev/\ + * ..GearSwap/libs/\ + * GearSwap/data/\/\ + * GearSwap/data/common/\ + * GearSwap/data/\ + * APPDATA/Windower/GearSwap/\/\ + * APPDATA/Windower/GearSwap/common/\ + * APPDATA/Windower/GearSwap/\ + * ..Windower/addons/libs/\ * gs reload : Reloads the current user file. -* gs export : Exports your currently equipped gear, inventory, or all the items in your current Lua files' sets into GearSwap .lua or spellcast .xml format. Takes options "inventory", "all", "wearable", "sets", and "xml." Defaults to currently equipped gear and lua otherwise. Also exports appropriate advanced set tables with augments for currently equipped gear and inventory. -* gs enable : Enables equip commands targeting a specified slot. "All" will allow all equip commands. Providing no slot argument will enable user GearSwap file execution, if it was disabled. -* gs disable : Disables equip commands targeting a given slot. "All" will prevent all equip commands. Providing no second argument will disable user GearSwap file execution, although registered events will still run. -* gs validate : This command checks to see whether the equipment in the sets table also exists in your inventory (default), or (by passing "inv") whether the equipment in your inventory exists in your sets table. is an optional list of words that restricts the output to only those items that contain text from one of the filter's words. +* gs export \ : Exports your currently equipped gear, inventory, or all the items in your current Lua files' sets into GearSwap .lua format. + Available options: + * one of "inventory", "all", "wearable", "sets". Defaults to currently equipped gear and lua otherwise. + * "noaugments", to export only base names and omit augments, or "only augments"m to export only gear that is augmented. These two options are mutually exclusive. Defaults to exporting all gear with the respective augments (if present) if neither is specified. + * "minify", exports the set in a single line without newlines. + * "clipboard", exports the set to clipboard instead of a file. + * "filename", followed by the desired name, exports to the specified filename. Defaults to "Charactername_YYYY-MM-DD HH:MM:SS.lua" otherwise. Does nothing if "clipboard" is passed. +* gs enable \ : Enables equip commands targeting a specified slot. "All" will allow all equip commands. Providing no slot argument will enable user GearSwap file execution, if it was disabled. +* gs disable \ : Disables equip commands targeting a given slot. "All" will prevent all equip commands. Providing no second argument will disable user GearSwap file execution, although registered events will still run. +* gs validate \ \ : This command checks to see whether the equipment in the sets table also exists in your inventory (default), or (by passing "inv") whether the equipment in your inventory exists in your sets table. \ is an optional list of words that restricts the output to only those items that contain text from one of the filter's words. Purpose: To assist in the micromanaging of equipment! diff --git a/addons/GearSwap/export.lua b/addons/GearSwap/export.lua index 2757da93d..882a080ed 100644 --- a/addons/GearSwap/export.lua +++ b/addons/GearSwap/export.lua @@ -25,40 +25,43 @@ --SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. function export_set(options) - local item_list = T{} - local targinv,all_items,minify,all_sets,use_job_in_filename,use_subjob_in_filename,overwrite_existing,named_file - if #options > 0 then - for _,v in ipairs(options) do - if S{'inventory','inv','i'}:contains(v:lower()) then - targinv = true - elseif v:lower() == 'all' then - all_items = true - elseif v:lower() == 'wearable' then - wearable = true - elseif S{'mini'}:contains(v:lower()) then - minify = true - elseif S{'sets','set','s'}:contains(v:lower()) then - all_sets = true - if not user_env or not user_env.sets then - msg.addon_msg(123,'Cannot export the sets table of the current file because there is no file loaded.') - return - end - elseif v:lower() == 'mainjob' then - use_job_in_filename = true - elseif v:lower() == 'mainsubjob' then - use_subjob_in_filename = true - elseif v:lower() == 'overwrite' then - overwrite_existing = true - elseif S{'filename','file','f'}:contains(v:lower()) then - named_file = true - else - if named_file then - filename = v - end + local named_file = false + local filename = false + for i=1,#options do + if S{'filename','file','f'}:contains(options[i]) then + filename = table.remove(options,i+1) + if not filename then + msg.addon_msg(123,'Cannot export to named file because a filename was not provided.') + return end + named_file = table.remove(options,i) + break end end + local options = S(options):map(string.lower) + + local targinv = not (options* S{'inventory','inv','i'}):empty() + local all_items = options:contains('all') + local wearable = options:contains('wearable') + local all_sets = not (options * S{'sets','set','s'}):empty() + if all_sets and (not user_env or not user_env.sets) then + msg.addon_msg(123,'Cannot export the sets table of the current file because there is no file loaded.') + return + end + + local noaugments = not (options * S{'noaugments','noaugs'}):empty() + if noaugments then onlyaugmented = false end + + local onlyaugmented = not (options * S{'onlyaugmented','onlyaugs'}):empty() + if onlyaugmented then noaugments = false end + + local minify = not (options * S{'mini','minify'}):empty() + local clipboard = not (options * S{'copy','clipboard'}):empty() + local use_job_in_filename = options:contains('mainjob') + local use_subjob_in_filename = options:contains('mainsubjob') + local overwrite_existing = options:contains('overwrite') + local buildmsg = 'Exporting ' if all_items then buildmsg = buildmsg..'all your items' @@ -72,26 +75,34 @@ function export_set(options) buildmsg = buildmsg..'your currently equipped gear' end - buildmsg = buildmsg..' as a lua file.' - - if use_job_in_filename then - buildmsg = buildmsg..' (Naming format: Character_JOB)' - elseif use_subjob_in_filename then - buildmsg = buildmsg..' (Naming format: Character_JOB_SUB)' - elseif named_file then - buildmsg = buildmsg..' (Named: Character_'..filename..')' + if noaugments then + buildmsg = buildmsg..' (omitting augments)' + elseif onlyaugmented then + buildmsg = buildmsg..' (only augmented items)' end - if overwrite_existing then - buildmsg = buildmsg..' Will overwrite existing files with same name.' - end + if clipboard then + buildmsg = buildmsg..' to clipboard.' + else + buildmsg = buildmsg..' as a lua file.' - msg.addon_msg(123,buildmsg) + if use_job_in_filename then + buildmsg = buildmsg..' (Naming format: Character_JOB)' + elseif use_subjob_in_filename then + buildmsg = buildmsg..' (Naming format: Character_JOB_SUB)' + elseif named_file then + buildmsg = buildmsg..' (Named: Character_'..filename..')' + end - if not windower.dir_exists(windower.addon_path..'data/export') then - windower.create_dir(windower.addon_path..'data/export') + if overwrite_existing then + buildmsg = buildmsg..' Will overwrite existing files with same name.' + end end + + msg.addon_msg(123,buildmsg) + + local item_list = T{} if all_items then for i = 0, #res.bags do item_list:extend(get_item_list(items[res.bags[i].english:gsub(' ', ''):lower()])) @@ -126,13 +137,15 @@ function export_set(options) name = res.items[item_tab.id][language], slot = slot_name } - local augments = extdata.decode(item_tab).augments or {} - local aug_str = '' - for aug_ind,augment in pairs(augments) do - if augment ~= 'none' then aug_str = aug_str.."'"..augment:gsub("'","\\'").."'," end - end - if string.len(aug_str) > 0 then - item_list[slot_map[slot_name]+1].augments = aug_str + if not noaugments then + local augments = extdata.decode(item_tab).augments or {} + local aug_str = '' + for aug_ind,augment in pairs(augments) do + if augment ~= 'none' then aug_str = aug_str.."'"..augment:gsub("'","\\'").."'," end + end + if string.len(aug_str) > 0 then + item_list[slot_map[slot_name]+1].augments = aug_str + end end else msg.addon_msg(123,'You are wearing an item that is not in the resources yet.') @@ -158,56 +171,49 @@ function export_set(options) end end + local output = 'sets.exported={\n' - if not windower.dir_exists(windower.addon_path..'data/export') then - windower.create_dir(windower.addon_path..'data/export') + local newline = minify and '' or '\n' + for i,v in ipairs(item_list) do + if v.name ~= empty then + if v.augments then + --Advanced set table + output = output .. ' '..v.slot..'={ name="'..v.name..'", augments={'..v.augments..'}},'..newline + elseif not onlyaugmented then + output = output .. ' '..v.slot..'="'..v.name..'",'..newline + end + end end + output = output .. '}' - local path = windower.addon_path..'data/export/'..player.name - - if use_job_in_filename then - path = path..'_'..windower.ffxi.get_player().main_job - elseif use_subjob_in_filename then - path = path..'_'..windower.ffxi.get_player().main_job..'_'..windower.ffxi.get_player().sub_job - elseif named_file then - path = path..'_'..filename + if clipboard then + windower.copy_to_clipboard(output) else - path = path..os.date(' %Y-%m-%d %H-%M-%S') - end - if (not overwrite_existing) and windower.file_exists(path..'.lua') then - path = path..' '..os.clock() - end + if not windower.dir_exists(windower.addon_path..'data/export') then + windower.create_dir(windower.addon_path..'data/export') + end - local f = io.open(path..'.lua','w+') - if minify then - f:write('sets.exported={\n') - for i,v in ipairs(item_list) do - if v.name ~= empty then - if v.augments then - --Advanced set table - f:write(v.slot..'={ name="'..v.name..'", augments={'..v.augments..'}},') - else - f:write(v.slot..'="'..v.name..'",') - end - end + local path = windower.addon_path..'data/export/'..player.name + + if use_job_in_filename then + path = path..'_'..windower.ffxi.get_player().main_job + elseif use_subjob_in_filename then + path = path..'_'..windower.ffxi.get_player().main_job..'_'..windower.ffxi.get_player().sub_job + elseif named_file then + path = path..'_'..filename + else + path = path..os.date(' %Y-%m-%d %H-%M-%S') end - f:write('\n}') - else - f:write('sets.exported={\n') - for i,v in ipairs(item_list) do - if v.name ~= empty then - if v.augments then - --Advanced set table - f:write(' '..v.slot..'={ name="'..v.name..'", augments={'..v.augments..'}},\n') - else - f:write(' '..v.slot..'="'..v.name..'",\n') - end - end + + if (not overwrite_existing) and windower.file_exists(path..'.lua') then + path = path..' '..os.clock() end - f:write('}') + + local f = io.open(path..'.lua','w+') + f:write(output) + f:close() end - f:close() end function unpack_names(ret_tab,up,tab_level,unpacked_table,exported)