2024-08-01 21:47:28 +02:00
|
|
|
local FolderLoader = Object:extend()
|
2024-08-01 23:14:47 +02:00
|
|
|
local BeastFile = require "classes.beastfile"
|
2024-08-01 21:47:28 +02:00
|
|
|
|
2024-08-02 10:31:28 +02:00
|
|
|
function FolderLoader.getAllDatas(value, bestiaires, creatures)
|
2024-08-01 21:47:28 +02:00
|
|
|
local folderLoader = FolderLoader(value)
|
2024-08-02 10:31:28 +02:00
|
|
|
folderLoader:getDatas(bestiaires, creatures)
|
2024-08-01 21:47:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function FolderLoader:new(value)
|
|
|
|
self.folder = "data/" .. value.folder
|
|
|
|
|
|
|
|
self.data = {}
|
|
|
|
self.data.nom = value.nom
|
2024-08-02 10:31:28 +02:00
|
|
|
self.data.description = value.description
|
|
|
|
self.data.folder = value.folder
|
2024-08-01 21:47:28 +02:00
|
|
|
self.data.list = {}
|
|
|
|
|
2024-08-01 23:14:47 +02:00
|
|
|
self.files = {}
|
|
|
|
|
2024-08-01 21:47:28 +02:00
|
|
|
for _, filename in ipairs(utils.scandir(self.folder)) do
|
2024-08-01 23:14:47 +02:00
|
|
|
local file = utils.split(filename, ".", true)
|
|
|
|
if (file[2] == "beast") then
|
|
|
|
table.insert(self.files, BeastFile(self.folder, filename))
|
|
|
|
else
|
|
|
|
print("[WARNING] Unknown extension " .. file[2] .. " for " .. filename)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-08-02 10:31:28 +02:00
|
|
|
function FolderLoader:prepareJson(simplercreatures, creatures)
|
2024-08-01 23:14:47 +02:00
|
|
|
for _, file in ipairs(self.files) do
|
2024-08-02 10:31:28 +02:00
|
|
|
file:prepareJson(simplercreatures, creatures)
|
2024-08-01 21:47:28 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-08-02 10:31:28 +02:00
|
|
|
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)
|
2024-08-01 21:47:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return FolderLoader
|