From cdffff59c368f405af0570699c491d137385416b Mon Sep 17 00:00:00 2001 From: neckrat Date: Sun, 9 Nov 2025 18:58:01 +0300 Subject: [PATCH 1/5] init camera:animateTo --- lib/controls.lua | 1 + lib/level/camera.lua | 5 +++++ main.lua | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/lib/controls.lua b/lib/controls.lua index 652d26a..71a119e 100644 --- a/lib/controls.lua +++ b/lib/controls.lua @@ -17,6 +17,7 @@ controls.keymap = { cameraMoveRight = control("key", "d"), cameraMoveDown = control("key", "s"), cameraMoveScroll = control("mouse", "3"), + cameraAnimateTo = control('key', 't'), fullMana = control("key", "m"), select = control("mouse", "1"), endTurnTest = control("key", "e"), diff --git a/lib/level/camera.lua b/lib/level/camera.lua index 4040203..612a43b 100644 --- a/lib/level/camera.lua +++ b/lib/level/camera.lua @@ -87,6 +87,11 @@ function camera:detach() love.graphics.pop() end +--- @param position Vec3 +function camera:animateTo(position) + self.position = position +end + --- @return Camera local function new() return setmetatable({ diff --git a/main.lua b/main.lua index 26825d5..d3a1724 100644 --- a/main.lua +++ b/main.lua @@ -40,6 +40,13 @@ function love.update(dt) Tree.level.turnOrder:toggleTurns() end + -- для тестов camera:attachTo + -- удалить как только потребность в тестах исчезнет + if Tree.controls:isJustPressed("cameraAnimateTo") then + local mousePosition = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }) + Tree.level.camera:animateTo(mousePosition) + end + Tree.controls:cache() local t2 = love.timer.getTime() From 331aefb0f6dadf9e17d07b3644899dd3fa82c060 Mon Sep 17 00:00:00 2001 From: neckrat Date: Sun, 9 Nov 2025 22:16:40 +0300 Subject: [PATCH 2/5] 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() From c566d1669e05ff12bbf1501c16a567d2119dfa02 Mon Sep 17 00:00:00 2001 From: PeaAshMeter Date: Mon, 10 Nov 2025 05:07:40 +0300 Subject: [PATCH 3/5] Add mouse wheel support for zoom control in camera module (the dumb way) --- lib/controls.lua | 9 +++++++-- lib/level/camera.lua | 13 +++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/controls.lua b/lib/controls.lua index 71a119e..6fa7a60 100644 --- a/lib/controls.lua +++ b/lib/controls.lua @@ -1,5 +1,3 @@ -local utils = require "lib.utils.utils" - --- @alias Device "mouse" | "key" | "pad" --- @param device Device @@ -27,6 +25,12 @@ controls.keymap = { local currentKeys = {} local cachedKeys = {} +--- @type number +controls.mouseWheelY = 0 +love.wheelmoved = function(x, y) + controls.mouseWheelY = y +end + --- polling controls in O(n) --- should be called at the beginning of every frame function controls:poll() @@ -50,6 +54,7 @@ function controls:cache() for k, v in pairs(currentKeys) do cachedKeys[k] = v end + controls.mouseWheelY = 0 end --- marks a control consumed for the current frame diff --git a/lib/level/camera.lua b/lib/level/camera.lua index 9e0468e..c1bcb25 100644 --- a/lib/level/camera.lua +++ b/lib/level/camera.lua @@ -30,12 +30,6 @@ camera.scale = camera:getDefaultScale() --------------------------------------------------- -love.wheelmoved = function(x, y) - if camera.scale > camera:getDefaultScale() * 5 and y > 0 then return end; - if camera.scale < camera:getDefaultScale() / 5 and y < 0 then return end; - camera.scale = camera.scale + (camera.scale * 0.1 * y) -end - local controlMap = { cameraMoveUp = Vec3({ 0, -1 }), cameraMoveLeft = Vec3({ -1 }), @@ -50,6 +44,13 @@ function camera:update(dt) return end + -------------------- зум на колесо --------------------- + local y = Tree.controls.mouseWheelY + if camera.scale > camera:getDefaultScale() * 5 and y > 0 then return end; + if camera.scale < camera:getDefaultScale() / 5 and y < 0 then return end; + camera.scale = camera.scale + (camera.scale * 0.1 * y) + -------------------------------------------------------- + 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) From 123885b2b3c49cc45a51ad6bce00a0d93f0c0933 Mon Sep 17 00:00:00 2001 From: PeaAshMeter Date: Mon, 10 Nov 2025 05:09:56 +0300 Subject: [PATCH 4/5] Reset camera velocity when starting animation --- lib/level/camera.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/level/camera.lua b/lib/level/camera.lua index c1bcb25..b2d5138 100644 --- a/lib/level/camera.lua +++ b/lib/level/camera.lua @@ -104,6 +104,7 @@ function camera:animateTo(position, animationNode) self.animationNode = animationNode self.animationEndPosition = position self.animationBeginPosition = self.position + self.velocity = Vec3 {} end --- @return Camera From e7e4071931212f56e57948e66a1da6f28cef6e20 Mon Sep 17 00:00:00 2001 From: neckrat Date: Tue, 11 Nov 2025 00:01:42 +0300 Subject: [PATCH 5/5] deleted tests --- main.lua | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/main.lua b/main.lua index 30e40a1..26825d5 100644 --- a/main.lua +++ b/main.lua @@ -40,17 +40,6 @@ function love.update(dt) Tree.level.turnOrder:toggleTurns() end - -- для тестов camera:animateTo - -- удалить как только потребность в тестах исчезнет - if Tree.controls:isJustPressed("cameraAnimateTo") then - local mousePosition = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }) - 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() local t2 = love.timer.getTime()