From 9b1d92449e2e17975a253c218093313708aa0d5a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 2 Aug 2024 10:31:28 +0200 Subject: [PATCH] fix: refonte des fichiers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Maintenant utilisation de plutôt deux fichier séparé, un contenant toutes les créatures et un autre contenant les bestiaires --- classes/beastfile.lua | 6 ++++-- classes/datalist.lua | 6 ++++-- classes/folderloader.lua | 26 +++++++++++++++++++------- config.lua | 2 +- main.lua | 29 +++++++++++++++++++---------- 5 files changed, 47 insertions(+), 22 deletions(-) diff --git a/classes/beastfile.lua b/classes/beastfile.lua index e92ac81..5c4a8c8 100644 --- a/classes/beastfile.lua +++ b/classes/beastfile.lua @@ -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 \ No newline at end of file diff --git a/classes/datalist.lua b/classes/datalist.lua index e06e0a8..1174261 100644 --- a/classes/datalist.lua +++ b/classes/datalist.lua @@ -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 \ No newline at end of file diff --git a/classes/folderloader.lua b/classes/folderloader.lua index 5ac953f..47da205 100644 --- a/classes/folderloader.lua +++ b/classes/folderloader.lua @@ -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 \ No newline at end of file diff --git a/config.lua b/config.lua index 7eb3c2f..7baedf5 100644 --- a/config.lua +++ b/config.lua @@ -1,3 +1,3 @@ return { - {nom = "Animaux", folder = "animaux"} + {nom = "Animaux", folder = "animaux", description = "Des animaux génériques et communs (ou moins communs)"} } \ No newline at end of file diff --git a/main.lua b/main.lua index 3bbcde4..57d4dda 100644 --- a/main.lua +++ b/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() + print("Charagement de la catégorie " .. value.nom) + FolderLoader.getAllDatas(value, bestiaires, creatures) +end - local datas = FolderLoader.getAllDatas(value) +local file = io.open("build/bestiaires.json", "w") +if (file ~= nil) then + file:write(json.encode(bestiaires)) +end - local file = io.open("build/" .. value.folder .. ".json", "w") - if (file ~= nil) then - file:write(json.encode(datas)) - 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 " .. value.folder .. ".json en " .. clock .. " seconds") -end \ No newline at end of file +clock = os.clock() - clock +print("Génération du fichier .json en " .. clock .. " seconds") \ No newline at end of file