foundryvtt-wh4-lang-fr-fr/tools/foundry_wh4_generic_merge.lua

30 lines
723 B
Lua
Raw Permalink Normal View History

2021-02-11 20:32:34 +01:00
package.path = package.path .. ";luajson/?.lua"
local JSON = require"json"
local oldf = "../compendium/wfrp4e-core.criticals.json.SAVED"
local newf = "../compendium/wfrp4e-core.criticals.json"
local origin = io.open(oldf, "r")
local strjson = origin:read("*a")
origin:close()
local oldjson = JSON.decode(strjson)
local new = io.open(newf, "r")
strjson = new:read("*a")
new:close()
local newjson = JSON.decode(strjson)
for _, newItem in pairs(newjson.entries) do
for _, oldItem in pairs(oldjson.entries) do
if newItem.name == oldItem.name then
newItem.id = oldItem.id
end
end
end
local jsonout = JSON.encode( newjson )
local fout = io.open("output.json", "w+")
fout:write( jsonout )
fout:close()