From c10d58e604dc2b370d820e78984502f2874aa9da Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 15 May 2021 22:48:25 +0200 Subject: [PATCH] chore: port to parser system --- .../datas/parsers/choregraphystep.lua | 30 ++++--- .../datas/parsers/ennemytype.lua | 10 ++- .../datas/parsers/eventstep.lua | 26 +++--- .../datas/parsers/itemeffects.lua | 12 ++- .../datas/parsers/qtesteps.lua | 6 +- sonic-radiance.love/game/events/init.lua | 3 +- sonic-radiance.love/game/events/utils.lua | 45 ---------- .../game/loot/effectManager.lua | 3 +- .../game/utils/battle/init.lua | 40 --------- .../game/utils/choregraphy/init.lua | 89 ------------------- sonic-radiance.love/game/utils/items/init.lua | 41 --------- .../battlesystem/controllers/ennemy.lua | 4 +- .../fighters/systems/choregraphy/init.lua | 5 +- 13 files changed, 57 insertions(+), 257 deletions(-) delete mode 100644 sonic-radiance.love/game/events/utils.lua delete mode 100644 sonic-radiance.love/game/utils/choregraphy/init.lua delete mode 100644 sonic-radiance.love/game/utils/items/init.lua diff --git a/sonic-radiance.love/datas/parsers/choregraphystep.lua b/sonic-radiance.love/datas/parsers/choregraphystep.lua index e7355f8..6e230cd 100644 --- a/sonic-radiance.love/datas/parsers/choregraphystep.lua +++ b/sonic-radiance.love/datas/parsers/choregraphystep.lua @@ -1,17 +1,21 @@ return { - ["wait"] = {"duration"}, - ["addGFX"] = {'sprite', "origin", "x", "y", "affectedByDirection", 'blockProcess'}, - ["playSFX"] = {"sfx"}, - ["sendDamage"] = {"power", "type", "element", "isSpecial"}, - ["goTo"] = {"origin", "x", "y", "duration", "blockProcess"}, - ["setAnimation"] = {"animation", "blockProcess"}, - ["jump"] = {"power", "bounceNumber", "blockProcess"}, - ["jumpTo"] = {"origin", "x", "y", "duration", "blockProcess"}, - ["jumpBack"] = {"duration", "blockProcess"}, - ["waitActorFinished"] = {"waitFor"}, - ["addQTE"] = {"qteData", "origin", "blockProcess"}, - ["useItemEffect"] = {}, - --[name] = {args}, + headings = {"name", "condition"}, + argumentLists = { + ["wait"] = {"duration"}, + ["addGFX"] = {'sprite', "origin", "x", "y", "affectedByDirection", 'blockProcess'}, + ["playSFX"] = {"sfx"}, + ["sendDamage"] = {"power", "type", "element", "isSpecial"}, + ["goTo"] = {"origin", "x", "y", "duration", "blockProcess"}, + ["setAnimation"] = {"animation", "blockProcess"}, + ["jump"] = {"power", "bounceNumber", "blockProcess"}, + ["jumpTo"] = {"origin", "x", "y", "duration", "blockProcess"}, + ["jumpBack"] = {"duration", "blockProcess"}, + ["waitActorFinished"] = {"waitFor"}, + ["addQTE"] = {"qteData", "origin", "blockProcess"}, + ["useItemEffect"] = {}, + --[name] = {args}, + }, + argumentWrapper = "arguments", } -- The "origin" argument can have the different values diff --git a/sonic-radiance.love/datas/parsers/ennemytype.lua b/sonic-radiance.love/datas/parsers/ennemytype.lua index a5e6780..de00b9b 100644 --- a/sonic-radiance.love/datas/parsers/ennemytype.lua +++ b/sonic-radiance.love/datas/parsers/ennemytype.lua @@ -1,5 +1,9 @@ return { - ["normal"] = {"category", "name", "number"}, - ["boss"] = {"category", "name", "pvFactor", "statFactor", "cheapEffect"}, - ["rival"] = {"character", "level", "pvFactor"} + headings = {"type"}, + argumentLists = { + ["normal"] = {"category", "name", "number"}, + ["boss"] = {"category", "name", "pvFactor", "statFactor", "cheapEffect"}, + ["rival"] = {"character", "level", "pvFactor"} + }, + argumentWrapper = "", } diff --git a/sonic-radiance.love/datas/parsers/eventstep.lua b/sonic-radiance.love/datas/parsers/eventstep.lua index d1268a2..caa4fc7 100644 --- a/sonic-radiance.love/datas/parsers/eventstep.lua +++ b/sonic-radiance.love/datas/parsers/eventstep.lua @@ -1,14 +1,18 @@ -return { - ["wait"] = {"duration"}, - ["simpleMessage"] = {"message"}, - ["dialogBox"] = {"message", "title", "avatar"}, - ["optionBox"] = {"message", "title", "avatar", "option1", "option2", "option3", "flag"}, - ["playSFX"] = {"sfx"}, - ["getRings"] = {"number"}, - ["getItems"] = {"type", "item", "number"}, - ["teleport"] = {"area", "x", "y", "charDir"}, - ["showGFX"] = {"x", "y", "spritename"} - --[name] = {args...}, +return { + headings = {"name", "condition"}, + argumentLists = { + ["wait"] = {"duration"}, + ["simpleMessage"] = {"message"}, + ["dialogBox"] = {"message", "title", "avatar"}, + ["optionBox"] = {"message", "title", "avatar", "option1", "option2", "option3", "flag"}, + ["playSFX"] = {"sfx"}, + ["getRings"] = {"number"}, + ["getItems"] = {"type", "item", "number"}, + ["teleport"] = {"area", "x", "y", "charDir"}, + ["showGFX"] = {"x", "y", "spritename"} + --[name] = {args...}, + }, + argumentWrapper = "arguments", } -- The "origin" argument can have the different values diff --git a/sonic-radiance.love/datas/parsers/itemeffects.lua b/sonic-radiance.love/datas/parsers/itemeffects.lua index b1683b8..6da4425 100644 --- a/sonic-radiance.love/datas/parsers/itemeffects.lua +++ b/sonic-radiance.love/datas/parsers/itemeffects.lua @@ -1,6 +1,10 @@ return { - ["heal"] = {"healType", "computationMode", "value"}, - ["setStatus"] = {"status", "set"}, - ["protectElement"] = {"element"}, - ["blockStatus"] = {"blockWhat"}, + headings = {"type"}, + argumentLists = { + ["heal"] = {"healType", "computationMode", "value"}, + ["setStatus"] = {"status", "set"}, + ["protectElement"] = {"element"}, + ["blockStatus"] = {"blockWhat"}, + }, + argumentWrapper = "", } diff --git a/sonic-radiance.love/datas/parsers/qtesteps.lua b/sonic-radiance.love/datas/parsers/qtesteps.lua index 4414f08..1586884 100644 --- a/sonic-radiance.love/datas/parsers/qtesteps.lua +++ b/sonic-radiance.love/datas/parsers/qtesteps.lua @@ -1,3 +1,7 @@ return { - ["simplePrompt"] = {"key", "duration"} + headings = {"name"}, + argumentLists = { + ["simplePrompt"] = {"key", "duration"} + }, + argumentWrapper = "arguments", } diff --git a/sonic-radiance.love/game/events/init.lua b/sonic-radiance.love/game/events/init.lua index 670fcfe..72fbb89 100644 --- a/sonic-radiance.love/game/events/init.lua +++ b/sonic-radiance.love/game/events/init.lua @@ -1,7 +1,6 @@ local EventManager = Object:extend() local stepObjectList = require "game.events.event" -local eventUtils = require "game.events.utils" local Conditions = require "game.events.conditions" @@ -73,7 +72,7 @@ end function EventManager:switchStep() if self:haveNextStep() then self.currentStepId = self.currentStepId + 1 - local stepData = eventUtils.getStepDatas(self.stepList[self.currentStepId]) + local stepData = core.datas:parse("eventstep", self.stepList[self.currentStepId]) core.debug:print("event", "Starting step " .. stepData.name) if (not self:testCondition(stepData.condition)) then self:switchStep() diff --git a/sonic-radiance.love/game/events/utils.lua b/sonic-radiance.love/game/events/utils.lua deleted file mode 100644 index f3888ba..0000000 --- a/sonic-radiance.love/game/events/utils.lua +++ /dev/null @@ -1,45 +0,0 @@ -local EventUtils = {} - --- steps utils - -function EventUtils.getStepStructure(stepName) - local stepTypeList = require "datas.parsers.eventstep" - return stepTypeList[stepName] -end - -function EventUtils.stepExists(stepName) - return (EventUtils.getStepStructure(stepName) ~= nil) -end - -function EventUtils.validateStep(stepBaseDatas) - local structure = EventUtils.getStepStructure(stepBaseDatas[1]) - if (structure == nil) then - return false - else - return ((#structure + 2) == #stepBaseDatas) - end -end - -function EventUtils.getStepDatas(stepBaseDatas) - local stepData = {} - stepData.name = stepBaseDatas[1] - - if (EventUtils.validateStep(stepBaseDatas)) then - stepData.condition = stepBaseDatas[2] - - local structure = EventUtils.getStepStructure(stepData.name) - - stepData.arguments = {} - - for i, argumentName in ipairs(structure) do - local argumentContent = stepBaseDatas[i + 2] - stepData.arguments[argumentName] = argumentContent - end - - return stepData - else - error("L'étape " .. stepData.name .. " à un nbr d'argument incorrect") - end -end - -return EventUtils \ No newline at end of file diff --git a/sonic-radiance.love/game/loot/effectManager.lua b/sonic-radiance.love/game/loot/effectManager.lua index e9e5cfa..ca73f56 100644 --- a/sonic-radiance.love/game/loot/effectManager.lua +++ b/sonic-radiance.love/game/loot/effectManager.lua @@ -1,6 +1,5 @@ local EffectManager = Object:extend() -local itemutils = require "game.utils.items" local effectList = require "game.loot.effects" function EffectManager:new() @@ -45,7 +44,7 @@ function EffectManager:getEffectStrings(character) end function EffectManager:getEffectObject(rawEffectData, character, duration) - local effect = itemutils.getItemEffectData(rawEffectData) + local effect = core.datas:parse("itemeffects", rawEffectData) if (effectList[effect.type] ~= nil) then return effectList[effect.type](effect, character, duration) else diff --git a/sonic-radiance.love/game/utils/battle/init.lua b/sonic-radiance.love/game/utils/battle/init.lua index f5c62dc..42bdf43 100644 --- a/sonic-radiance.love/game/utils/battle/init.lua +++ b/sonic-radiance.love/game/utils/battle/init.lua @@ -1,43 +1,3 @@ local BattleUtils = {} --- ENNEMY FUNCTIONS - -function BattleUtils.getEnnemyTypeStructure(type) - local typeList = require "datas.parsers.ennemytype" - 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 diff --git a/sonic-radiance.love/game/utils/choregraphy/init.lua b/sonic-radiance.love/game/utils/choregraphy/init.lua deleted file mode 100644 index 06fa49c..0000000 --- a/sonic-radiance.love/game/utils/choregraphy/init.lua +++ /dev/null @@ -1,89 +0,0 @@ -local ChoregraphyUtils = {} - --- steps utils - -function ChoregraphyUtils.getStepStructure(stepName) - local stepTypeList = require "datas.parsers.choregraphystep" - return stepTypeList[stepName] -end - -function ChoregraphyUtils.stepExists(stepName) - return (ChoregraphyUtils.getStepStructure(stepName) ~= nil) -end - -function ChoregraphyUtils.validateStep(stepBaseDatas) - local structure = ChoregraphyUtils.getStepStructure(stepBaseDatas[1]) - if (structure == nil) then - return false - else - return ((#structure + 2) == #stepBaseDatas) - end -end - -function ChoregraphyUtils.getStepDatas(stepBaseDatas) - - local stepData = {} - stepData.name = stepBaseDatas[1] - - if (ChoregraphyUtils.validateStep(stepBaseDatas)) then - stepData.condition = stepBaseDatas[2] - - local structure = ChoregraphyUtils.getStepStructure(stepData.name) - - stepData.arguments = {} - - for i, argumentName in ipairs(structure) do - local argumentContent = stepBaseDatas[i + 2] - stepData.arguments[argumentName] = argumentContent - end - - return stepData - else - error("L'étape " .. stepData.name .. " à un nbr d'argument incorrect") - end - -end - --- QTE utils - -function ChoregraphyUtils.getQteStructure(qteName) - local stepTypeList = require "datas.parsers.qtesteps" - return stepTypeList[qteName] -end - -function ChoregraphyUtils.qteExists(qteName) - return (ChoregraphyUtils.getQteStructure(qteName) ~= nil) -end - -function ChoregraphyUtils.validateQte(qteBaseDatas) - local structure = ChoregraphyUtils.getQteStructure(qteBaseDatas[1]) - if (structure == nil) then - return false - else - return ((#structure + 1) == #qteBaseDatas) - end -end - -function ChoregraphyUtils.getQteDatas(qteBaseDatas) - - local qteData = {} - qteData.name = qteBaseDatas[1] - - if (ChoregraphyUtils.validateQte(qteBaseDatas)) then - local structure = ChoregraphyUtils.getQteStructure(qteData.name) - - qteData.arguments = {} - - for i, argumentName in ipairs(structure) do - local argumentContent = qteBaseDatas[i + 1] - qteData.arguments[argumentName] = argumentContent - end - - return qteData - else - error("Le QTE " .. qteData.name .. " à un nbr d'argument incorrect") - end - -end - -return ChoregraphyUtils diff --git a/sonic-radiance.love/game/utils/items/init.lua b/sonic-radiance.love/game/utils/items/init.lua deleted file mode 100644 index 39b43a9..0000000 --- a/sonic-radiance.love/game/utils/items/init.lua +++ /dev/null @@ -1,41 +0,0 @@ -local ItemUtils = {} - --- VALIDATION FUNCTIONS - -function ItemUtils.getItemEffectStructure(type) - local typeList = require "datas.parsers.itemeffects" - return typeList[type] -end - -function ItemUtils.itemEffectExists(type) - return (ItemUtils.getItemEffectStructure(type) ~= nil) -end - -function ItemUtils.validateItemEffect(effectBaseData) - local structure = ItemUtils.getItemEffectStructure(effectBaseData[1]) - if (structure == nil) then - return false - else - return ((#structure + 1) == #effectBaseData) - end -end - -function ItemUtils.getItemEffectData(effectBaseData) - local effectData = {} - effectData.type = effectBaseData[1] - - if (ItemUtils.validateItemEffect(effectBaseData)) then - local structure = ItemUtils.getItemEffectStructure(effectData.type) - - for i, argumentName in ipairs(structure) do - local argumentContent = effectBaseData[i + 1] - effectData[argumentName] = argumentContent - end - - return effectData - else - error("Le type d'effet d'objet " .. effectData.type .. " à un nbr d'argument incorrect") - end -end - -return ItemUtils diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua b/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua index ac70bc9..c5f89ae 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua @@ -3,8 +3,6 @@ local EnnemyController = FighterControllerParent:extend() local Villain = require "scenes.battlesystem.controllers.fighters.villain" -local battleutils = require "game.utils.battle" - function EnnemyController:new(owner, battleData) self.super.new(self, owner) self:initVillains(battleData) @@ -12,7 +10,7 @@ end function EnnemyController:initVillains(battleData) for i,ennemyBaseData in ipairs(battleData.ennemies) do - local ennData = battleutils.getEnnemyData(ennemyBaseData) + local ennData = core.datas:parse("ennemytype", ennemyBaseData) if (ennData.type == "normal") then self:addVillain(ennData) elseif (ennData.type == "boss") then diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/init.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/init.lua index 51bb7fd..ce7be2d 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/init.lua @@ -1,6 +1,5 @@ local ChoregraphySystem = Object:extend() -local choregraphyUtils = require "game.utils.choregraphy" local stepObjectList = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.step" local qteObjectList = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.qte" @@ -38,7 +37,7 @@ end function ChoregraphySystem:switchStep() if self:haveNextStep() then self.currentStepId = self.currentStepId + 1 - local stepData = choregraphyUtils.getStepDatas(self.stepList[self.currentStepId]) + local stepData = core.datas:parse("choregraphystep", self.stepList[self.currentStepId]) core.debug:print("cbs/choregraphy", "Starting step " .. stepData.name) if (stepObjectList[stepData.name] ~= nil and self:checkCondition(stepData.condition)) then self.currentStep = stepObjectList[stepData.name](self, stepData.arguments) @@ -58,7 +57,7 @@ function ChoregraphySystem:checkCondition(condition) end function ChoregraphySystem:addQTE(action, origin, qteBaseData, blockProcess) - local qteData = choregraphyUtils.getQteDatas(qteBaseData) + local qteData = core.datas:parse("qtesteps", qteBaseData) if (qteObjectList[qteData.name] ~= nil) then core.debug:print("cbs/choregraphy", "Starting qte " .. qteData.name) self.qte.current = qteObjectList[qteData.name](self, qteData.arguments, 0, 0)