From fa6e6c2bc4af3586684cef952520c778d8e12c38 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 18 Jul 2020 09:51:02 +0200 Subject: [PATCH] chore: more code extraction --- .../scenes/battlesystem/actors/hero.lua | 13 +++++++ .../scenes/battlesystem/controllers/init.lua | 7 ++-- .../battlesystem/controllers/parent.lua | 22 +++++++++++ .../battlesystem/controllers/player.lua | 28 +++++++++++++ .../battlesystem/controllers/view/menu.lua | 1 + .../battlesystem/controllers/view/moving.lua | 39 +++++++++++++++++++ 6 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/parent.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/player.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/view/menu.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/view/moving.lua diff --git a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua index 7c71e50..db3d113 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua @@ -273,6 +273,12 @@ function Hero:receiveSignal(action_type, id) end end +function Hero:positionSelected(x, y) + self:changeAnimation("walk", true) + self:goTo(self.world.cursor.x, self.world.cursor.y, 'cursorMove', 1) + self.assets.sfx["woosh"]:play() +end + function Hero:receiveBackSignal() self.world.cursor:set(self.x, self.y, "cursorMove") if (self.x ~= self.startx) or (self.y ~= self.starty) then @@ -344,6 +350,13 @@ function Hero:unblockChoregraphy() self.blockingChoregraphy = "" end +-- INFO FUNCTIONS +-- Getting info about the actor + +function Hero:getCharacterData() + return game.characters.list[self.charid] +end + -- ASSETS FUNCTIONS -- Load and play assets needed by the character diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/init.lua b/sonic-radiance.love/scenes/battlesystem/controllers/init.lua index 78f8a92..9c34d96 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/init.lua @@ -9,7 +9,7 @@ function TurnController:new(scene) self.scene = scene self.world = scene.world - --self.player = Player(self) + self.player = Player(self) --self.ennemies = Ennemy(self) self.isActive = false @@ -31,7 +31,7 @@ end function TurnController:update(dt) if (self.isActive) then if (self.currentlyPlaying == "heroes") then - --self.player:update(dt) + self.player:update(dt) elseif (self.currentlyPlaying == "ennemies") then --self.ennemies:update(dt) else @@ -75,9 +75,8 @@ core.debug:print("cbs/world", "Starting action " .. self.turns.current) self:nextAction() else if (nextActor.side == "heroes") then - --self.player:setActive(nextActor) + self.player:setActive(nextActor) self.currentlyPlaying = "heroes" - self.actionList[self.turns.current].actor:setActive() elseif (nextActor.side == "ennemies") then --self.ennemies:setActive(nextActor) self.currentlyPlaying = "ennemies" diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua new file mode 100644 index 0000000..01775eb --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua @@ -0,0 +1,22 @@ +local ControllerParent = Object:extend() + +function ControllerParent:new(owner) + self.owner = owner + self.activeActor = nil; + self.startData = {} +end + +function ControllerParent:setActive(activeActor) + self.activeActor = activeActor + activeActor:setActive() +end + +function ControllerParent:update(dt) + +end + +function ControllerParent:endAction() + self.owner:nextAction() +end + +return PlayerController diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/player.lua b/sonic-radiance.love/scenes/battlesystem/controllers/player.lua new file mode 100644 index 0000000..8ec0a5b --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/player.lua @@ -0,0 +1,28 @@ +local PlayerController = Object:extend() + +function PlayerController:new(owner) + self.owner = owner + self.activeActor = nil; + self.startData = {} +end + +function PlayerController:setActive(activeActor) + self.activeActor = activeActor + activeActor:setActive() +end + +function PlayerController:update(dt) + +end + +function PlayerController:setStartData(x, y, direction) + self.startData.x = x + self.startData.y = y + self.startData.direction = direction +end + +function PlayerController:getStartData() + return self.startData.x, self.startData.y, self.startData.direction +end + +return PlayerController diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/view/menu.lua b/sonic-radiance.love/scenes/battlesystem/controllers/view/menu.lua new file mode 100644 index 0000000..186b759 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/view/menu.lua @@ -0,0 +1 @@ +self.scene.menu:set( self ) diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/view/moving.lua b/sonic-radiance.love/scenes/battlesystem/controllers/view/moving.lua new file mode 100644 index 0000000..2a27569 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/view/moving.lua @@ -0,0 +1,39 @@ +local MovingView = Object:extend() + +local DEFAULT_GRIDSIZE = 2 + +function MovingView:new(owner, actor) + self.owner = owner + self.actor = actor + self.world = actor.world +end + +function MovingView:update(dt) + +end + +function MovingVew:start() + local character = self.actor:getCharacterData(); + local gridsize = character.move + if (gridsize == nil) then + gridsize = DEFAULT_GRIDSIZE + core.debug:warning("cbs/character", "move value is nil") + end + local x, y = utils.math.round(self.actor.x), utils.math.round(self.actor.y) + self.world.cursor:setGrid(x, y, "circle", gridsize, 1, self.owner) + self.actor.x, self.actor.y = x, y + self.owner:setStartData(x, y, self.actor.direction) + + self.world.cursor:set(x, y, "cursorMove") +end + +function MovingView:receiveSignal(signal, id) + if (signal == "positionSelected") then + self.actor:set + elseif (signal == "characterMoved") then + self.world:resetActiveGrid() + self:endView() + end +end + +return MovingView