chore: more code extraction

This commit is contained in:
Kazhnuz 2020-07-18 09:51:02 +02:00
parent b413946368
commit fa6e6c2bc4
6 changed files with 106 additions and 4 deletions

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -0,0 +1 @@
self.scene.menu:set( self )

View file

@ -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