sonic-radiance/sonic-radiance.love/game/utils/items.lua
2020-08-15 22:43:46 +02:00

45 lines
1.2 KiB
Lua

local ItemUtils = {}
local datasutils = require "game.utils.datas"
local DIR = "items"
function ItemUtils.getBaseDirectory(lua)
return datasutils.concatDataFolder(DIR, lua)
end
function ItemUtils.listCategories()
return require(ItemUtils.getBaseDirectory(true))
end
function ItemUtils.getCategoryDirectory(directory, lua)
return datasutils.concatFolder(ItemUtils.getBaseDirectory(lua), directory, lua)
end
function ItemUtils.getItemsFromCategory(directory)
local folder = ItemUtils.getCategoryDirectory(directory, false)
local baseTable = love.filesystem.getDirectoryItems(folder)
return datasutils.luaFileListToModuleList(baseTable)
end
function ItemUtils.getItemFile(category, item, lua)
local dir = ItemUtils.getCategoryDirectory(category, lua)
local path = datasutils.concatFolder(dir, item, lua)
if (not lua) then
path = path .. ".lua"
end
return path
end
function ItemUtils.itemExists(category, item)
local path = ItemUtils.getItemFile(category, item, false)
local fileinfo = love.filesystem.getInfo(path)
return (fileinfo ~= nil)
end
function ItemUtils.getItemData(category, item)
local path = ItemUtils.getItemFile(category, item, true)
return datasutils.copy(path)
end
return ItemUtils