From 28b8243870ea81a718d1a96a3948930177c4300b Mon Sep 17 00:00:00 2001 From: "Sean S. LeBlanc" Date: Fri, 8 Jul 2022 08:36:09 -0800 Subject: [PATCH] fix(follower): incompatibility with smooth moves (#267) refactors the movement portion of the follower hack to happen after `update` instead of during the `setTimeout`; this allows the difference in position to be caught by the `before`/`after` check in the smooth moves hack --- src/follower.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/follower.js b/src/follower.js index 616c6350..e7504ac1 100644 --- a/src/follower.js +++ b/src/follower.js @@ -71,6 +71,7 @@ function setFollower(followerName) { } var walking = false; +var shouldWalk = false; function takeStep() { if (walking) { @@ -78,23 +79,7 @@ function takeStep() { } walking = true; setTimeout(() => { - let takeAnother = false; - followers.forEach(function (follower) { - var path = paths[follower.id]; - var point = path.shift(); - if (point) { - follower.x = point.x; - follower.y = point.y; - follower.room = point.room; - } - walking = false; - if (path.length) { - takeAnother = true; - } - }); - if (takeAnother) { - takeStep(); - } + shouldWalk = true; }, hackOptions.delay); } @@ -115,6 +100,27 @@ before('update', function () { }); let movedFollower = false; after('update', function () { + if (shouldWalk) { + shouldWalk = false; + let takeAnother = false; + followers.forEach(function (follower) { + var path = paths[follower.id]; + var point = path.shift(); + if (point) { + follower.x = point.x; + follower.y = point.y; + follower.room = point.room; + } + walking = false; + if (path.length) { + takeAnother = true; + } + }); + if (takeAnother) { + takeStep(); + } + } + // only walk if player moved if (px === bitsy.player().x && py === bitsy.player().y) { return;