2021-04-03 10:39:34 +02:00
|
|
|
local BattleUtils = {}
|
2020-08-04 17:50:03 +02:00
|
|
|
|
|
|
|
local DIR = "battles"
|
|
|
|
|
|
|
|
function BattleUtils.getBaseDirectory(lua)
|
2021-05-15 15:09:02 +02:00
|
|
|
return utils.datas.concatDataFolder(DIR, lua)
|
2020-08-04 17:50:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function BattleUtils.listCategories()
|
|
|
|
return love.filesystem.getDirectoryItems(BattleUtils.getBaseDirectory(false))
|
|
|
|
end
|
|
|
|
|
|
|
|
function BattleUtils.getCategoryDirectory(directory, lua)
|
|
|
|
local baseDir = BattleUtils.getBaseDirectory(lua)
|
2021-05-15 15:09:02 +02:00
|
|
|
return utils.datas.concatFolder(baseDir, directory, lua)
|
2020-08-04 17:50:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function BattleUtils.getDirectoryLuaStyle(directory)
|
2020-09-13 16:49:50 +02:00
|
|
|
return DIR .. "." .. directory
|
2020-08-04 17:50:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function BattleUtils.getBattleFromCategory(directory)
|
|
|
|
local folder = BattleUtils.getCategoryDirectory(directory, false)
|
2021-05-15 15:09:02 +02:00
|
|
|
return utils.datas.luaFileListToModuleList(love.filesystem.getDirectoryItems(folder))
|
2020-08-04 17:50:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function BattleUtils.getBattleData(directory, battlename)
|
|
|
|
local categoryDir = BattleUtils.getCategoryDirectory(directory, true)
|
2021-05-15 15:09:02 +02:00
|
|
|
return utils.datas.require(categoryDir, battlename)
|
2020-08-04 17:50:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- ENNEMY FUNCTIONS
|
|
|
|
|
|
|
|
function BattleUtils.getEnnemyTypeStructure(type)
|
|
|
|
local typeList = require "game.utils.battle.arguments"
|
|
|
|
return typeList[type]
|
|
|
|
end
|
|
|
|
|
|
|
|
function BattleUtils.ennemyTypeExists(type)
|
|
|
|
return (BattleUtils.getEnnemyTypeStructure(type) ~= nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
function BattleUtils.validateEnnemyType(ennemyBaseData)
|
|
|
|
local structure = BattleUtils.getEnnemyTypeStructure(ennemyBaseData[1])
|
|
|
|
if (structure == nil) then
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
return ((#structure + 1) == #ennemyBaseData)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function BattleUtils.getEnnemyData(ennemyBaseData)
|
|
|
|
local ennemyData = {}
|
|
|
|
ennemyData.type = ennemyBaseData[1]
|
|
|
|
|
|
|
|
if (BattleUtils.validateEnnemyType(ennemyBaseData)) then
|
|
|
|
local structure = BattleUtils.getEnnemyTypeStructure(ennemyData.type)
|
|
|
|
|
|
|
|
for i, argumentName in ipairs(structure) do
|
|
|
|
local argumentContent = ennemyBaseData[i + 1]
|
|
|
|
ennemyData[argumentName] = argumentContent
|
|
|
|
end
|
|
|
|
|
|
|
|
return ennemyData
|
|
|
|
else
|
|
|
|
error("Le type d'ennemy " .. ennemyData.type .. " à un nbr d'argument incorrect")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return BattleUtils
|