From ab37f6816de1ff3d1bb268f41f38b59b2f8f80c7 Mon Sep 17 00:00:00 2001 From: PeaAshMeter Date: Sat, 17 Jan 2026 18:26:13 +0300 Subject: [PATCH] add demo dynamic light on dev_mana cast --- lib/animation_node.lua | 1 + lib/character/behaviors/residentsleeper.lua | 13 +++-------- lib/spellbook.lua | 25 +++++++++++++++++---- main.lua | 13 ----------- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/lib/animation_node.lua b/lib/animation_node.lua index b8309e7..e3f5aff 100644 --- a/lib/animation_node.lua +++ b/lib/animation_node.lua @@ -89,6 +89,7 @@ local function new(data) t.t = 0 t.state = "running" t.finish = function() + if t.state ~= "running" then return end t.state = "waiting" t:bubbleUp() for _, anim in ipairs(t.children) do diff --git a/lib/character/behaviors/residentsleeper.lua b/lib/character/behaviors/residentsleeper.lua index 6c5af5f..c46b701 100644 --- a/lib/character/behaviors/residentsleeper.lua +++ b/lib/character/behaviors/residentsleeper.lua @@ -1,7 +1,6 @@ --- Умеет асинхронно ждать какое-то время (для анимаций) --- @class ResidentSleeperBehavior : Behavior --- @field animationNode? AnimationNode ---- @field endsAt? number local behavior = {} behavior.__index = behavior behavior.id = "residentsleeper" @@ -10,19 +9,13 @@ function behavior.new() return setmetatable({}, behavior) end function behavior:update(dt) if not self.animationNode then return end - if love.timer.getTime() >= self.endsAt then - self.animationNode:finish() - self.animationNode = nil - self.endsAt = nil - end + self.animationNode:update(dt) end ---- @param ms number time to wait in milliseconds --- @param node AnimationNode -function behavior:sleep(ms, node) - if self.animationNode then node:finish() end +function behavior:sleep(node) + if self.animationNode then self.animationNode:finish() end self.animationNode = node - self.endsAt = love.timer.getTime() + ms / 1000 end return behavior diff --git a/lib/spellbook.lua b/lib/spellbook.lua index 2149541..e50fc82 100644 --- a/lib/spellbook.lua +++ b/lib/spellbook.lua @@ -8,15 +8,16 @@ --- Да, это Future/Promise/await/async local AnimationNode = require "lib.animation_node" +local easing = require "lib.utils.easing" --- @class Spell Здесь будет много бойлерплейта, поэтому тоже понадобится спеллмейкерский фреймворк, который просто вернет готовый Spell --- @field tag string --- @field update fun(self: Spell, caster: Character, dt: number): nil Изменяет состояние спелла --- @field draw fun(self: Spell): nil Рисует превью каста, ничего не должна изменять в идеальном мире --- @field cast fun(self: Spell, caster: Character, target: Vec3): boolean Вызывается в момент каста, изменяет мир. Возвращает bool в зависимости от того, получилось ли скастовать -local spell = {} -spell.__index = spell -spell.tag = "base" +local spell = {} +spell.__index = spell +spell.tag = "base" function spell:update(caster, dt) end @@ -90,6 +91,13 @@ function regenerateMana:cast(caster, target) print(caster.id, "has regenerated mana and gained initiative") local sprite = caster:has(Tree.behaviors.sprite) if not sprite then return true end + + local light = require "lib/character/character".spawn("Light Effect") + light:addBehavior { + Tree.behaviors.light.new { color = Vec3 { 0.6, 0.3, 0.3 }, intensity = 4 }, + Tree.behaviors.residentsleeper.new(), + Tree.behaviors.positioned.new(caster:has(Tree.behaviors.positioned).position + Vec3 { 0.5, 0.5 }), + } AnimationNode { function(node) sprite:animate("hurt", node) @@ -97,6 +105,14 @@ function regenerateMana:cast(caster, target) onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end }:run() + AnimationNode { + function(node) + light:has(Tree.behaviors.residentsleeper):sleep(node) + end, + duration = 400, + onEnd = function() light:die() end + }:run() + return true end @@ -140,8 +156,9 @@ function attack:cast(caster, target) }, AnimationNode { function(node) - targetCharacter:has(Tree.behaviors.residentsleeper):sleep(200, node) + targetCharacter:has(Tree.behaviors.residentsleeper):sleep(node) end, + duration = 200, children = { AnimationNode { function(node) diff --git a/main.lua b/main.lua index 846cac0..26d002d 100644 --- a/main.lua +++ b/main.lua @@ -39,12 +39,6 @@ function love.load() Tree.level.turnOrder:add(id) end - character.spawn("My Light") - :addBehavior { - Tree.behaviors.light.new { color = Vec3 { 88, 34, 13 }, intensity = 10 }, - Tree.behaviors.positioned.new(), - Tree.behaviors.cursor.new() - } Tree.level.turnOrder:endRound() print("Now playing:", Tree.level.turnOrder.current) @@ -61,13 +55,6 @@ function love.update(dt) Tree.controls:cache() - if t1 > 2 then - local foodor = Tree.level.characters[1] - if not foodor then return end - print("Killing Foodor") - foodor:die() - end - local t2 = love.timer.getTime() lt = string.format("%.3f", (t2 - t1) * 1000) end