Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 127 additions & 36 deletions addons/GearSwap/libs/closetCleaner.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--Copyright © 2016-2017, Brimstone
--Copyright © 2016-2025, Brimstone
--All rights reserved.

--Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -47,9 +47,10 @@ defaults.ccmaxuse = nil
-- List bags you want to not check against, needs to match "Location" column in <player>_report.txt
defaults.ccskipBags = S{ 'Storage', 'Temporary' }
-- this prints out the _sets _ignored and _inventory files
ccDebug = false

settings = config.load('ccConfig.xml',defaults)
defaults.ccDebug = false
settings = config.load('ccConfig.xml', defaults)
ccDebug = settings.ccDebug
errors = 0

register_unhandled_command(function(command)
command = command and command:lower() or nil
Expand Down Expand Up @@ -83,14 +84,53 @@ register_unhandled_command(function(command)
return true
end)

function cc.InitializeSetsForSelindrile()
sets.precast = {}
sets.precast.FC = {}
sets.precast.JA = {}
sets.precast.WS = {}
sets.precast.RA = {}
sets.precast.Item = {}
sets.midcast = {}
sets.midcast.RA = {}
sets.midcast.Pet = {}
sets.idle = {}
sets.resting = {}
sets.engaged = {}
sets.defense = {}
sets.buff = {}
sets.element = {}
sets.passive = {}
sets.weapons = {}
sets.DuskIdle = {}
sets.DayIdle = {}
sets.NightIdle = {}
sets.buff = {}
gear = {}
gear.default = {}
gear.ElementalGorget = {name=""}
gear.ElementalBelt = {name=""}
gear.ElementalObi = {name=""}
gear.ElementalCape = {name=""}
gear.ElementalRing = {name=""}
gear.FastcastStaff = {name=""}
gear.RecastStaff = {name=""}
info = {}
end

-- This function creates the report and generates the calls to the other functions
function cc.run_report(path)
add_to_chat(1, "closetCleaner Started!")
mainReportName = path..'_report.txt'
local f = io.open(mainReportName,'w+')
errReportName = path..'_errors.txt'
errRpt = io.open(errReportName,'w+')
dbgReportName = path..'_debug.txt'
dbgRpt = io.open(dbgReportName,'w+')
f:write('closetCleaner Report:\n')
f:write('=====================\n\n')
cc.export_inv(path)
cc.export_sets(path)
cc.export_inv(path, errRpt)
cc.export_sets(path, errRpt, dbgRpt, f)
for k,v in pairs(cc.sandbox.inventoryGear) do
if cc.sandbox.gsGear[k] == nil then
cc.sandbox.gsGear[k] = 0
Expand Down Expand Up @@ -140,18 +180,18 @@ function cc.run_report(path)
end
if ccDebug then
f2:close()
print("File created: "..ignoredReportName)
add_to_chat(1, "File created: "..ignoredReportName)
end
f:close()
print("File created: "..mainReportName)
add_to_chat(1, "File created: "..mainReportName)
end

function cc.xmlify(phrase)
if tonumber(phrase:sub(1,1)) then phrase = 'NUM'..phrase end
return phrase --:gsub('"','&quot;'):gsub("'","&apos;"):gsub('<','&lt;'):gsub('>','&gt;'):gsub('&&','&amp;')
end
-- This function tallies all the gear in your inventory
function cc.export_inv(path)
function cc.export_inv(path, errRpt)
if ccDebug then
reportName = path..'_inventory.txt'
finv = io.open(reportName,'w+')
Expand All @@ -173,7 +213,8 @@ function cc.export_inv(path)
elseif cc.sandbox.itemsBylongName[name:lower()] ~= nil then
itemid = cc.sandbox.itemsBylongName[name:lower()]
else
print("Item: "..name.." not found in gearswap.resources!")
errors = errors + 1
errRpt:write("Item: "..name.." not found in gearswap.resources!")
end
if ccDebug then
finv:write("Name: "..name.." Slot: "..slot.." Bag: "..gearswap.res.bags[n].english.."\n")
Expand All @@ -189,13 +230,13 @@ function cc.export_inv(path)
end
if ccDebug then
finv:close()
print("File created: "..reportName)
add_to_chat(1, "File created: "..reportName)
end
end

-- loads all the relevant jobs.lua files and inserts the sets tables into a supersets table:
-- supersets.<JOB>.sets....
function cc.export_sets(path)
function cc.export_sets(path, errRpt, dbgRpt, f)
if ccDebug then
reportName = path..'_sets.txt'
fsets = io.open(reportName,'w+')
Expand All @@ -210,13 +251,17 @@ function cc.export_sets(path)
fpath = string.lower(fpath)
dpath = fpath..'data/'
for i,v in ipairs(settings.ccjobs) do
dname = string.lower(dpath..player.name..'/'..v..'.lua')
dname = string.lower(dpath..player.name..'/'..v..'.lua')
lname = string.lower(dpath..player.name..'_'..v..'.lua')
selgearFull = string.lower(dpath..player.name..'/'..player.name..'_'..v..'_gear.lua')
selgearRel = string.lower('..'..'/data/'..player.name..'/'..player.name..'_'..v..'_gear')
lgname = string.lower(dpath..player.name..'_'..v..'_gear.lua')
sname = string.lower(dpath..v..'.lua')
sgname = string.lower(dpath..v..'_gear.lua')
if windower.file_exists(lgname) then
cc.supersets[v] = cc.extract_sets(lgname)
if windower.file_exists(selgearFull) then
cc.supersets[v] = cc.extract_sets_sel(selgearRel)
elseif windower.file_exists(lgname) then
cc.supersets[v] = cc.extract_sets(lgname)
elseif windower.file_exists(lname) then
cc.supersets[v] = cc.extract_sets(lname)
elseif windower.file_exists(sgname) then
Expand All @@ -226,15 +271,27 @@ function cc.export_sets(path)
elseif windower.file_exists(dname) then
cc.supersets[v] = cc.extract_sets(dname)
else
print('lua file for '..v..' not found!')
add_to_chat(3, 'Warning: lua file for '..v..' not found!')
end
end
cc.list_sets(cc.supersets, fsets)
cc.list_sets(cc.supersets, fsets, path, errRpt, dbgRpt, f)
cc.supersets = nil
if ccDebug then
fsets:close()
print("File created: "..reportName)
add_to_chat(1, "File created: "..reportName)
end
end

function cc.deepCopy(orig)
local copy = {}
for k, v in pairs(orig) do
if type(v) == 'table' then
copy[k] = cc.deepCopy(v)
else
copy[k] = v
end
end
return copy
end

-- sets the 'sets' and puts them into supersets based off file name.
Expand All @@ -243,41 +300,62 @@ function cc.extract_sets(file)
if user_file then
gearswap.setfenv(user_file, cc.sandbox)
cc.sandbox.sets = {}
user_file()
user_file()
local def_gear = cc.sandbox.init_get_sets or cc.sandbox.get_sets
if def_gear then
def_gear()
end
return table.copy(cc.sandbox.sets)
else
print('lua file for '..file..' not found!')
add_to_chat(3, 'lua file for '..file..' not found!')
end
end

-- sets the 'sets' and puts them into supersets based off file name.
function cc.extract_sets_sel(file)
sets = {}
cc.InitializeSetsForSelindrile() -- Must set each time after clearing out the sets list
if settings.ccSeluseGlobalItems then GetGlobalItems() end
include(file)
init_gear_sets() -- Selindrile uses this rather than get_sets
selsets = table.copy(sets)
sets = {}
return selsets
end

function cc.printTable(t, path, dbgRpt)
for k, v in pairs(t) do
local newPath = path .. (type(k) == "string" and "." .. k or "[" .. k .. "]")
if type(v) == "table" then
cc.printTable(v, newPath, dbgRpt)
elseif (type(v)=="string") then
dbgRpt:write(newPath..'='..v..'\n')
end
end
end

-- this function tallies the items used in each lua file
function cc.list_sets(t, f)
function cc.list_sets(t, fsets, path, errRpt, dbgRpt, f)
write_sets = T{}
local print_r_cache={}
local function sub_print_r(t,fromTab)
local function sub_print_r(t,fromTab,fullName)
if (type(t)=="table") then
for pos,val in pairs(t) do
if S{"WAR", "MNK", "WHM", "BLM", "RDM", "THF", "PLD", "DRK", "BST", "BRD", "RNG", "SAM", "NIN", "DRG", "SMN", "BLU", "COR", "PUP", "DNC", "SCH", "GEO", "RUN"}:contains(pos) then
job = pos
end
if (type(val)=="table") then
sub_print_r(val,job)
sub_print_r(val,job,fullName)
elseif (type(val)=="string") then
if val ~= "" and val ~= "empty" then
if S{"name", "main", "sub", "range", "ammo", "head", "neck", "left_ear", "right_ear", "body", "hands", "left_ring", "right_ring", "back", "waist", "legs", "feet", "ear1", "ear2", "ring1", "ring2", "lear", "rear", "lring", "rring"}:contains(pos) then
if cc.sandbox.itemsByName[val:lower()] ~= nil then
if cc.sandbox.itemsByName[val:lower()] ~= nil then
itemid = cc.sandbox.itemsByName[val:lower()]
elseif cc.sandbox.itemsBylongName[val:lower()] ~= nil then
itemid = cc.sandbox.itemsBylongName[val:lower()]
else
print("Item: '"..val.."' not found in gearswap.resources! "..pos)
end
if ccDebug then
f:write('Processing '..job..' name for val '..val..' id '..itemid..'\n')
errors = errors + 1
errRpt:write("Item: '"..val.."' Slot: "..pos.." => not found in gearswap.resources!\n")
end
if write_sets[itemid] == nil then
write_sets[itemid] = 1
Expand All @@ -298,31 +376,44 @@ function cc.list_sets(t, f)
end
end
elseif (type(val)=="number") then
print("Found Number: "..val.." from "..pos.." table "..t)
errors = errors + 1
errRpt:write("Found Number: "..val.." from "..pos.." table "..t..'\n')
else
print("Error: Val needs to be table or string "..type(val))
errors = errors + 1
errRpt:write("Error: Val needs to be table or string "..type(val)..'\n')
end
end
end
end
sub_print_r(t,nil)
sub_print_r(t,nil,nil)
if ccDebug then
data = T{"Name", " | ", "Count", " | ", "Jobs", " | ", "Long Name"}
form = T{"%22s", "%3s", "%10s", "%3s", "%88s", "%3s", "%60s"}
cc.print_row(f, data, form)
cc.print_break(f, form)
f:write('\n')
cc.print_row(fsets, data, form)
cc.print_break(fsets, form)
fsets:write('\n')
for k,v in pairs(write_sets) do
data = T{gearswap.res.items[k].english, " | ", tostring(v), " | ", cc.job_used[k], " | ", gearswap.res.items[k].english_log}
cc.print_row(f, data, form)
cc.print_row(fsets, data, form)
cc.sandbox.gsGear[k] = v
end
f:write()
fsets:write()
else
for k,v in pairs(write_sets) do
cc.sandbox.gsGear[k] = v
end
end
errRpt:close()

if errors > 0 then
add_to_chat(123, errors.." errors found, see report")
add_to_chat(123, "File created: "..errReportName)
end
if ccDebug then
cc.printTable(t, "sets", dbgRpt)
add_to_chat(1, "File created: "..dbgReportName)
end
dbgRpt:close()
end

-- interate throught table in a sorted order.
Expand Down