From 28a869a42e407c16a1836285ef70c43dd03a5545 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 7 Aug 2021 11:28:27 +0200 Subject: [PATCH] feat: make that any actor can block choregraphy --- .../scenes/battlesystem/actors/battler.lua | 78 +---------------- .../scenes/battlesystem/actors/parent.lua | 84 ++++++++++++++++++- .../fighters/systems/choregraphy/init.lua | 2 +- 3 files changed, 86 insertions(+), 78 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/battler.lua b/sonic-radiance.love/scenes/battlesystem/actors/battler.lua index f6d570e..29218ac 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/battler.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/battler.lua @@ -25,10 +25,6 @@ function Battler:new(world, x, y, z, owner) self.owner = owner self.isDefending = false - - self.tags = {} - self.choregraphy = nil - self.frameSignals = {} end function Battler:destroy() @@ -84,68 +80,15 @@ function Battler:update(dt) end end -function Battler:purgeFrameSignal() - self.frameSignals = {} -end - -function Battler:receiveFrameSignal(signal) - table.insert(self.frameSignals, signal) -end - -function Battler:haveFrameSignal(signal) - return utils.table.contain(self.frameSignals, signal) -end - -- CHOREGRAPHY FUNCTIONS -- All functions related to the choregraphy system -function Battler:blockChoregraphy(isBlocking, currentlyBlocking, blockedBy) - if (isBlocking) then - self.currentlyBlocking = currentlyBlocking - self.blockedBy = blockedBy - end -end - -function Battler:addTaggedAction(tag, choregraphy, taggedBy) - if (not utils.string.isEmpty(tag)) then - self.tags[tag] = taggedBy - self.choregraphy = choregraphy - end -end - -function Battler:unlockTag(taggedBy) - for tag, actionTag in pairs(self.tags) do - if (self.choregraphy ~= nil) and (actionTag == taggedBy) then - self.choregraphy:finishTagAction(tag) - self.tags[tag] = nil - end - end -end - -function Battler:unblockChoregraphy() - self.currentlyBlocking:finish() - self.currentlyBlocking = nil -end - -function Battler:timerResponse(signal) - self:finishAction(signal) - - if (signal == "removeOutput") then - self.showOutput = false - end -end - -function Battler:finishAction(signal) - if ((self.currentlyBlocking ~= nil) and (signal == self.blockedBy)) then - self:unblockChoregraphy() - end - self:unlockTag(signal) -end - function Battler:choregraphyEnded() self:resetMovement() end +-- DAMAGE FUNCTIONS + function Battler:getHurt() end @@ -183,23 +126,6 @@ function Battler:initSprite() self:changeAnimation("idle") end -function Battler:changeAnimation(animation, restart) - self:purgeFrameSignal() - Battler.super.changeAnimation(self, animation, restart) -end - -function Battler:animationEnded(animation) - if (self.currentlyBlocking ~= nil and self.blockedBy=="animation") then - self:unblockChoregraphy() - end - self:unlockTag("animation") - self:getNewAnimation(animation) -end - -function Battler:getNewAnimation(animation) - -end - function Battler:validateAction() end diff --git a/sonic-radiance.love/scenes/battlesystem/actors/parent.lua b/sonic-radiance.love/scenes/battlesystem/actors/parent.lua index c6256cb..44f997e 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/parent.lua @@ -29,6 +29,8 @@ function Parent:new(world, x, y, z) self.tweens = TweenManager(self) + self:resetTags() + self:setSprite() self:register() end @@ -67,6 +69,8 @@ function Parent:setSprite(spritename, ox, oy, active) self.sprite.exist = (spritename ~= nil) self.sprite.clone = nil self.sprite.active = active or false + + self:resetFrameSignal() end function Parent:cloneSprite() @@ -77,6 +81,7 @@ function Parent:cloneSprite() end function Parent:changeAnimation(animation, restart) + self:resetFrameSignal() if (self.sprite.clone == nil) then self.assets.sprites[self.sprite.name]:changeAnimation(animation, restart) else @@ -93,7 +98,15 @@ function Parent:setAnimSpeed(speed) end function Parent:animationEnded(animation) - -- Empty placeholder function + if (self.currentlyBlocking ~= nil and self.blockedBy=="animation") then + self:unblockChoregraphy() + end + self:unlockTag("animation") + self:getNewAnimation(animation) +end + +function Parent:getNewAnimation(animation) + end function Parent:setCustomSpeed(customSpeed) @@ -184,6 +197,75 @@ function Parent:drawSprite(tx, ty) end end +-- FRAME SIGNAL +-- Get signals from specific frames of the animation + +function Parent:resetFrameSignal() + self.frameSignals = {} +end + +function Parent:receiveFrameSignal(signal) + table.insert(self.frameSignals, signal) +end + +function Parent:haveFrameSignal(signal) + return utils.table.contain(self.frameSignals, signal) +end + +-- TAGS +-- Handle tags + +function Parent:resetTags() + self.tags = {} + self.choregraphy = nil +end + +function Parent:addTaggedAction(tag, choregraphy, taggedBy) + if (not utils.string.isEmpty(tag)) then + self.tags[tag] = taggedBy + self.choregraphy = choregraphy + end +end + +function Parent:unlockTag(taggedBy) + for tag, actionTag in pairs(self.tags) do + if (self.choregraphy ~= nil) and (actionTag == taggedBy) then + self.choregraphy:finishTagAction(tag) + self.tags[tag] = nil + end + end +end + +-- CHOREGRAPHY BLOCKING +-- Handle blocking/unblocking the choregraphy + +function Parent:blockChoregraphy(isBlocking, currentlyBlocking, blockedBy) + if (isBlocking) then + self.currentlyBlocking = currentlyBlocking + self.blockedBy = blockedBy + end +end + +function Parent:unblockChoregraphy() + self.currentlyBlocking:finish() + self.currentlyBlocking = nil +end + +function Parent:timerResponse(signal) + self:finishAction(signal) + + if (signal == "removeOutput") then + self.showOutput = false + end +end + +function Parent:finishAction(signal) + if ((self.currentlyBlocking ~= nil) and (signal == self.blockedBy)) then + self:unblockChoregraphy() + end + self:unlockTag(signal) +end + -- DRAW FUNCTIONS -- Handle draw functions 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 47e0691..f600ec5 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 @@ -13,7 +13,7 @@ function ChoregraphySystem:new(action, choregraphy) self.action = action self.fighter = action.fighter self.actor = self.fighter.actor - self.actor:purgeFrameSignal() + self.actor:resetFrameSignal() self.assets = self.fighter.actor.assets self.world = self.actor.world self.target = action.target