Compare commits
6 Commits
59f1227033
...
187b8b3c74
| Author | SHA1 | Date | |
|---|---|---|---|
| 187b8b3c74 | |||
| e7e4071931 | |||
| 123885b2b3 | |||
| c566d1669e | |||
| 331aefb0f6 | |||
| cdffff59c3 |
@ -1,5 +1,3 @@
|
|||||||
local utils = require "lib.utils.utils"
|
|
||||||
|
|
||||||
--- @alias Device "mouse" | "key" | "pad"
|
--- @alias Device "mouse" | "key" | "pad"
|
||||||
|
|
||||||
--- @param device Device
|
--- @param device Device
|
||||||
@ -17,6 +15,7 @@ controls.keymap = {
|
|||||||
cameraMoveRight = control("key", "d"),
|
cameraMoveRight = control("key", "d"),
|
||||||
cameraMoveDown = control("key", "s"),
|
cameraMoveDown = control("key", "s"),
|
||||||
cameraMoveScroll = control("mouse", "3"),
|
cameraMoveScroll = control("mouse", "3"),
|
||||||
|
cameraAnimateTo = control('key', 't'),
|
||||||
fullMana = control("key", "m"),
|
fullMana = control("key", "m"),
|
||||||
select = control("mouse", "1"),
|
select = control("mouse", "1"),
|
||||||
endTurnTest = control("key", "e"),
|
endTurnTest = control("key", "e"),
|
||||||
@ -26,6 +25,12 @@ controls.keymap = {
|
|||||||
local currentKeys = {}
|
local currentKeys = {}
|
||||||
local cachedKeys = {}
|
local cachedKeys = {}
|
||||||
|
|
||||||
|
--- @type number
|
||||||
|
controls.mouseWheelY = 0
|
||||||
|
love.wheelmoved = function(x, y)
|
||||||
|
controls.mouseWheelY = y
|
||||||
|
end
|
||||||
|
|
||||||
--- polling controls in O(n)
|
--- polling controls in O(n)
|
||||||
--- should be called at the beginning of every frame
|
--- should be called at the beginning of every frame
|
||||||
function controls:poll()
|
function controls:poll()
|
||||||
@ -49,6 +54,7 @@ function controls:cache()
|
|||||||
for k, v in pairs(currentKeys) do
|
for k, v in pairs(currentKeys) do
|
||||||
cachedKeys[k] = v
|
cachedKeys[k] = v
|
||||||
end
|
end
|
||||||
|
controls.mouseWheelY = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
--- marks a control consumed for the current frame
|
--- marks a control consumed for the current frame
|
||||||
|
|||||||
@ -9,6 +9,9 @@ local EPSILON = 0.001
|
|||||||
--- @field speed number
|
--- @field speed number
|
||||||
--- @field pixelsPerMeter integer
|
--- @field pixelsPerMeter integer
|
||||||
--- @field scale number
|
--- @field scale number
|
||||||
|
--- @field animationNode AnimationNode?
|
||||||
|
--- @field animationEndPosition Vec3
|
||||||
|
--- @field animationBeginPosition Vec3
|
||||||
local camera = {
|
local camera = {
|
||||||
position = Vec3 {},
|
position = Vec3 {},
|
||||||
velocity = Vec3 {},
|
velocity = Vec3 {},
|
||||||
@ -27,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 = {
|
local controlMap = {
|
||||||
cameraMoveUp = Vec3({ 0, -1 }),
|
cameraMoveUp = Vec3({ 0, -1 }),
|
||||||
cameraMoveLeft = Vec3({ -1 }),
|
cameraMoveLeft = Vec3({ -1 }),
|
||||||
@ -41,6 +38,19 @@ local controlMap = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function camera:update(dt)
|
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 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
|
local ps = Tree.panning
|
||||||
if ps.delta:length() > 0 then
|
if ps.delta:length() > 0 then
|
||||||
local worldDelta = ps.delta:scale(1 / (self.pixelsPerMeter * self.scale)):scale(dt):scale(self.speed)
|
local worldDelta = ps.delta:scale(1 / (self.pixelsPerMeter * self.scale)):scale(dt):scale(self.speed)
|
||||||
@ -87,6 +97,16 @@ function camera:detach()
|
|||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param position Vec3
|
||||||
|
--- @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
|
||||||
|
self.velocity = Vec3 {}
|
||||||
|
end
|
||||||
|
|
||||||
--- @return Camera
|
--- @return Camera
|
||||||
local function new()
|
local function new()
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user