From 4a8ea25b7e55df01ff029a5e286d74ffd7a39e33 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 4 Jul 2021 11:43:46 +0200 Subject: [PATCH] feat: ajout d'un viewer des animations --- sonic-radiance.love/scenes/debug/init.lua | 3 +- .../scenes/debug/menu/init.lua | 1 + .../scenes/debug/viewers/animation/init.lua | 61 +++++++++++++++++++ .../scenes/debug/viewers/animation/menu.lua | 19 ++++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 sonic-radiance.love/scenes/debug/viewers/animation/init.lua create mode 100644 sonic-radiance.love/scenes/debug/viewers/animation/menu.lua diff --git a/sonic-radiance.love/scenes/debug/init.lua b/sonic-radiance.love/scenes/debug/init.lua index 1bb65b9..3cd6af2 100644 --- a/sonic-radiance.love/scenes/debug/init.lua +++ b/sonic-radiance.love/scenes/debug/init.lua @@ -2,6 +2,7 @@ return { menu = require "scenes.debug.menu", viewers = { battleBack = require "scenes.debug.viewers.battleBack", - choregraphy = require "scenes.debug.viewers.choregraphy" + choregraphy = require "scenes.debug.viewers.choregraphy", + animation = require "scenes.debug.viewers.animation", } } diff --git a/sonic-radiance.love/scenes/debug/menu/init.lua b/sonic-radiance.love/scenes/debug/menu/init.lua index c71ef87..10cf03e 100644 --- a/sonic-radiance.love/scenes/debug/menu/init.lua +++ b/sonic-radiance.love/scenes/debug/menu/init.lua @@ -60,6 +60,7 @@ function DebugMenu:buildBattleMenu() end menu.commons.SceneWidget(self, "combat", scenes.debug.viewers.battleBack, "Background Viewer") + menu.commons.SceneWidget(self, "combat", scenes.debug.viewers.animation, "Animation Viewer") menu.commons.SceneWidget(self, "combat", scenes.debug.viewers.choregraphy, "Ennemies' Action Viewer") end diff --git a/sonic-radiance.love/scenes/debug/viewers/animation/init.lua b/sonic-radiance.love/scenes/debug/viewers/animation/init.lua new file mode 100644 index 0000000..51c10ba --- /dev/null +++ b/sonic-radiance.love/scenes/debug/viewers/animation/init.lua @@ -0,0 +1,61 @@ +local Scene = require "birb.modules.scenes" +local menu = require "scenes.debug.viewers.animation.menu" + +local CharAnimViewer = Scene:extend() +local Background = require "game.modules.drawing.parallaxBackground" +local Sprite = require "birb.modules.assets.types.sprites" + + +function CharAnimViewer:new() + CharAnimViewer.super.new(self) + self.assets:batchImport("scenes.debug.commons.assets") + local mainMenu = menu.commons.DebugMenu(self, "MainMenu") + + self:setBackground("city") + + for charName, _ in pairs(game.characters.list) do + mainMenu:addSubMenu(charName, charName) + local sprite = Sprite("datas/gamedata/characters/" .. charName .. "/sprites") + for animName, _ in pairs(sprite.data.animations) do + menu.AnimationWidget(self, charName, animName) + end + end + menu.commons.SceneWidget(self, "MainMenu", scenes.debug.menu, "Back") + + self.menusystem:activate() + self.menusystem:switchMenu("MainMenu") + + self.sprite = nil +end + +function CharAnimViewer:constructMenu() + +end + +function CharAnimViewer:setSpriteAndAnim(character, animationName) + self.sprite = Sprite("datas/gamedata/characters/" .. character .. "/sprites") + self.sprite:changeAnimation(animationName, true) +end + + +function CharAnimViewer:update(dt) + if (love.keyboard.isDown("z") and (not self.menusystem.isActive)) then + self.menusystem:activate() + end + if (self.sprite ~= nil) then + self.sprite:update(dt) + end +end + +function CharAnimViewer:setBackground(newBackground) + self.background = Background(self, 5, 1, newBackground) +end + +function CharAnimViewer:draw() + self.background:draw() + if (self.sprite ~= nil) then + self.sprite:drawAnimation(424/2, 240/1.5) + end +end + +return CharAnimViewer diff --git a/sonic-radiance.love/scenes/debug/viewers/animation/menu.lua b/sonic-radiance.love/scenes/debug/viewers/animation/menu.lua new file mode 100644 index 0000000..2dd6eac --- /dev/null +++ b/sonic-radiance.love/scenes/debug/viewers/animation/menu.lua @@ -0,0 +1,19 @@ +local commons = require "scenes.debug.commons.menu" +local listMenu = require "game.modules.menus.list" +local menu = {} +menu.commons = commons +menu.AnimationWidget = listMenu.DualTextWidget:extend() + +-- ShowBackground +function menu.AnimationWidget:new(scene, menuName, animName) + menu.AnimationWidget.super.new(self, scene, menuName, animName, "") + self.charName = menuName + self.animName = animName +end + +function menu.AnimationWidget:action() + self.scene:setSpriteAndAnim(self.charName, self.animName) + self.scene.menusystem:deactivate() +end + +return menu