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

110 lines
3.5 KiB
Lua
Raw Permalink 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 SIZE2FR = { Size = "Taille",
Tiny = "Minuscule",
Little = "Très petite",
Small = "Petit",
Average = "Moyenne",
Large = "Grande",
Enormous = "Enorme",
Monstrous = "Monstrueuse",
Difficulty = "Difficulté",
Everything = "Tout",
Moderate= "Modéré",
Major= "Majeur",
Minor= "Mineur",
Greenskins= "Peaux vertes",
Challenging= "Intermédiaire",
Elves = "Elfes",
}
local table
2020-04-06 23:20:27 +02:00
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
print("Testing", beastfr.name)
2020-04-06 23:20:27 +02:00
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
2020-04-22 20:22:34 +02:00
--local uniq = io.open(beast.name .. ".json", "w+")
--uniq:write(line)
--uniq:close()
2020-04-06 23:20:27 +02:00
--print(beast.name, beast.items)
if beast.items then
local myitems = {}
2020-04-06 23:20:27 +02:00
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
--local newtrait = { }
2020-04-22 20:22:34 +02:00
--traitbeast.id = trim1(traitbeast.name)
traitbeast._id = nil
traitbeast.name = trim1(traitdata.name)
2020-04-22 20:22:34 +02:00
if traitbeast.data.description then
traitbeast.data.description.value = traitdata.description
end
if SIZE2FR[traitbeast.data.specification.value] then
traitbeast.data.specification.value = SIZE2FR[traitbeast.data.specification.value]
end
2020-04-20 09:18:48 +02:00
print(" Found trait " .. traitdata.name)
--newtrait.specification = traitbeast.data.specification.value
--myitems[#myitems+1] = newtrait
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
2020-04-22 20:22:34 +02:00
--sel_beastfr.items = beast.items
--sel_beastfr.items = myitems
2020-04-22 20:22:34 +02:00
sel_beastfr.items = nil
2020-04-06 23:20:27 +02:00
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()