fix: refonte des fichiers
Maintenant utilisation de plutôt deux fichier séparé, un contenant toutes les créatures et un autre contenant les bestiaires
This commit is contained in:
parent
7a972d4726
commit
9b1d92449e
5 changed files with 47 additions and 22 deletions
|
@ -38,8 +38,10 @@ function BeastFile:loadMixin(mixin)
|
|||
end
|
||||
end
|
||||
|
||||
function BeastFile:prepareJson()
|
||||
return self.datas:prepareJson()
|
||||
function BeastFile:prepareJson(simplercreatures, creatures)
|
||||
assert(simplercreatures ~= nil)
|
||||
assert(creatures ~= nil)
|
||||
self.datas:prepareJson(simplercreatures, creatures)
|
||||
end
|
||||
|
||||
return BeastFile
|
|
@ -97,9 +97,11 @@ function DataList:reduce()
|
|||
--TODO
|
||||
end
|
||||
|
||||
function DataList:prepareJson()
|
||||
function DataList:prepareJson(simplercreatures, creatures)
|
||||
self:reduce()
|
||||
return self.reducedList
|
||||
|
||||
table.insert(simplercreatures, {nom = self.reducedList.name, level = self.reducedList.level, nomType = self.reducedList.nomType, categorie = self.reducedList.categorie})
|
||||
table.insert(creatures, self.reducedList)
|
||||
end
|
||||
|
||||
return DataList
|
|
@ -1,9 +1,9 @@
|
|||
local FolderLoader = Object:extend()
|
||||
local BeastFile = require "classes.beastfile"
|
||||
|
||||
function FolderLoader.getAllDatas(value)
|
||||
function FolderLoader.getAllDatas(value, bestiaires, creatures)
|
||||
local folderLoader = FolderLoader(value)
|
||||
return folderLoader:getDatas()
|
||||
folderLoader:getDatas(bestiaires, creatures)
|
||||
end
|
||||
|
||||
function FolderLoader:new(value)
|
||||
|
@ -11,6 +11,8 @@ function FolderLoader:new(value)
|
|||
|
||||
self.data = {}
|
||||
self.data.nom = value.nom
|
||||
self.data.description = value.description
|
||||
self.data.folder = value.folder
|
||||
self.data.list = {}
|
||||
|
||||
self.files = {}
|
||||
|
@ -25,16 +27,26 @@ function FolderLoader:new(value)
|
|||
end
|
||||
end
|
||||
|
||||
function FolderLoader:prepareJson()
|
||||
function FolderLoader:prepareJson(simplercreatures, creatures)
|
||||
for _, file in ipairs(self.files) do
|
||||
table.insert(self.data.list, file:prepareJson())
|
||||
file:prepareJson(simplercreatures, creatures)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function FolderLoader:getDatas()
|
||||
self:prepareJson()
|
||||
return self.data
|
||||
function FolderLoader:getDatas(bestiaires, creatures)
|
||||
local simplercreatures = {}
|
||||
self:prepareJson(simplercreatures, creatures)
|
||||
|
||||
|
||||
local bestiaire = {
|
||||
nom = self.data.nom,
|
||||
description = self.data.description,
|
||||
folder = self.data.folder,
|
||||
list = simplercreatures
|
||||
}
|
||||
|
||||
table.insert(bestiaires, bestiaire)
|
||||
end
|
||||
|
||||
return FolderLoader
|
|
@ -1,3 +1,3 @@
|
|||
return {
|
||||
{nom = "Animaux", folder = "animaux"}
|
||||
{nom = "Animaux", folder = "animaux", description = "Des animaux génériques et communs (ou moins communs)"}
|
||||
}
|
33
main.lua
33
main.lua
|
@ -4,17 +4,26 @@ local FolderLoader = require "classes.folderloader"
|
|||
|
||||
local json = require "libs.json"
|
||||
|
||||
print("Début de génération des fichiers .json")
|
||||
clock = os.clock()
|
||||
|
||||
local bestiaires = {}
|
||||
local creatures = {}
|
||||
|
||||
for _, value in ipairs(config) do
|
||||
print("Début de génération du fichier " .. value.folder .. ".json")
|
||||
clock = os.clock()
|
||||
|
||||
local datas = FolderLoader.getAllDatas(value)
|
||||
|
||||
local file = io.open("build/" .. value.folder .. ".json", "w")
|
||||
if (file ~= nil) then
|
||||
file:write(json.encode(datas))
|
||||
end
|
||||
|
||||
clock = os.clock() - clock
|
||||
print("Génération du fichier " .. value.folder .. ".json en " .. clock .. " seconds")
|
||||
print("Charagement de la catégorie " .. value.nom)
|
||||
FolderLoader.getAllDatas(value, bestiaires, creatures)
|
||||
end
|
||||
|
||||
local file = io.open("build/bestiaires.json", "w")
|
||||
if (file ~= nil) then
|
||||
file:write(json.encode(bestiaires))
|
||||
end
|
||||
|
||||
local file2 = io.open("build/creatures.json", "w")
|
||||
if (file2 ~= nil) then
|
||||
file2:write(json.encode(creatures))
|
||||
end
|
||||
|
||||
clock = os.clock() - clock
|
||||
print("Génération du fichier .json en " .. clock .. " seconds")
|
Loading…
Reference in a new issue