From 3e2eafb63db3709e598302747516994a236298d8 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 8 Aug 2021 13:11:36 +0200 Subject: [PATCH] feat: add subchoregraphies --- .../datas/parsers/choregraphystep.lua | 1 + .../fighters/systems/actions/parent.lua | 4 +- .../systems/choregraphy/conditions.lua | 8 ++ .../fighters/systems/choregraphy/init.lua | 18 ++++- .../choregraphy/mixins/subchoregraphies.lua | 73 +++++++++++++++++++ .../systems/choregraphy/mixins/wrappers.lua | 4 +- .../systems/choregraphy/step/init.lua | 1 + .../step/startSubChoregraphies.lua | 21 ++++++ .../systems/choregraphy/subchoregraphy.lua | 44 +++++++++++ 9 files changed, 169 insertions(+), 5 deletions(-) create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/subchoregraphies.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/startSubChoregraphies.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/subchoregraphy.lua diff --git a/sonic-radiance.love/datas/parsers/choregraphystep.lua b/sonic-radiance.love/datas/parsers/choregraphystep.lua index 57a6755..05860c1 100644 --- a/sonic-radiance.love/datas/parsers/choregraphystep.lua +++ b/sonic-radiance.love/datas/parsers/choregraphystep.lua @@ -19,6 +19,7 @@ return { ["setCounter"] = {"counterName", "number", "relative"}, ["useItemEffect"] = {}, ["stopMov"] = {"who"}, + ["startSubChoregraphies"] = {"waitTime", "blockProcess"}, --[name] = {args}, }, argumentWrapper = "arguments", diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua index 3371346..ce0378d 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua @@ -18,11 +18,11 @@ end function ActionParent:loadChoregraphy(skillname) local skill = core.datas:get("skills", skillname) - self.choregraphy = ChoregraphySystem(self, skill.choregraphy) + self:loadChoregraphy(self, skill) end function ActionParent:loadChoregraphyFromSkill(skill) - self.choregraphy = ChoregraphySystem(self, skill.choregraphy) + self.choregraphy = ChoregraphySystem(self, skill.choregraphy, skill.subChoregraphy) end function ActionParent:needTarget() diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/conditions.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/conditions.lua index db6ca4b..b62c1cd 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/conditions.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/conditions.lua @@ -32,4 +32,12 @@ function Conditions.haveFrameSignal(cond, predicate, asker) return asker:haveFrameSignal(cond[2]) end +function Conditions.hasNextTarget(cond, predicate, asker) + return asker:hasNextTarget() +end + +function Conditions.hasSubChoregraphiesActive(cond, predicate, asker) + return asker:hasSubChoregraphiesActive() +end + return Conditions \ No newline at end of file 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 1ce2d0c..82d7b1f 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 @@ -5,20 +5,27 @@ local StepsMixin = require "scenes.battlesystem.controllers.fighters.systems.cho local TagsMixin = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.mixins.tags" local CountersMixin = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.mixins.counters" local WrappersMixin = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.mixins.wrappers" +local SubChoregraphiesMixin = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.mixins.subchoregraphies" + +local TweenManager = require "birb.classes.time" ChoregraphySystem:implement(QteMixin) ChoregraphySystem:implement(StepsMixin) ChoregraphySystem:implement(TagsMixin) ChoregraphySystem:implement(CountersMixin) ChoregraphySystem:implement(WrappersMixin) +ChoregraphySystem:implement(SubChoregraphiesMixin) -function ChoregraphySystem:new(action, choregraphy) +function ChoregraphySystem:new(action, choregraphy, subChoregraphy) self:initWrappers(action) self:initSteps(choregraphy) self:initQte() self:initTagActions() self:initCounters() + self:initSubchoregraphies(subChoregraphy) + + self.tweens = TweenManager(self) self.actor:resetFrameSignal() end @@ -26,6 +33,14 @@ end function ChoregraphySystem:update(dt) self:updateQte(dt) self:updateSteps(dt) + self.tweens:update(dt) + self:updateSubChoregraphies(dt) +end + +function ChoregraphySystem:timerResponse(signal) + if (signal == "startNextTarget") then + self:startNextTarget() + end end function ChoregraphySystem:endChoregraphy() @@ -36,6 +51,7 @@ end function ChoregraphySystem:draw() self:drawQte() + self:drawSubChoregraphies() end return ChoregraphySystem diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/subchoregraphies.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/subchoregraphies.lua new file mode 100644 index 0000000..b1a1e44 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/subchoregraphies.lua @@ -0,0 +1,73 @@ +local SubChoregraphiesMixin = Object:extend() + +local SubChoregraphy = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.subchoregraphy" + +function SubChoregraphiesMixin:initSubchoregraphies(subChoregraphy) + self.subChoregraphies = {} + self.subChoregraphies.isActive = (self.target == nil) + self.subChoregraphies.steps = subChoregraphy + self.subChoregraphies.currentTarget = 0 + self.subChoregraphies.waitTime = 0 + self.subChoregraphies.list = {} +end + +function SubChoregraphiesMixin:startSubChoregraphies(waitTime) + self.subChoregraphies.currentTarget = 0 + self.subChoregraphies.waitTime = waitTime + self:startNextTarget() +end + +function SubChoregraphiesMixin:updateSubChoregraphies(dt) + for _, subchoregraphy in ipairs(self.subChoregraphies.list) do + subchoregraphy:update(dt) + end +end + +function SubChoregraphiesMixin:startNextTarget() + local target = self:getNextTarget() + if (target ~= nil) then + SubChoregraphy(self, target, self.subChoregraphies.steps) + self.tweens:newTimer(self.subChoregraphies.waitTime, "startNextTarget") + end +end + +function SubChoregraphiesMixin:registerSubChoregraphy(subChoregraphy) + table.insert(self.subChoregraphies.list, subChoregraphy) + self:updateSubChoregraphyIds() +end + +function SubChoregraphiesMixin:removeSubChoregraphy(subChoregraphy) + self:updateSubChoregraphyIds() + table.remove(self.subChoregraphies.list, subChoregraphy.id) + self:updateSubChoregraphyIds() +end + +function SubChoregraphiesMixin:updateSubChoregraphyIds() + for id, subchoregraphy in ipairs(self.subChoregraphies.list) do + subchoregraphy.id = id + end +end + +function SubChoregraphiesMixin:getNextTarget() + if (self:hasNextTarget()) then + self.subChoregraphies.currentTarget = self.subChoregraphies.currentTarget + 1 + return self.targetList[self.subChoregraphies.currentTarget] + end +end + +function SubChoregraphiesMixin:hasNextTarget() + return (self.targetList[self.subChoregraphies.currentTarget + 1] ~= nil) +end + +function SubChoregraphiesMixin:hasSubChoregraphiesActive() + return (#self.subChoregraphies.list > 0) +end + +function SubChoregraphiesMixin:drawSubChoregraphies() + for _, subchoregraphy in ipairs(self.subChoregraphies.list) do + subchoregraphy:draw() + end +end + + +return SubChoregraphiesMixin \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/wrappers.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/wrappers.lua index 6aefe54..a6fd761 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/wrappers.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/wrappers.lua @@ -1,13 +1,13 @@ local InfosMixin = Object:extend() -function InfosMixin:initWrappers(action) +function InfosMixin:initWrappers(action, target) self.action = action self.fighter = action.fighter self.actor = self.fighter.actor self.assets = self.fighter.actor.assets self.world = self.actor.world - self:initTargets(action.target) + self:initTargets(target or action.target) end function InfosMixin:initTargets(target) diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua index ddbcabd..b2c2525 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua @@ -19,5 +19,6 @@ actions["skipTo"] = require(baseURI .. "skipTo") actions["waitActorFinished"] = require(baseURI .. "waitActorFinished") actions["useItemEffect"] = require(baseURI .. "useItemEffect") actions["setCounter"] = require(baseURI .. "setCounter") +actions["startSubChoregraphies"] = require(baseURI .. "startSubChoregraphies") return actions diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/startSubChoregraphies.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/startSubChoregraphies.lua new file mode 100644 index 0000000..474d54b --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/startSubChoregraphies.lua @@ -0,0 +1,21 @@ +local StepParent = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.step.parent" +local StartSubchoregraphiesStep = StepParent:extend() + +function StartSubchoregraphiesStep:new(controller, args) + StartSubchoregraphiesStep.super.new(self, controller, args) +end + +function StartSubchoregraphiesStep:start() + self.choregraphy:startSubChoregraphies(self.arguments.waitTime) + if (not self.arguments.blockProcess) then + self:finish() + end +end + +function StartSubchoregraphiesStep:update(dt) + if (not self.choregraphy:hasNextTarget()) then + self:finish() + end +end + +return StartSubchoregraphiesStep; diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/subchoregraphy.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/subchoregraphy.lua new file mode 100644 index 0000000..cb76444 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/subchoregraphy.lua @@ -0,0 +1,44 @@ +local SubChoregraphy = Object:extend() + +local QteMixin = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.mixins.qtes" +local StepsMixin = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.mixins.steps" +local TagsMixin = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.mixins.tags" +local CountersMixin = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.mixins.counters" +local WrappersMixin = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.mixins.wrappers" + +SubChoregraphy:implement(QteMixin) +SubChoregraphy:implement(StepsMixin) +SubChoregraphy:implement(TagsMixin) +SubChoregraphy:implement(CountersMixin) +SubChoregraphy:implement(WrappersMixin) + +function SubChoregraphy:new(parent, target, choregraphy) + self.parent = parent + self:initWrappers(parent.action, target) + + self:initSteps(choregraphy) + self:initQte() + self:initTagActions() + self:initCounters() + + self:register() +end + +function SubChoregraphy:register() + self.parent:registerSubChoregraphy(self) +end + +function SubChoregraphy:update(dt) + self:updateQte(dt) + self:updateSteps(dt) +end + +function SubChoregraphy:endChoregraphy() + self.parent:removeSubChoregraphy(self) +end + +function SubChoregraphy:draw() + self:drawQte() +end + +return SubChoregraphy