diff --git a/gamecore/modules/assets/init.lua b/gamecore/modules/assets/init.lua index 04a7c02..f6fde88 100644 --- a/gamecore/modules/assets/init.lua +++ b/gamecore/modules/assets/init.lua @@ -63,6 +63,85 @@ function Assets:update(dt) end end +-- IMPORT FUNCTIONS +-- Easilly import assets + +function Assets:batchImport(datafile) + local datas = require(datafile) + + for asset_type, assets in pairs(datas) do + if (asset_type == "autotiles") then + self:importAutotiles(assets) + elseif (asset_type == "backgrounds") then + self:importBackgrounds(assets) + elseif (asset_type == "fonts") then + self:importFonts(assets) + elseif (asset_type == "imagefonts") then + self:importImageFonts(assets) + elseif (asset_type == "images") then + self:importTextures(assets) + elseif (asset_type == "sprites") then + self:importSprites(assets) + elseif (asset_type == "textures") then + self:importTextures(assets) + elseif (asset_type == "tilesets") then + self:importTilesets(assets) + elseif (asset_type == "sfx") then + self:importSFX(assets) + else + print("Unkown asset type : " .. asset_type) + end + end +end + +function Assets:importAutotiles(assets) + for i, asset in ipairs(assets) do + self:addAutotile(asset[1], asset[2]) + end +end + +function Assets:importBackgrounds(assets) + for i, asset in ipairs(assets) do + self:addBackground(asset[1], asset[2]) + end +end + +function Assets:importFonts(assets) + for i, asset in ipairs(assets) do + self:addFont(asset[1], asset[2], asset[3]) + end +end + +function Assets:importImageFonts(assets) + for i, asset in ipairs(assets) do + self:addImageFont(asset[1], asset[2], asset[3]) + end +end + +function Assets:importSprites(assets) + for i, asset in ipairs(assets) do + self:addSprite(asset[1], asset[2]) + end +end + +function Assets:importTextures(assets) + for i, asset in ipairs(assets) do + self:addImage(asset[1], asset[2]) + end +end + +function Assets:importTilesets(assets) + for i, asset in ipairs(assets) do + self:addTileset(asset[1], asset[2]) + end +end + +function Assets:importSFX(assets) + for i, asset in ipairs(assets) do + self:addSFX(asset[1], asset[2]) + end +end + -- SFX & MUSICS -- Handle sound effects and musics