bdd-creature/classes/folderloader.lua

55 lines
1.5 KiB
Lua
Raw Permalink Normal View History

local FolderLoader = Object:extend()
2024-08-01 23:14:47 +02:00
local BeastFile = require "classes.beastfile"
2024-08-12 13:08:29 +02:00
local GroupFile = require "classes.groupfile"
function FolderLoader.getAllDatas(value, bestiaires, creatures)
local folderLoader = FolderLoader(value)
folderLoader:getDatas(bestiaires, creatures)
end
function FolderLoader:new(value)
self.folder = "data/" .. value.folder
self.data = {}
self.data.nom = value.nom
self.data.description = value.description
self.data.folder = value.folder
self.data.list = {}
2024-08-01 23:14:47 +02:00
self.files = {}
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))
2024-08-12 13:08:29 +02:00
elseif (file[2] == "group") then
table.insert(self.files, GroupFile(self.folder, filename))
2024-08-01 23:14:47 +02:00
else
print("[WARNING] Unknown extension " .. file[2] .. " for " .. filename)
end
end
end
function FolderLoader:prepareJson(simplercreatures, creatures)
2024-08-01 23:14:47 +02:00
for _, file in ipairs(self.files) do
2024-08-02 11:43:34 +02:00
file:prepareJson(simplercreatures, creatures, self.data.nom)
end
end
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