Files
PathOfBuilding/Export/_common.lua
Openarl 9772c87121 Release 1.4.15
- Added handling for level and attribute requirements
- Fixed Witchfire Brew/Umbilicus Immortalis interaction
- Overhauled export system; added item base export
2017-05-26 23:39:11 +10:00

94 lines
2.2 KiB
Lua

json = require("dkjson")
function printf(...)
print(string.format(...))
end
function round(val, dec)
if dec then
return math.floor(val * 10 ^ dec + 0.5) / 10 ^ dec
else
return math.floor(val + 0.5)
end
end
function processTemplateFile(name, directiveTable)
local state = { }
local out = io.open(name..".lua", "w")
out:write("-- This file is automatically generated, do not edit!\n")
for line in io.lines(name..".txt") do
local spec, args = line:match("#(%a+) ?(.*)")
if spec then
if directiveTable[spec] then
directiveTable[spec](state, args, out)
else
printf("Unknown directive '%s'", spec)
end
else
out:write(line, "\n")
end
end
out:close()
end
function loadDat(name)
if _G[name] then
return
end
printf("Loading '%s'...", name)
local f = io.open(name..".json", "r")
if not f then
os.execute("pypoe_exporter dat json "..name..".json --files "..name..".dat")
f = io.open(name..".json", "r")
end
local text = f:read("*a")
f:close()
local t = json.decode(text)[1]
local headerMap = { }
for i, header in pairs(t.header) do
headerMap[header.name] = i
end
local rowMeta = {
__index = function(self, index)
if index == "print" then
return function()
for i, header in pairs(t.header) do
printf("%s = %s", header.name, type(self[i]) == "table" and ("{ "..table.concat(self[i], ", ").." }") or self[i])
end
end
else
return rawget(self, headerMap[index])
end
end
}
_G[name] = setmetatable({ maxRow = #t.data - 1, headerMap = headerMap }, {
__index = function(self, index)
if type(index) == "number" then
return setmetatable(t.data[index + 1], rowMeta)
elseif headerMap[index] then
return function(val, match)
local col = headerMap[index]
local out = { }
for index, row in ipairs(t.data) do
if type(row[col]) == "table" then
for _, v in pairs(row[col]) do
if (match and v:match(val)) or (not match and v == val) then
table.insert(out, index - 1)
break
end
end
else
if (match and row[col]:match(val)) or (not match and row[col] == val) then
table.insert(out, index - 1)
end
end
end
return out
end
end
end
})
_G[name:gsub("%l","")] = _G[name]
end