sonic-radiance/sonic-radiance.love/game/utils/datas.lua

52 lines
1.1 KiB
Lua
Raw Normal View History

2020-08-04 16:55:09 +02:00
DataUtils = {}
local DATADIR = "datas"
local GAMEDATADIR = "gamedata"
function DataUtils.isLuaFile(name)
local extension = name:sub(#name - 4, #name)
return (extension == ".lua")
end
function DataUtils.luaFileToModule(luaFile)
if (not DataUtils.isLuaFile(luaFile)) then
return luaFile:sub(1, #luaFile - 4)
else
return luaFile
end
end
function DataUtils.luaFileListToModuleList(luaFileList)
local moduleList = {}
for i,luaFile in ipairs(luaFileList) do
table.insert(moduleList, DataUtils.luaFileToModule(luaFile))
end
return moduleList
end
function DataUtils.require(parent, filename)
return require(DataUtils.concatFolder(parent, filename, true))
end
function DataUtils.concatDataFolder(folder, lua)
return DataUtils.concatFolder(DataUtils.getGameDataDir(lua), folder, lua)
end
function DataUtils.getGameDataDir(lua)
return DataUtils.concatFolder(DATADIR, GAMEDATADIR, lua)
end
function DataUtils.concatFolder(parent, filename, lua)
return parent .. DataUtils.sep(lua) .. filename
end
function DataUtils.sep(lua)
if (lua) then
return "."
else
return "/"
end
end
return DataUtils