@quenty/steputils 3.0.1-canary.9c1fd3b.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [3.0.1-canary.9c1fd3b.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/steputils@3.0.0...@quenty/steputils@3.0.1-canary.9c1fd3b.0) (2021-09-11)
6
+ ## [3.0.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/steputils@3.0.0...@quenty/steputils@3.0.1) (2021-12-30)
7
7
 
8
8
  **Note:** Version bump only for package @quenty/steputils
9
9
 
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014 Quenty
3
+ Copyright (c) 2014-2021 Quenty
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  ## StepUtils
2
2
  <div align="center">
3
- <a href="http://quenty.github.io/api/">
4
- <img src="https://img.shields.io/badge/docs-website-green.svg" alt="Documentation" />
3
+ <a href="http://quenty.github.io/NevermoreEngine/">
4
+ <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
5
5
  </a>
6
6
  <a href="https://discord.gg/mhtGUS8">
7
- <img src="https://img.shields.io/badge/discord-nevermore-blue.svg" alt="Discord" />
7
+ <img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
8
8
  </a>
9
9
  <a href="https://github.com/Quenty/NevermoreEngine/actions">
10
10
  <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
@@ -13,23 +13,9 @@
13
13
 
14
14
  Binds animations into step, where the animation only runs as needed
15
15
 
16
+ <div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/StepUtils">View docs →</a></div>
17
+
16
18
  ## Installation
17
19
  ```
18
20
  npm install @quenty/steputils --save
19
- ```
20
-
21
- ## Usage
22
- Usage is designed to be simple.
23
-
24
- ### `StepUtils.bindToRenderStep(update)`
25
-
26
- ### `StepUtils.bindToSignal(signal, update)`
27
-
28
- ### `StepUtils.onceAtRenderPriority(priority, func)`
29
-
30
- ### `StepUtils.onceAtStepped(func)`
31
-
32
- ### `StepUtils.onceAtRenderStepped(func)`
33
-
34
- ### `StepUtils.onceAtEvent(event, func)`
35
-
21
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/steputils",
3
- "version": "3.0.1-canary.9c1fd3b.0",
3
+ "version": "3.0.1",
4
4
  "description": "Binds animations into step, where the animation only runs as needed",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,5 +27,5 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "9c1fd3b43a16f8bc00caafbbb3f7092b4e5cc9eb"
30
+ "gitHead": "d146c77d0a8e452824de0ab0b4b03ba0370bcc1b"
31
31
  }
@@ -1,17 +1,53 @@
1
- --- Binds animations into step, where the animation only runs as needed
2
- -- @module StepUtils
3
- -- @author Quenty
1
+ --[=[
2
+ Utility functions primarily used to bind animations into update loops of the Roblox engine.
3
+ @class StepUtils
4
+ ]=]
4
5
 
5
6
  local HttpService = game:GetService("HttpService")
6
7
  local RunService = game:GetService("RunService")
7
8
 
8
9
  local StepUtils = {}
9
10
 
10
- -- update should return true while it needs to update
11
+ --[=[
12
+ Binds the given update function to render stepped.
13
+
14
+ ```lua
15
+ local spring = Spring.new(0)
16
+ local maid = Maid.new()
17
+
18
+ local startAnimation, maid._stopAnimation = StepUtils.bindToRenderStep(function()
19
+ local animating, position = SpringUtils.animating(spring)
20
+
21
+ print(position)
22
+
23
+ return animating
24
+ end)
25
+
26
+ spring.t = 1
27
+ startAnimation()
28
+ ```
29
+
30
+ :::tip
31
+ Be sure to call the disconnect function when cleaning up, otherwise you may memory leak.
32
+ :::
33
+
34
+ @param update () -> boolean -- should return true while it needs to update
35
+ @return (...) -> () -- Connect function
36
+ @return () -> () -- Disconnect function
37
+ ]=]
11
38
  function StepUtils.bindToRenderStep(update)
12
39
  return StepUtils.bindToSignal(RunService.RenderStepped, update)
13
40
  end
14
41
 
42
+ --[=[
43
+ Binds an update event to a signal until the update function stops returning a truthy
44
+ value.
45
+
46
+ @param signal Signal | RBXScriptSignal
47
+ @param update () -> boolean -- should return true while it needs to update
48
+ @return (...) -> () -- Connect function
49
+ @return () -> () -- Disconnect function
50
+ ]=]
15
51
  function StepUtils.bindToSignal(signal, update)
16
52
  if typeof(signal) ~= "RBXScriptSignal" then
17
53
  error("signal must be of type RBXScriptSignal")
@@ -58,6 +94,14 @@ function StepUtils.bindToSignal(signal, update)
58
94
  return connect, disconnect
59
95
  end
60
96
 
97
+ --[=[
98
+ Calls the function once at the given priority level, unless the cancel callback is
99
+ invoked.
100
+
101
+ @param priority number
102
+ @param func function -- Function to call
103
+ @return function -- Call this function to cancel call
104
+ ]=]
61
105
  function StepUtils.onceAtRenderPriority(priority, func)
62
106
  assert(type(priority) == "number", "Bad priority")
63
107
  assert(type(func) == "function", "Bad func")
@@ -76,14 +120,39 @@ function StepUtils.onceAtRenderPriority(priority, func)
76
120
  return cleanup
77
121
  end
78
122
 
123
+ --[=[
124
+ Invokes the function once at stepped, unless the cancel callback is called.
125
+
126
+ ```lua
127
+ -- Sometimes you need to defer the execution of code to make physics happy
128
+ maid:GiveTask(StepUtils.onceAtStepped(function()
129
+ part.CFrame = CFrame.new(0, 0, )
130
+ end))
131
+ ```
132
+ @param func function -- Function to call
133
+ @return function -- Call this function to cancel call
134
+ ]=]
79
135
  function StepUtils.onceAtStepped(func)
80
136
  return StepUtils.onceAtEvent(RunService.Stepped, func)
81
137
  end
82
138
 
139
+ --[=[
140
+ Invokes the function once at renderstepped, unless the cancel callback is called.
141
+
142
+ @param func function -- Function to call
143
+ @return function -- Call this function to cancel call
144
+ ]=]
83
145
  function StepUtils.onceAtRenderStepped(func)
84
146
  return StepUtils.onceAtEvent(RunService.RenderStepped, func)
85
147
  end
86
148
 
149
+ --[=[
150
+ Invokes the function once at the given event, unless the cancel callback is called.
151
+
152
+ @param event Signal | RBXScriptSignal
153
+ @param func function -- Function to call
154
+ @return function -- Call this function to cancel call
155
+ ]=]
87
156
  function StepUtils.onceAtEvent(event, func)
88
157
  assert(type(func) == "function", "Bad func")
89
158
 
@@ -103,5 +172,4 @@ function StepUtils.onceAtEvent(event, func)
103
172
  return cleanup
104
173
  end
105
174
 
106
-
107
175
  return StepUtils
@@ -1,9 +1,19 @@
1
- --- Executes code at a specific point in render step priority queue
2
- -- @module onRenderStepFrame
1
+ --[=[
2
+ Executes code at a specific point in render step priority queue
3
+ @class onRenderStepFrame
4
+ ]=]
3
5
 
4
6
  local RunService = game:GetService("RunService")
5
7
  local HttpService = game:GetService("HttpService")
6
8
 
9
+ --[=[
10
+ Executes code at a specific point in render step priority queue.
11
+ @function onRenderStepFrame
12
+ @param priority number
13
+ @return MaidTask
14
+ @within onRenderStepFrame
15
+ ]=]
16
+
7
17
  return function(priority, callback)
8
18
  assert(type(priority) == "number", "Bad priority")
9
19
  assert(type(callback) == "function", "Bad callback")
@@ -1,15 +1,24 @@
1
- --- Executes code at a specific point in Roblox's engine
2
- -- @module onSteppedFrame
1
+ --[=[
2
+ Executes code at a specific point in Roblox's engine
3
+ @class onSteppedFrame
4
+ ]=]
3
5
 
4
6
  local RunService = game:GetService("RunService")
5
7
 
6
- return function(_function)
7
- assert(type(_function) == "function", "Bad _function")
8
+ --[=[
9
+ Executes code at a specific point in Roblox's engine.
10
+ @function onSteppedFrame
11
+ @param func function
12
+ @return RBXScriptConnection
13
+ @within onSteppedFrame
14
+ ]=]
15
+ return function(func)
16
+ assert(type(func) == "function", "Bad func")
8
17
 
9
18
  local conn
10
19
  conn = RunService.Stepped:Connect(function()
11
20
  conn:Disconnect()
12
- _function()
21
+ func()
13
22
  end)
14
23
 
15
24
  return conn