modules/assets: add a basic batch importing system
This commit is contained in:
parent
fc34cdc199
commit
5055f84320
1 changed files with 79 additions and 0 deletions
|
@ -63,6 +63,85 @@ function Assets:update(dt)
|
||||||
end
|
end
|
||||||
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
|
-- SFX & MUSICS
|
||||||
-- Handle sound effects and musics
|
-- Handle sound effects and musics
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue