diff --git a/src/createMotion.luau b/src/createMotion.luau index c1b859c..39ded2f 100644 --- a/src/createMotion.luau +++ b/src/createMotion.luau @@ -210,7 +210,7 @@ local function createMotion(initialValue: T, options: types.MotionOptions?): local value = self:get() local complete = self:isComplete() - if not wasComplete or not complete then + if not complete or not wasComplete or lastCompleteValue ~= value then for _, listener in onStepListeners do task.spawn(listener, value, deltaTime) end diff --git a/src/solvers/immediate.spec.luau b/src/solvers/immediate.spec.luau index 64a4919..4edbbe9 100644 --- a/src/solvers/immediate.spec.luau +++ b/src/solvers/immediate.spec.luau @@ -6,7 +6,7 @@ return function() local motion = createMotion({ x = 0, y = 0 }) motion:to(immediate({ x = 1, y = 1 })) - motion:step(0) + motion:step(1) expect(motion:get()).to.be.ok() expect(motion:get().x).to.equal(1) @@ -18,7 +18,7 @@ return function() local motion = createMotion({ x = 0, y = 0 }) motion:to({ x = immediate(1), y = immediate(1) }) - motion:step(0) + motion:step(1) expect(motion:get()).to.be.ok() expect(motion:get().x).to.equal(1) @@ -26,11 +26,72 @@ return function() expect(motion:isComplete()).to.equal(true) motion:to({ x = immediate(2), y = immediate(2) }) - motion:step(0) + motion:step(1) expect(motion:get()).to.be.ok() expect(motion:get().x).to.equal(2) expect(motion:get().y).to.equal(2) expect(motion:isComplete()).to.equal(true) end) + + it("should wake spring after last completion", function() + local motion = createMotion(0) + + motion:linear(1, { speed = 1 }) + motion:step(1) + + expect(motion:isComplete()).to.equal(true) + + local firedOnStep = 0 + local firedOnComplete = 0 + + motion:onStep(function() + firedOnStep += 1 + end) + + motion:onComplete(function() + firedOnComplete += 1 + end) + + motion:immediate(0) + + expect(motion:isComplete()).to.equal(false) + + motion:step(1) + + expect(motion:isComplete()).to.equal(true) + expect(firedOnStep).to.equal(1) + expect(firedOnComplete).to.equal(1) + + motion:step(1) + + expect(firedOnStep).to.equal(1) + expect(firedOnComplete).to.equal(1) + end) + + it("should trigger events", function() + local motion = createMotion(0) + local firedOnStep = 0 + local firedOnComplete = 0 + + motion:onStep(function() + firedOnStep += 1 + end) + + motion:onComplete(function() + firedOnComplete += 1 + end) + + motion:immediate(0) + motion:step(1) + + expect(motion:isComplete()).to.equal(true) + expect(firedOnStep).to.equal(1) + expect(firedOnComplete).to.equal(1) + + motion:step(1) + + expect(firedOnStep).to.equal(1) + expect(firedOnComplete).to.equal(1) + end) end diff --git a/wally.lock b/wally.lock index e2db01c..11bf078 100644 --- a/wally.lock +++ b/wally.lock @@ -9,7 +9,7 @@ dependencies = [] [[package]] name = "littensy/ripple" -version = "0.8.1" +version = "0.9.1" dependencies = [["Promise", "evaera/promise@4.0.0"], ["TestEZ", "roblox/testez@0.4.1"]] [[package]]