feat: add a way to override GFX by character

This commit is contained in:
Kazhnuz 2021-08-15 15:25:44 +02:00
parent 603d61a1fc
commit 39507951b8

View file

@ -4,7 +4,9 @@ local GFX_DIRECTORY = "assets/sprites/gfx/"
function GFX:new(world, x, y, z, spritename, creator, blockProcess, tag) function GFX:new(world, x, y, z, spritename, creator, blockProcess, tag)
GFX.super.new(self, world, x, y, z) 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.creator = creator
self.blockProcess = blockProcess or false self.blockProcess = blockProcess or false
@ -17,9 +19,30 @@ function GFX:new(world, x, y, z, spritename, creator, blockProcess, tag)
self.direction = 1 self.direction = 1
end 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 if self.world.assets.sprites[spritename] == nil then
self.world.assets:addSprite(spritename, GFX_DIRECTORY .. spritename) self.world.assets:addSprite(spritename, path)
end end
local width, height = self.world.assets.sprites[spritename]:getDimensions() local width, height = self.world.assets.sprites[spritename]:getDimensions()
self:setSprite(spritename, width/2, height, true) self:setSprite(spritename, width/2, height, true)