local func = loadfile(...) loadfile("load-all-item-info.lua")() func() func = loadfile("scanned/ItemsThatNeedManualIntervention.lua") if func then func() end if not ItemsThatNeedManualIntervention then ItemsThatNeedManualIntervention = {} end IS_invalid_items = IS_status.items.invalid for k, v in pairs(item_info) do if IS_item_info[k] then if #(v) > #(IS_item_info[k]) then ItemsThatNeedManualIntervention[k] = IS_item_info[k] IS_item_info[k] = v else ItemsThatNeedManualIntervention[k] = nil end elseif type(k) ~= "string" then ItemsThatNeedManualIntervention[k] = string.format("Unknown item link format: %q", tostring(k)) else local start, _, itemNum = k:find("^item:(%d+):0:0:0:0:0:0:0:") if start then itemNum = tonumber(itemNum) if type(IS_invalid_items[itemNum]) == "number" then if IS_invalid_items[itemNum] > 10 then v = nil ItemsThatNeedManualIntervention[k] = nil end elseif IS_invalid_items[itemNum] == true then ItemsThatNeedManualIntervention[k] = "Exists in old data, but marked definitely invalid" elseif IS_invalid_items[itemNum] ~= false and IS_invalid_items[itemNum] ~= nil then ItemsThatNeedManualIntervention[k] = string.format("Unhandled invalid item type: %s (tostring = %q)", type(IS_invalid_items[itemNum]), tostring(IS_invalid_items[itemNum])) end IS_item_info[k] = v else ItemsThatNeedManualIntervention[k] = string.format("Unknown item link format: %q", k) end end end loadfile("sort.lua")() local tbl = { ["^item:%d%d?%d?:0:0:0:0:0:0:0:"] = "00000_00999", } for i = 1, 99 do local padded = string.sub("00" .. i, -2) tbl["^item:" .. i .. "%d%d%d:0:0:0:0:0:0:0:"] = padded .. "000_" .. padded .. "999" end local savedVars = { ["IS_item_info"] = {"scanned/item-info-%s.lua", tbl}, ["IS_invalid_items"] = "scanned/invalid-items.lua", ["ItemsThatNeedManualIntervention"] = "scanned/ItemsThatNeedManualIntervention.lua", } for varName, fileName in pairs(savedVars) do local splitType, splitParam = "none" if type(fileName) == "table" then fileName, splitParam = unpack(fileName) if fileName:find("%%s") then splitType = "string" end end local var = _G[varName] if type(var) == "number" then io.output(fileName) io.write(string.format("%s = %d", varName, var)) io.close() elseif type(var) == "table" then io.stdout:write(string.format("%sSaving %s...", string.rep("\8 \8", 50), varName)) io.stdout:flush() if splitType == "none" then io.output(fileName) sort(var, varName) io.close() elseif splitType == "string" then local tempArr = {} for k, v in pairs(var) do local c = k local fileNamePart for k, v in pairs(splitParam) do if string.match(c, k) then fileNamePart = v break end end fileNamePart = fileNamePart or "other" if not tempArr[fileNamePart] then tempArr[fileNamePart] = {} end tempArr[fileNamePart][k] = v end for k, v in pairs(tempArr) do io.output(string.format(fileName, k)) if k == "" then sort(v, varName) else sort(v, varName .. "_" .. k) end io.output():close() end else io.stdout:write(string.format("\nError: Unknown splitType \"%s\" for var %q\n", splitType, varName)) io.stdout:flush() end else io.stdout:write(string.format("Unhandled variable type: %q (%s)\n", type(var), varName)) end end io.stdout:write("\n")