From 39507951b80fc71fc9dbde81f34a06af3866253f Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 15 Aug 2021 15:25:44 +0200 Subject: [PATCH] feat: add a way to override GFX by character --- .../scenes/battlesystem/actors/gfx.lua | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/gfx.lua b/sonic-radiance.love/scenes/battlesystem/actors/gfx.lua index 398e70e..5a0c463 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/gfx.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/gfx.lua @@ -4,7 +4,9 @@ local GFX_DIRECTORY = "assets/sprites/gfx/" function GFX:new(world, x, y, z, spritename, creator, blockProcess, tag) GFX.super.new(self, world, x, y, z) - self:loadAnimation(spritename) + + self.char = self:getCharacter(creator.choregraphy.fighter) + self:setAnimation(spritename) self.creator = creator self.blockProcess = blockProcess or false @@ -17,9 +19,30 @@ function GFX:new(world, x, y, z, spritename, creator, blockProcess, tag) self.direction = 1 end -function GFX:loadAnimation(spritename) +function GFX:getCharacter(fighter) + if (fighter.isHero) then + return fighter.abstract.simplename + end + return nil +end + +function GFX:setAnimation(spritename) + local defaultPath = GFX_DIRECTORY .. spritename + if (utils.string.isEmpty(self.char)) then + self:loadAnimation(spritename, defaultPath) + else + local charGFXPath = "datas/gamedata/characters/" .. self.char .. "/gfx/" .. spritename + if (utils.filesystem.exists(charGFXPath .. ".lua")) then + self:loadAnimation(self.char .. spritename, charGFXPath) + else + self:loadAnimation(spritename, defaultPath) + end + end +end + +function GFX:loadAnimation(spritename, path) if self.world.assets.sprites[spritename] == nil then - self.world.assets:addSprite(spritename, GFX_DIRECTORY .. spritename) + self.world.assets:addSprite(spritename, path) end local width, height = self.world.assets.sprites[spritename]:getDimensions() self:setSprite(spritename, width/2, height, true)