bdd-creature/classes/folderloader.lua

52 lines
1.4 KiB
Lua
Raw Normal View History

local FolderLoader = Object:extend()
2024-08-01 23:14:47 +02:00
local BeastFile = require "classes.beastfile"
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))
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
file:prepareJson(simplercreatures, creatures)
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