feat: add a data utils
This commit is contained in:
parent
b8e8473fba
commit
1935659378
2 changed files with 70 additions and 6 deletions
|
@ -1,7 +1,8 @@
|
||||||
local CharUtils = {}
|
local CharUtils = {}
|
||||||
|
|
||||||
local CONST = {}
|
local datasutils = require "game.utils.datas"
|
||||||
|
|
||||||
|
local CONST = {}
|
||||||
CONST.EXP_MULTIPLICATOR = 4
|
CONST.EXP_MULTIPLICATOR = 4
|
||||||
CONST.EXP_RATIO = 5
|
CONST.EXP_RATIO = 5
|
||||||
|
|
||||||
|
@ -14,6 +15,18 @@ CONST.MULT_HP = 7.5
|
||||||
CONST.SALT_HP = 35
|
CONST.SALT_HP = 35
|
||||||
CONST.MULT_MP = 1.5
|
CONST.MULT_MP = 1.5
|
||||||
|
|
||||||
|
local DIR = "characters"
|
||||||
|
|
||||||
|
function CharUtils.getBaseDirectory(lua)
|
||||||
|
return datasutils.concatDataFolder(DIR, lua)
|
||||||
|
end
|
||||||
|
|
||||||
|
function CharUtils.getCharacterDirectory(name, lua)
|
||||||
|
local baseDirectory = CharUtils.getBaseDirectory(lua)
|
||||||
|
return datasutils.concatFolder(baseDirectory, name, lua)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function CharUtils.getExpValue(level)
|
function CharUtils.getExpValue(level)
|
||||||
return math.floor( ( CONST.EXP_MULTIPLICATOR * ( level ^ 3 ) ) / CONST.EXP_RATIO )
|
return math.floor( ( CONST.EXP_MULTIPLICATOR * ( level ^ 3 ) ) / CONST.EXP_RATIO )
|
||||||
end
|
end
|
||||||
|
@ -31,18 +44,18 @@ function CharUtils.getPPValue(level, base)
|
||||||
end
|
end
|
||||||
|
|
||||||
function CharUtils.charDataExists(name)
|
function CharUtils.charDataExists(name)
|
||||||
local dir = "datas/gamedata/characters/" .. name .. "/init.lua"
|
local dir = CharUtils.getCharacterDirectory(name, false) .. "/init.lua"
|
||||||
local fileinfo = love.filesystem.getInfo(dir)
|
local fileinfo = love.filesystem.getInfo(dir)
|
||||||
return (fileinfo ~= nil)
|
return (fileinfo ~= nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
function CharUtils.getCharacterData(charname)
|
function CharUtils.getCharacterData(charname)
|
||||||
-- va eprmettre de récupérer les données d'un personnage
|
-- va eprmettre de récupérer les données d'un personnage
|
||||||
local charfolder = "datas.gamedata.characters." .. charname
|
local charfolder = CharUtils.getCharacterDirectory(charname, true)
|
||||||
local character = require(charfolder)
|
local character = require(charfolder)
|
||||||
character.stats = require(charfolder .. ".stats")
|
character.stats = datasutils.require(charfolder, "stats")
|
||||||
character.inventory = require(charfolder .. ".inventory")
|
character.inventory = datasutils.require(charfolder, "inventory")
|
||||||
character.skills = require(charfolder .. ".skills")
|
character.skills = datasutils.require(charfolder, "skills")
|
||||||
|
|
||||||
return character
|
return character
|
||||||
end
|
end
|
||||||
|
|
51
sonic-radiance.love/game/utils/datas.lua
Normal file
51
sonic-radiance.love/game/utils/datas.lua
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
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
|
Loading…
Reference in a new issue