Skip to content

Commit

Permalink
feat: add setVelocity method
Browse files Browse the repository at this point in the history
  • Loading branch information
littensy committed Aug 20, 2024
1 parent 9c07a8a commit a8cc437
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion scripts/analyze.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
curl -o scripts/roblox.d.lua https://raw.githubusercontent.com/JohnnyMorganz/luau-lsp/main/scripts/globalTypes.d.luau
curl -o scripts/roblox.d.luau https://raw.githubusercontent.com/JohnnyMorganz/luau-lsp/main/scripts/globalTypes.d.luau

rojo sourcemap test.project.json -o sourcemap.json

Expand Down
24 changes: 19 additions & 5 deletions src/createMotion.luau
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ local function createMotion<T>(initialValue: T, options: types.MotionOptions?):
end

state.complete = false
state.velocity = state.velocity :: number + impulses
state.velocity += impulses
end

return
Expand All @@ -123,10 +123,23 @@ local function createMotion<T>(initialValue: T, options: types.MotionOptions?):
end

state.complete = false
state.velocity = state.velocity :: number + amount
state.velocity += amount
end
end

local function setVelocity(_self, velocity)
local intermediates = intermediate.to(velocity)

for key, amount in intermediates do
local state = motionState[key]

if not state or not state.velocity then
continue
end

return
state.complete = false
state.velocity = amount
end
end

local function to(_self, solvers)
Expand Down Expand Up @@ -268,10 +281,11 @@ local function createMotion<T>(initialValue: T, options: types.MotionOptions?):
start = start,
stop = stop,
get = get,
getVelocity = getVelocity,
set = set,
patch = patch,
getVelocity = getVelocity,
setVelocity = setVelocity,
impulse = impulse,
patch = patch,
to = to,
immediate = immediate,
linear = linear,
Expand Down
2 changes: 2 additions & 0 deletions src/createMotion.spec.luau
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ return function()
expect(motion.stop).to.be.a("function")
expect(motion.get).to.be.a("function")
expect(motion.set).to.be.a("function")
expect(motion.getVelocity).to.be.a("function")
expect(motion.setVelocity).to.be.a("function")
expect(motion.patch).to.be.a("function")
expect(motion.impulse).to.be.a("function")
expect(motion.to).to.be.a("function")
Expand Down
3 changes: 2 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ declare namespace Ripple {
start(): Cleanup;
stop(): void;
get(): T;
getVelocity(): T;
set(value: PartialMotionGoal<T>): void;
getVelocity(): T;
setVelocity(velocity: PartialMotionGoal<T>): void;
impulse(velocity: PartialMotionGoal<T>): void;
to(solver: MotionSolver<T> | MapSolvers<PartialMotionGoal<T>>): void;
immediate(goal: PartialMotionGoal<T>): void;
Expand Down
5 changes: 3 additions & 2 deletions src/types.luau
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export type Motion<T = number> = {
start: (self: Motion<T>) -> Cleanup,
stop: (self: Motion<T>) -> (),
get: (self: Motion<T>) -> T,
getVelocity: (self: Motion<T>) -> T,
set: (self: Motion<T>, value: T | { [any]: number }) -> (),
patch: (self: Motion<T>, patch: { [any]: Partial<MotionState> }) -> (),
getVelocity: (self: Motion<T>) -> T,
setVelocity: (self: Motion<T>, value: T | { [any]: number }) -> (),
impulse: (self: Motion<T>, impulse: T | { [any]: number }) -> (),
patch: (self: Motion<T>, patch: { [any]: Partial<MotionState> }) -> (),
to: (self: Motion<T>, goal: MotionSolver | { [any]: MotionSolver }) -> (),
immediate: (self: Motion<T>, goal: T) -> (),
spring: (self: Motion<T>, goal: T, options: SpringOptions?) -> (),
Expand Down
19 changes: 0 additions & 19 deletions src/utils/graph.luau

This file was deleted.

0 comments on commit a8cc437

Please sign in to comment.