foundryvtt-wh4-lang-fr-fr/tools/foundry_wh4_bestiary_french...

73 lines
2.3 KiB
Lua
Raw Normal View History

2020-04-06 23:20:27 +02:00
2020-04-20 09:18:48 +02:00
package.path = package.path .. ";luajson/?.lua"
2020-04-06 23:20:27 +02:00
local JSON = require"json"
local path_in = "/home/sigmar/work/foundryvtt/WFRP-4th-Edition-FoundryVTT/packs/"
local traitsf = "/home/sigmar/work/foundryvtt/foundryvtt-wh4-lang-fr-fr/compendium/wfrp4e.traits.json"
local beastsf = "/home/sigmar/work/foundryvtt/foundryvtt-wh4-lang-fr-fr/compendium/wfrp4e.bestiary.json"
local f1 = io.open(path_in .. "bestiary.db")
local f2 = io.open(traitsf)
local strjson = f2:read("*a")
f2:close()
local traits = JSON.decode(strjson)
local f3 = io.open(beastsf)
local beastjson = f3:read("*a")
f3:close()
local beast_french = JSON.decode(beastjson)
local function trim1(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
local line = f1:read()
while line do
--print(line)
local beast = JSON.decode( line)
-- Get the french beast translation
local sel_beastfr
for _, beastfr in pairs(beast_french.entries) do
if beast.name:lower() == beastfr.id:lower() then
sel_beastfr = beastfr
break
end
end
if not sel_beastfr then print(">>>>>>>>>>>>>>> NO BEAST !!!", beast.name) end
--print(beast.name, beast.items)
if beast.items then
for _, traitbeast in pairs( beast.items) do
if traitbeast.name then
2020-04-20 09:18:48 +02:00
print(beast.name, traitbeast.name)
2020-04-06 23:20:27 +02:00
local found, ntentacle = false
local name, bonus_or_category = traitbeast.name:match("([%w%s]+)%s%(([%s%w]+)%)")
if not name then ntentacle, name = traitbeast.name:match("(%d)x%s*(Tentacles)") end
if not name then name = traitbeast.name end
for _, traitdata in pairs(traits.entries) do
if traitdata.id == trim1(name) then
found = true
2020-04-20 09:18:48 +02:00
--traitbeast._id = nil
--traitbeast.id = traitbeast.name --Swap !
2020-04-06 23:20:27 +02:00
traitbeast.name = traitdata.name
traitbeast.data.description.value = traitdata.description
2020-04-20 09:18:48 +02:00
print(" Found trait " .. traitdata.name)
2020-04-06 23:20:27 +02:00
break
end
end
if not found then
print(" > NOT FOUND !!!", beast.name, name, traitbeast.name)
end
end
end
sel_beastfr.items = beast.items
end
line = f1:read()
end
f1:close()
local jsonout = JSON.encode( beast_french )
local fout = io.open("beasts.json", "w+")
fout:write( jsonout )
2020-04-20 09:18:48 +02:00
fout:close()