chore: make the datas utils a part of birb
This commit is contained in:
parent
1991b5005f
commit
33d854ffd4
6 changed files with 23 additions and 30 deletions
|
@ -31,4 +31,5 @@ return {
|
||||||
table = require(cwd .. "table"),
|
table = require(cwd .. "table"),
|
||||||
string = require(cwd .. "string"),
|
string = require(cwd .. "string"),
|
||||||
time = require(cwd .. "time"),
|
time = require(cwd .. "time"),
|
||||||
|
datas = require(cwd .. "datas")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
local BattleUtils = {}
|
local BattleUtils = {}
|
||||||
|
|
||||||
local datasutils = require "game.utils.datas"
|
|
||||||
|
|
||||||
local DIR = "battles"
|
local DIR = "battles"
|
||||||
|
|
||||||
function BattleUtils.getBaseDirectory(lua)
|
function BattleUtils.getBaseDirectory(lua)
|
||||||
return datasutils.concatDataFolder(DIR, lua)
|
return utils.datas.concatDataFolder(DIR, lua)
|
||||||
end
|
end
|
||||||
|
|
||||||
function BattleUtils.listCategories()
|
function BattleUtils.listCategories()
|
||||||
|
@ -14,7 +12,7 @@ end
|
||||||
|
|
||||||
function BattleUtils.getCategoryDirectory(directory, lua)
|
function BattleUtils.getCategoryDirectory(directory, lua)
|
||||||
local baseDir = BattleUtils.getBaseDirectory(lua)
|
local baseDir = BattleUtils.getBaseDirectory(lua)
|
||||||
return datasutils.concatFolder(baseDir, directory, lua)
|
return utils.datas.concatFolder(baseDir, directory, lua)
|
||||||
end
|
end
|
||||||
|
|
||||||
function BattleUtils.getDirectoryLuaStyle(directory)
|
function BattleUtils.getDirectoryLuaStyle(directory)
|
||||||
|
@ -23,12 +21,12 @@ end
|
||||||
|
|
||||||
function BattleUtils.getBattleFromCategory(directory)
|
function BattleUtils.getBattleFromCategory(directory)
|
||||||
local folder = BattleUtils.getCategoryDirectory(directory, false)
|
local folder = BattleUtils.getCategoryDirectory(directory, false)
|
||||||
return datasutils.luaFileListToModuleList(love.filesystem.getDirectoryItems(folder))
|
return utils.datas.luaFileListToModuleList(love.filesystem.getDirectoryItems(folder))
|
||||||
end
|
end
|
||||||
|
|
||||||
function BattleUtils.getBattleData(directory, battlename)
|
function BattleUtils.getBattleData(directory, battlename)
|
||||||
local categoryDir = BattleUtils.getCategoryDirectory(directory, true)
|
local categoryDir = BattleUtils.getCategoryDirectory(directory, true)
|
||||||
return datasutils.require(categoryDir, battlename)
|
return utils.datas.require(categoryDir, battlename)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ENNEMY FUNCTIONS
|
-- ENNEMY FUNCTIONS
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
local CharUtils = {}
|
local CharUtils = {}
|
||||||
|
|
||||||
local datasutils = require "game.utils.datas"
|
|
||||||
|
|
||||||
local CONST = {}
|
local CONST = {}
|
||||||
CONST.EXP_MULTIPLICATOR = 4
|
CONST.EXP_MULTIPLICATOR = 4
|
||||||
CONST.EXP_RATIO = 5
|
CONST.EXP_RATIO = 5
|
||||||
|
@ -18,12 +16,12 @@ CONST.MULT_MP = 1.5
|
||||||
local DIR = "characters"
|
local DIR = "characters"
|
||||||
|
|
||||||
function CharUtils.getBaseDirectory(lua)
|
function CharUtils.getBaseDirectory(lua)
|
||||||
return datasutils.concatDataFolder(DIR, lua)
|
return utils.datas.concatDataFolder(DIR, lua)
|
||||||
end
|
end
|
||||||
|
|
||||||
function CharUtils.getCharacterDirectory(name, lua)
|
function CharUtils.getCharacterDirectory(name, lua)
|
||||||
local baseDirectory = CharUtils.getBaseDirectory(lua)
|
local baseDirectory = CharUtils.getBaseDirectory(lua)
|
||||||
return datasutils.concatFolder(baseDirectory, name, lua)
|
return utils.datas.concatFolder(baseDirectory, name, lua)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,10 +62,10 @@ 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 = CharUtils.getCharacterDirectory(charname, true)
|
local charfolder = CharUtils.getCharacterDirectory(charname, true)
|
||||||
local character = datasutils.copy(charfolder)
|
local character = utils.datas.copy(charfolder)
|
||||||
character.stats = datasutils.copyDataset(charfolder, "stats")
|
character.stats = utils.datas.copyDataset(charfolder, "stats")
|
||||||
character.inventory = datasutils.copyDataset(charfolder, "inventory")
|
character.inventory = utils.datas.copyDataset(charfolder, "inventory")
|
||||||
character.skills = datasutils.copyDataset(charfolder, "skills")
|
character.skills = utils.datas.copyDataset(charfolder, "skills")
|
||||||
|
|
||||||
return character
|
return character
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
local EnnemyUtils = {}
|
local EnnemyUtils = {}
|
||||||
|
|
||||||
local datasutils = require "game.utils.datas"
|
|
||||||
|
|
||||||
local DIR = "ennemies"
|
local DIR = "ennemies"
|
||||||
|
|
||||||
function EnnemyUtils.getBaseDirectory(lua)
|
function EnnemyUtils.getBaseDirectory(lua)
|
||||||
return datasutils.concatDataFolder(DIR, lua)
|
return utils.datas.concatDataFolder(DIR, lua)
|
||||||
end
|
end
|
||||||
|
|
||||||
function EnnemyUtils.listCategories()
|
function EnnemyUtils.listCategories()
|
||||||
|
@ -13,12 +11,12 @@ function EnnemyUtils.listCategories()
|
||||||
end
|
end
|
||||||
|
|
||||||
function EnnemyUtils.getCategoryDirectory(directory, lua)
|
function EnnemyUtils.getCategoryDirectory(directory, lua)
|
||||||
return datasutils.concatFolder(EnnemyUtils.getBaseDirectory(lua), directory, lua)
|
return utils.datas.concatFolder(EnnemyUtils.getBaseDirectory(lua), directory, lua)
|
||||||
end
|
end
|
||||||
|
|
||||||
function EnnemyUtils.getEnnemyFolder(directory, ennemy, lua)
|
function EnnemyUtils.getEnnemyFolder(directory, ennemy, lua)
|
||||||
local categoryDirectory = EnnemyUtils.getCategoryDirectory(directory, lua)
|
local categoryDirectory = EnnemyUtils.getCategoryDirectory(directory, lua)
|
||||||
return datasutils.concatFolder(categoryDirectory, ennemy, lua)
|
return utils.datas.concatFolder(categoryDirectory, ennemy, lua)
|
||||||
end
|
end
|
||||||
|
|
||||||
function EnnemyUtils.getEnnemiesFromCategory(directory)
|
function EnnemyUtils.getEnnemiesFromCategory(directory)
|
||||||
|
@ -27,7 +25,7 @@ function EnnemyUtils.getEnnemiesFromCategory(directory)
|
||||||
end
|
end
|
||||||
|
|
||||||
function EnnemyUtils.dataExists(directory, name)
|
function EnnemyUtils.dataExists(directory, name)
|
||||||
local dir = datasutils.concatFolder(EnnemyUtils.getEnnemyFolder(directory, name, false), "init.lua", false)
|
local dir = utils.datas.concatFolder(EnnemyUtils.getEnnemyFolder(directory, name, false), "init.lua", false)
|
||||||
local fileinfo = love.filesystem.getInfo(dir)
|
local fileinfo = love.filesystem.getInfo(dir)
|
||||||
return (fileinfo ~= nil)
|
return (fileinfo ~= nil)
|
||||||
end
|
end
|
||||||
|
@ -35,9 +33,9 @@ end
|
||||||
function EnnemyUtils.getData(directory, name)
|
function EnnemyUtils.getData(directory, name)
|
||||||
-- 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 folder = EnnemyUtils.getEnnemyFolder(directory, name, true)
|
local folder = EnnemyUtils.getEnnemyFolder(directory, name, true)
|
||||||
local ennemy = datasutils.copy(folder)
|
local ennemy = utils.datas.copy(folder)
|
||||||
ennemy.stats = datasutils.copyDataset(folder, "stats")
|
ennemy.stats = utils.datas.copyDataset(folder, "stats")
|
||||||
ennemy.skills = datasutils.copyDataset(folder, "skills")
|
ennemy.skills = utils.datas.copyDataset(folder, "skills")
|
||||||
|
|
||||||
return ennemy
|
return ennemy
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
local ItemUtils = {}
|
local ItemUtils = {}
|
||||||
|
|
||||||
local datasutils = require "game.utils.datas"
|
|
||||||
|
|
||||||
local DIR = "items"
|
local DIR = "items"
|
||||||
|
|
||||||
function ItemUtils.getBaseDirectory(lua)
|
function ItemUtils.getBaseDirectory(lua)
|
||||||
return datasutils.concatDataFolder(DIR, lua)
|
return utils.datas.concatDataFolder(DIR, lua)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ItemUtils.listCategories()
|
function ItemUtils.listCategories()
|
||||||
|
@ -13,18 +11,18 @@ function ItemUtils.listCategories()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ItemUtils.getCategoryDirectory(directory, lua)
|
function ItemUtils.getCategoryDirectory(directory, lua)
|
||||||
return datasutils.concatFolder(ItemUtils.getBaseDirectory(lua), directory, lua)
|
return utils.datas.concatFolder(ItemUtils.getBaseDirectory(lua), directory, lua)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ItemUtils.getItemsFromCategory(directory)
|
function ItemUtils.getItemsFromCategory(directory)
|
||||||
local folder = ItemUtils.getCategoryDirectory(directory, false)
|
local folder = ItemUtils.getCategoryDirectory(directory, false)
|
||||||
local baseTable = love.filesystem.getDirectoryItems(folder)
|
local baseTable = love.filesystem.getDirectoryItems(folder)
|
||||||
return datasutils.luaFileListToModuleList(baseTable)
|
return utils.datas.luaFileListToModuleList(baseTable)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ItemUtils.getItemFile(category, item, lua)
|
function ItemUtils.getItemFile(category, item, lua)
|
||||||
local dir = ItemUtils.getCategoryDirectory(category, lua)
|
local dir = ItemUtils.getCategoryDirectory(category, lua)
|
||||||
local path = datasutils.concatFolder(dir, item, lua)
|
local path = utils.datas.concatFolder(dir, item, lua)
|
||||||
if (not lua) then
|
if (not lua) then
|
||||||
path = path .. ".lua"
|
path = path .. ".lua"
|
||||||
end
|
end
|
||||||
|
@ -39,7 +37,7 @@ end
|
||||||
|
|
||||||
function ItemUtils.getItemData(category, item)
|
function ItemUtils.getItemData(category, item)
|
||||||
local path = ItemUtils.getItemFile(category, item, true)
|
local path = ItemUtils.getItemFile(category, item, true)
|
||||||
return datasutils.copy(path)
|
return utils.datas.copy(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- VALIDATION FUNCTIONS
|
-- VALIDATION FUNCTIONS
|
||||||
|
|
Loading…
Reference in a new issue