From 331aefb0f6dadf9e17d07b3644899dd3fa82c060 Mon Sep 17 00:00:00 2001 From: neckrat Date: Sun, 9 Nov 2025 22:16:40 +0300 Subject: [PATCH] i love easing4d Co-authored-by: Ivan Yuriev --- lib/level/camera.lua | 17 +++++++++++++++-- main.lua | 8 ++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/level/camera.lua b/lib/level/camera.lua index 612a43b..9e0468e 100644 --- a/lib/level/camera.lua +++ b/lib/level/camera.lua @@ -9,6 +9,9 @@ local EPSILON = 0.001 --- @field speed number --- @field pixelsPerMeter integer --- @field scale number +--- @field animationNode AnimationNode? +--- @field animationEndPosition Vec3 +--- @field animationBeginPosition Vec3 local camera = { position = Vec3 {}, velocity = Vec3 {}, @@ -41,6 +44,12 @@ local controlMap = { } function camera:update(dt) + if self.animationNode and not (self.animationNode.t >= 1) then + self.animationNode:update(dt) -- тик анимации + self.position = utils.lerp(self.animationBeginPosition, self.animationEndPosition, self.animationNode:getValue()) + return + end + local ps = Tree.panning if ps.delta:length() > 0 then local worldDelta = ps.delta:scale(1 / (self.pixelsPerMeter * self.scale)):scale(dt):scale(self.speed) @@ -88,8 +97,12 @@ function camera:detach() end --- @param position Vec3 -function camera:animateTo(position) - self.position = position +--- @param animationNode AnimationNode +function camera:animateTo(position, animationNode) + if self.animationNode then self.animationNode:finish() end + self.animationNode = animationNode + self.animationEndPosition = position + self.animationBeginPosition = self.position end --- @return Camera diff --git a/main.lua b/main.lua index d3a1724..30e40a1 100644 --- a/main.lua +++ b/main.lua @@ -40,11 +40,15 @@ function love.update(dt) Tree.level.turnOrder:toggleTurns() end - -- для тестов camera:attachTo + -- для тестов camera:animateTo -- удалить как только потребность в тестах исчезнет if Tree.controls:isJustPressed("cameraAnimateTo") then local mousePosition = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }) - Tree.level.camera:animateTo(mousePosition) + require('lib.animation_node') { + function(animationNode) Tree.level.camera:animateTo(mousePosition, animationNode) end, + onEnd = function() print('completed') end, + easing = require("lib.utils.easing").easeInOutCubic + }:run() end Tree.controls:cache()