2021-08-07 11:47:26 +02:00
|
|
|
local Parent = require("scenes.battlesystem.actors.movable")
|
2019-08-18 19:02:14 +02:00
|
|
|
local GFX = Parent:extend()
|
2021-08-15 14:49:03 +02:00
|
|
|
local GFX_DIRECTORY = "assets/sprites/gfx/"
|
2019-08-18 19:02:14 +02:00
|
|
|
|
2021-07-17 21:23:08 +02:00
|
|
|
function GFX:new(world, x, y, z, spritename, creator, blockProcess, tag)
|
2019-08-18 19:02:14 +02:00
|
|
|
GFX.super.new(self, world, x, y, z)
|
2021-08-15 15:25:44 +02:00
|
|
|
|
|
|
|
self.char = self:getCharacter(creator.choregraphy.fighter)
|
|
|
|
self:setAnimation(spritename)
|
2021-08-15 14:49:03 +02:00
|
|
|
|
2019-08-18 19:02:14 +02:00
|
|
|
self.creator = creator
|
|
|
|
self.blockProcess = blockProcess or false
|
2021-07-17 21:23:08 +02:00
|
|
|
self.tag = tag or ""
|
2019-08-18 19:02:14 +02:00
|
|
|
|
2021-08-07 12:02:28 +02:00
|
|
|
if (not utils.string.isEmpty(self.tag)) then
|
|
|
|
self:setIndexName(self.tag)
|
|
|
|
end
|
|
|
|
|
2019-08-18 19:02:14 +02:00
|
|
|
self.direction = 1
|
|
|
|
end
|
|
|
|
|
2021-08-15 15:25:44 +02:00
|
|
|
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)
|
2021-08-15 14:49:03 +02:00
|
|
|
if self.world.assets.sprites[spritename] == nil then
|
2021-08-15 15:25:44 +02:00
|
|
|
self.world.assets:addSprite(spritename, path)
|
2021-08-15 14:49:03 +02:00
|
|
|
end
|
|
|
|
local width, height = self.world.assets.sprites[spritename]:getDimensions()
|
|
|
|
self:setSprite(spritename, width/2, height, true)
|
|
|
|
self:cloneSprite()
|
|
|
|
end
|
|
|
|
|
2019-08-18 19:02:14 +02:00
|
|
|
function GFX:animationEnded(animation)
|
|
|
|
core.debug:print("gfx", 'Current animation "' .. animation .. '" have ended, destroying gfx')
|
2020-05-02 13:01:43 +02:00
|
|
|
if (self.blockProcess) and (self.creator ~= nil) and (self.creator.getSignal ~= nil) then
|
|
|
|
self.creator:getSignal("gfxEnded")
|
|
|
|
end
|
2021-07-17 21:23:08 +02:00
|
|
|
if ((self.creator ~= nil) and (self.creator.choregraphy ~= nil) and (not utils.string.isEmpty(self.tag))) then
|
|
|
|
self.creator.choregraphy:finishTagAction(self.tag)
|
|
|
|
end
|
2019-08-18 19:02:14 +02:00
|
|
|
self:destroy()
|
|
|
|
end
|
|
|
|
|
|
|
|
function GFX:draw()
|
2021-05-09 15:07:54 +02:00
|
|
|
self:drawSprite(0, -self.z)
|
2019-08-18 19:02:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function GFX:drawShadow()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return GFX
|