diff --git a/macrovision.js b/macrovision.js index eda7a895..9dbc0d73 100644 --- a/macrovision.js +++ b/macrovision.js @@ -4289,4 +4289,48 @@ function toastRateLimit(msg, key, delay) { delete rateLimits[key] }, delay); } +} +let lastTime = undefined; + +function pan(fromX, fromY, fromHeight, toX, toY, toHeight, duration) { + + Object.keys(entities).forEach(key => { + document.querySelector("#entity-" + key).classList.add("no-transition"); + }); + + config.x = fromX; + config.y = fromY; + config.height = math.unit(fromHeight, "meters") + updateSizes(); + + lastTime = undefined; + + requestAnimationFrame((timestamp) => panTo(toX, toY, toHeight, (toX - fromX) / duration, (toY - fromY) / duration, (toHeight - fromHeight) / duration, timestamp, duration)); +} + +function panTo(x, y, height, xSpeed, ySpeed, heightSpeed, timestamp, remaining) { + if (lastTime === undefined) { + lastTime = timestamp; + } + dt = timestamp - lastTime; + remaining -= dt; + console.log(lastTime, remaining, dt) + if (remaining < 0) { + dt += remaining + } + let newX = config.x + xSpeed * dt; + let newY = config.y + ySpeed * dt; + let newHeight = config.height.toNumber("meters") + heightSpeed * dt; + console.log(newX); + if (remaining > 0) { + requestAnimationFrame((timestamp) => panTo(x, y, height, xSpeed, ySpeed, heightSpeed, timestamp, remaining)) + } else { + Object.keys(entities).forEach(key => { + document.querySelector("#entity-" + key).classList.remove("no-transition"); + }); + } + config.x = newX; + config.y = newY; + config.height = math.unit(newHeight, "meters"); + updateSizes(); } \ No newline at end of file