From 92cbda69a187de4e530910ccce11ab4b7f0f517e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 10 May 2020 11:38:50 +0200 Subject: [PATCH] fix(actors): replace deprecated functions after the sprite transition --- birb/modules/world/actors/actor2D.lua | 2 +- birb/modules/world/actors/actor3D.lua | 2 +- birb/modules/world/actors/baseactor.lua | 27 ++++++------------- birb/modules/world/actors/gfx2D.lua | 3 +-- birb/modules/world/actors/gfx3D.lua | 3 +-- birb/modules/world/actors/utils/sprites.lua | 16 +++++------ .../gameplay/action3D/actors/player.lua | 15 +++++------ .../gameplay/moveplayer3D/actors/player.lua | 15 +++++------ .../gameplay/plateform/actors/player.lua | 15 +++++------ 9 files changed, 40 insertions(+), 58 deletions(-) diff --git a/birb/modules/world/actors/actor2D.lua b/birb/modules/world/actors/actor2D.lua index 1b8c794..5038eb7 100644 --- a/birb/modules/world/actors/actor2D.lua +++ b/birb/modules/world/actors/actor2D.lua @@ -130,7 +130,7 @@ end -- Functions related to actor hitboxes function Actor2D:addHitboxFromFrameData(framedata, animationID, frameID, hitboxID) - local sx, sy = self:getSpriteScalling() + local sx, sy = self.sprite:getScalling() local type = framedata[1] local ox = framedata[2] local oy = framedata[3] diff --git a/birb/modules/world/actors/actor3D.lua b/birb/modules/world/actors/actor3D.lua index c5f4208..e00786e 100644 --- a/birb/modules/world/actors/actor3D.lua +++ b/birb/modules/world/actors/actor3D.lua @@ -152,7 +152,7 @@ end -- Functions related to actor hitboxes function Actor3D:addHitboxFromFrameData(framedata, animationID, frameID, hitboxID) - local sx, sy = self:getSpriteScalling() + local sx, sy = self.sprite:getScalling() local type = framedata[1] local ox = framedata[2] local oy = framedata[3] diff --git a/birb/modules/world/actors/baseactor.lua b/birb/modules/world/actors/baseactor.lua index bfcfde9..a639b40 100644 --- a/birb/modules/world/actors/baseactor.lua +++ b/birb/modules/world/actors/baseactor.lua @@ -292,8 +292,8 @@ function BaseActor:updateHitboxes() if (self.hitboxList ~= nil) then self:purgeHitbox() local animation, frame - animation = self:getCurrentAnimation() - frame = self:getRelativeFrame() + animation = self.sprite:getCurrentAnimation() + frame = self.sprite:getRelativeFrame() local hitboxList = self:getHitboxList(animation, frame) if (hitboxList ~= nil) then @@ -364,13 +364,9 @@ end -- SPRITES FUNCTIONS -- Handle the sprite of the actor -function BaseActor:setSprite(spritename, ox, oy) +function BaseActor:setSprite(spritename, isClone, ox, oy) self.sprite = Sprite(self, spritename, ox, oy) -end - -function BaseActor:cloneSprite() - if self.sprite ~= nil then - core.debug:warning("actor", "the function BaseActor:cloneSprite is deprecated, prefer BaseActor.sprite:clone()") + if (isClone) then self.sprite:clone() end end @@ -399,16 +395,6 @@ function BaseActor:updateSprite(dt) end end -function BaseActor:setSpriteScallingX(sx) - core.debug:warning("actor", "the function BaseActor:setSpriteScallingX is deprecated, prefer BaseActor.sprite:setSpriteScallingX()") - self.sprite:setScallingX(sx) -end - -function BaseActor:setSpriteScallingY(sy) - core.debug:warning("actor", "the function BaseActor:setSpriteScallingY is deprecated, prefer BaseActor.sprite:setSpriteScallingY()") - self.sprite:setScallingY(sY) -end - function BaseActor:getCurrentAnimation() if (self.sprite ~= nil) then core.debug:warning("actor", "the function BaseActor:getCurrentAnimation is deprecated, prefer BaseActor.sprite:getCurrentAnimation()") @@ -416,25 +402,28 @@ function BaseActor:getCurrentAnimation() end end - function BaseActor:getSpriteScalling() + core.debug:warning("actor", "the function BaseActor:getSpriteScalling is deprecated, prefer BaseActor.sprite:getScalling()") return self.sprite:getScalling() end function BaseActor:getFrame() if (self.sprite ~= nil) then + core.debug:warning("actor", "the function BaseActor:getFrame is deprecated, prefer BaseActor.sprite:getFrame()") return self.sprite:getFrame() end end function BaseActor:getRelativeFrame() if (self.sprite ~= nil) then + core.debug:warning("actor", "the function BaseActor:getRelativeFrame is deprecated, prefer BaseActor.sprite:getRelativeFrame()") return self.sprite:getRelativeFrame() end end function BaseActor:getAnimationDuration() if (self.sprite ~= nil) then + core.debug:warning("actor", "the function BaseActor:getAnimationDuration is deprecated, prefer BaseActor.sprite:getAnimationDuration()") return self.sprite:getAnimationDuration() end end diff --git a/birb/modules/world/actors/gfx2D.lua b/birb/modules/world/actors/gfx2D.lua index 900654c..955170a 100644 --- a/birb/modules/world/actors/gfx2D.lua +++ b/birb/modules/world/actors/gfx2D.lua @@ -29,8 +29,7 @@ function GFX:new(world, x, y, spritename) local width, height = world.scene.assets.sprites[spritename]:getDimensions() GFX.super.new(self, world, "gfx", x - (width/2), y - (height/2), width, height) - self:setSprite(spritename) - self:cloneSprite() + self:setSprite(spritename, true) end function GFX:animationEnded(animation) diff --git a/birb/modules/world/actors/gfx3D.lua b/birb/modules/world/actors/gfx3D.lua index fa40c05..5bc465b 100644 --- a/birb/modules/world/actors/gfx3D.lua +++ b/birb/modules/world/actors/gfx3D.lua @@ -29,8 +29,7 @@ function GFX:new(world, x, y, z, spritename) local width, height = world.scene.assets.sprites[spritename]:getDimensions() GFX.super.new(self, world, "gfx", x - (width/2), y - (width/2), z - (height/2), width, width, height) - self:setSprite(spritename) - self:cloneSprite() + self:setSprite(spritename, true) end function GFX:animationEnded(animation) diff --git a/birb/modules/world/actors/utils/sprites.lua b/birb/modules/world/actors/utils/sprites.lua index 564e499..d56db7f 100644 --- a/birb/modules/world/actors/utils/sprites.lua +++ b/birb/modules/world/actors/utils/sprites.lua @@ -48,16 +48,14 @@ function Sprite:update(dt) end end -function Sprite:setScallingX(sx) - local sx = sx or 1 +function Sprite:setScalling(sx, sy) + if (sx ~= nil) then + self.sx = sx + end - self.sx = sx -end - -function Sprite:setScallingY(sy) - local sy = sy or 1 - - self.sy = sy + if (sy ~= nil) then + self.sy = sy + end end function Sprite:getCurrentAnimation() diff --git a/examples/scenes/gameplay/action3D/actors/player.lua b/examples/scenes/gameplay/action3D/actors/player.lua index 02494d1..c0bfe74 100644 --- a/examples/scenes/gameplay/action3D/actors/player.lua +++ b/examples/scenes/gameplay/action3D/actors/player.lua @@ -6,8 +6,7 @@ function Player:new(world, x, y, z, id) Player.super.new(self, world, "player", x, y, 0, 16, 16, 24, true) self:setGravity(480) - self:setSprite("player", 8, 12) - self:cloneSprite() + self:setSprite("player", true, 8, 12) self:setHitboxFile("scenes.gameplay.action3D.actors.hitboxes.player") end @@ -49,19 +48,19 @@ end function Player:setAnimation() local gsp = utils.math.pointDistance(0, 0, self.xsp, self.ysp) - self:setCustomSpeed(math.abs(gsp) / 12) + self.sprite:setCustomSpeed(math.abs(gsp) / 12) self:setDirection(self.xsp) if (self.isPunching) then - self:changeAnimation("punch", false) + self.sprite:changeAnimation("punch", false) else if (self.onGround) then if (math.abs(self.xsp) > 0) or (math.abs(self.ysp) > 0) then - self:changeAnimation("walk", false) + self.sprite:changeAnimation("walk", false) else - self:changeAnimation("idle", true) + self.sprite:changeAnimation("idle", true) end else - self:changeAnimation("jump", true) + self.sprite:changeAnimation("jump", true) end end end @@ -71,7 +70,7 @@ function Player:setDirection(direction) if direction ~= 0 then direction = utils.math.sign(direction) self.direction = direction - self:setSpriteScallingX(direction) + self.sprite:setScalling(direction, nil) end end diff --git a/examples/scenes/gameplay/moveplayer3D/actors/player.lua b/examples/scenes/gameplay/moveplayer3D/actors/player.lua index 85327b8..cd021ce 100644 --- a/examples/scenes/gameplay/moveplayer3D/actors/player.lua +++ b/examples/scenes/gameplay/moveplayer3D/actors/player.lua @@ -6,8 +6,7 @@ function Player:new(world, x, y, z, id) Player.super.new(self, world, "player", x, y, 0, 16, 16, 24, true) self:setGravity(480) - self:setSprite("player", 8, 12) - self:cloneSprite() + self:setSprite("player", true, 8, 12) end function Player:updateStart(dt) @@ -37,19 +36,19 @@ end function Player:setAnimation() local gsp = utils.math.pointDistance(0, 0, self.xsp, self.ysp) - self:setCustomSpeed(math.abs(gsp) / 12) + self.sprite:setCustomSpeed(math.abs(gsp) / 12) self:setDirection(self.xsp) if (self.isPunching) then - self:changeAnimation("punch", false) + self.sprite:changeAnimation("punch", false) else if (self.onGround) then if (math.abs(self.xsp) > 0) or (math.abs(self.ysp) > 0) then - self:changeAnimation("walk", false) + self.sprite:changeAnimation("walk", false) else - self:changeAnimation("idle", true) + self.sprite:changeAnimation("idle", true) end else - self:changeAnimation("jump", true) + self.sprite:changeAnimation("jump", true) end end end @@ -59,7 +58,7 @@ function Player:setDirection(direction) if direction ~= 0 then direction = utils.math.sign(direction) self.direction = direction - self:setSpriteScallingX(direction) + self.sprite:setScalling(direction, nil) end end diff --git a/examples/scenes/gameplay/plateform/actors/player.lua b/examples/scenes/gameplay/plateform/actors/player.lua index 892fef3..09ad23f 100644 --- a/examples/scenes/gameplay/plateform/actors/player.lua +++ b/examples/scenes/gameplay/plateform/actors/player.lua @@ -3,8 +3,7 @@ local Player = Base:extend() function Player:new(world, x, y, id) Player.super.new(self, world, "player", x, y, 16, 24, true) - self:setSprite("player", 8, 12) - self:cloneSprite() + self:setSprite("player", true, 8, 12) self:setGravity(480) self.isPunching = false @@ -67,18 +66,18 @@ function Player:updateEnd(dt) end function Player:setAnimation() - self:setCustomSpeed(math.abs(self.xsp) / 12) + self.sprite:setCustomSpeed(math.abs(self.xsp) / 12) if (self.isPunching) then - self:changeAnimation("punch", false) + self.sprite:changeAnimation("punch", false) else if (self.onGround) then if math.abs(self.xsp) > 0 then - self:changeAnimation("walk", false) + self.sprite:changeAnimation("walk", false) else - self:changeAnimation("idle", true) + self.sprite:changeAnimation("idle", true) end else - self:changeAnimation("jump", true) + self.sprite:changeAnimation("jump", true) end end end @@ -88,7 +87,7 @@ function Player:setDirection(direction) if direction ~= 0 then direction = utils.math.sign(direction) self.direction = direction - self:setSpriteScallingX(direction) + self.sprite:setScalling(direction, nil) end end