@quenty/promptqueue 1.0.1-canary.468.ea8a226.0

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 ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 1.0.1-canary.468.ea8a226.0 (2024-05-09)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add PromptQueue package ([6b0dd39](https://github.com/Quenty/NevermoreEngine/commit/6b0dd39938ef2d4c3b31dd9f57301668f239bb65))
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2014-2024 James Onnen (Quenty)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ ## PromptQueue
2
+
3
+ <div align="center">
4
+ <a href="http://quenty.github.io/NevermoreEngine/">
5
+ <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
6
+ </a>
7
+ <a href="https://discord.gg/mhtGUS8">
8
+ <img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
9
+ </a>
10
+ <a href="https://github.com/Quenty/NevermoreEngine/actions">
11
+ <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
12
+ </a>
13
+ </div>
14
+
15
+ Queue system for prompts and other UI
16
+
17
+ <div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/PromptQueueUtils">View docs →</a></div>
18
+
19
+ ## Installation
20
+
21
+ ```
22
+ npm install @quenty/promptqueue --save
23
+ ```
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "promptqueue",
3
+ "globIgnorePaths": [ "**/.package-lock.json" ],
4
+ "tree": {
5
+ "$path": "src"
6
+ }
7
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@quenty/promptqueue",
3
+ "version": "1.0.1-canary.468.ea8a226.0",
4
+ "description": "Queue system for prompts and other UI",
5
+ "keywords": [
6
+ "Roblox",
7
+ "Nevermore",
8
+ "Lua",
9
+ "promptqueue"
10
+ ],
11
+ "bugs": {
12
+ "url": "https://github.com/Quenty/NevermoreEngine/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/Quenty/NevermoreEngine.git",
17
+ "directory": "src/promptqueue/"
18
+ },
19
+ "funding": {
20
+ "type": "patreon",
21
+ "url": "https://www.patreon.com/quenty"
22
+ },
23
+ "license": "MIT",
24
+ "contributors": [
25
+ "Quenty"
26
+ ],
27
+ "dependencies": {
28
+ "@quenty/baseobject": "10.2.1-canary.468.ea8a226.0",
29
+ "@quenty/loader": "10.2.1-canary.468.ea8a226.0",
30
+ "@quenty/promise": "10.2.1-canary.468.ea8a226.0",
31
+ "@quenty/signal": "7.2.1-canary.468.ea8a226.0",
32
+ "@quenty/transitionmodel": "7.2.1-canary.468.ea8a226.0"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "gitHead": "ea8a2260a364aaf6d6c246a93632b789935da134"
38
+ }
@@ -0,0 +1,199 @@
1
+ --[=[
2
+ Queue system for prompts and other UI
3
+
4
+ @class PromptQueue
5
+ ]=]
6
+
7
+ local require = require(script.Parent.loader).load(script)
8
+
9
+ local Maid = require("Maid")
10
+ local BaseObject = require("BaseObject")
11
+ local Promise = require("Promise")
12
+ local TransitionModel = require("TransitionModel")
13
+ local ValueObject = require("ValueObject")
14
+ local Signal = require("Signal")
15
+
16
+ local PromptQueue = setmetatable({}, BaseObject)
17
+ PromptQueue.ClassName = "PromptQueue"
18
+ PromptQueue.__index = PromptQueue
19
+
20
+ --[=[
21
+ Constructs a new prompt queue
22
+ @return PromptQueue
23
+ ]=]
24
+ function PromptQueue.new()
25
+ local self = setmetatable(BaseObject.new(), PromptQueue)
26
+
27
+ self._isShowing = self._maid:Add(ValueObject.new(false, "boolean"))
28
+ self._clearRequested = self._maid:Add(Signal.new())
29
+
30
+ self._queue = {}
31
+ self._currentProcessingEntry = nil
32
+
33
+ return self
34
+ end
35
+
36
+ --[=[
37
+ Queues a transition model to be shown
38
+
39
+ @param transitionModel TransitionModel
40
+ ]=]
41
+ function PromptQueue:Queue(transitionModel)
42
+ assert(TransitionModel.isTransitionModel(transitionModel), "Bad transitionModel")
43
+
44
+ local maid = Maid.new()
45
+ local promise = maid:Add(Promise.new())
46
+
47
+ local isCancelling = false
48
+
49
+ local entry = {
50
+ promise = promise;
51
+ execute = function()
52
+ assert(promise:IsPending(), "Not pending")
53
+
54
+ maid:GivePromise(transitionModel:PromiseShow())
55
+ :Then(function()
56
+ if transitionModel.PromiseSustain then
57
+ return maid:GivePromise(transitionModel:PromiseSustain())
58
+ end
59
+ end)
60
+ :Then(function()
61
+ return maid:GivePromise(transitionModel:PromiseHide())
62
+ end)
63
+ :Then(function()
64
+ promise:Resolve()
65
+ end)
66
+ :Catch(function(...)
67
+ if promise:IsPending() then
68
+ return
69
+ end
70
+
71
+ if isCancelling then
72
+ return
73
+ end
74
+
75
+ warn(string.format("[PromptQueue] - Failed to execute due to %q", tostring(... or nil)))
76
+ return Promise.rejected(...)
77
+ end)
78
+ end;
79
+ cancel = function(doNotAnimate)
80
+ assert(promise:IsPending(), "Not pending")
81
+ if isCancelling then
82
+ return
83
+ end
84
+
85
+ isCancelling = true
86
+
87
+ maid:GivePromise(transitionModel:PromiseHide(doNotAnimate))
88
+ :Then(function()
89
+ promise:Resolve()
90
+ end)
91
+ :Catch(function(...)
92
+ promise:Reject(...)
93
+
94
+ if select("#", ...) > 0 then
95
+ warn(string.format("[PromptQueue] - Failed to cancel due to %q", tostring(... or nil)))
96
+ end
97
+
98
+ return Promise.rejected(...)
99
+ end)
100
+ end;
101
+ }
102
+
103
+ table.insert(self._queue, entry)
104
+
105
+
106
+ maid:GiveTask(self._clearRequested:Connect(function(doNotAnimate)
107
+ entry.cancel(doNotAnimate)
108
+ end))
109
+
110
+ promise:Finally(function()
111
+ self._maid[maid] = nil
112
+ end)
113
+ maid:GiveTask(function()
114
+ if self._currentProcessingEntry == entry then
115
+ self._currentProcessingEntry = nil
116
+ end
117
+
118
+ local index = table.find(self._queue, entry)
119
+ if index then
120
+ table.remove(self._queue, index)
121
+ end
122
+
123
+ self._maid[maid] = nil
124
+ end)
125
+
126
+ self._maid[maid] = maid
127
+
128
+ self:_startQueueProcessing()
129
+
130
+ return promise
131
+ end
132
+
133
+ --[=[
134
+ Returns if the queue has any items
135
+
136
+ @return boolean
137
+ ]=]
138
+ function PromptQueue:HasItems()
139
+ return #self._queue > 0
140
+ end
141
+
142
+ --[=[
143
+ Clears the current queue
144
+
145
+ @param doNotAnimate boolean?
146
+ ]=]
147
+ function PromptQueue:Clear(doNotAnimate)
148
+ self._clearRequested:Fire(doNotAnimate)
149
+ end
150
+
151
+ --[=[
152
+ Promises the current prompt to be hidden
153
+
154
+ @param doNotAnimate boolean?
155
+ @return Promise
156
+ ]=]
157
+ function PromptQueue:HideCurrent(doNotAnimate)
158
+ if self._currentProcessingEntry then
159
+ local promise = self._currentProcessingEntry.promise
160
+
161
+ self._currentProcessingEntry.cancel(doNotAnimate)
162
+
163
+ return promise
164
+ else
165
+ return Promise.resolved()
166
+ end
167
+ end
168
+
169
+ function PromptQueue:_startQueueProcessing()
170
+ if self._maid._processing then
171
+ return
172
+ end
173
+
174
+ self._maid._processing = task.spawn(function()
175
+ self._isShowing.Value = true
176
+
177
+ local current = table.remove(self._queue, 1)
178
+ while current do
179
+ self._currentProcessingEntry = current
180
+
181
+ current.execute()
182
+ current.promise:Yield()
183
+
184
+ if self._currentProcessingEntry == current then
185
+ self._currentProcessingEntry = nil
186
+ end
187
+
188
+ -- Otherwise we have an issue where we process stuff that should have been already removed...?
189
+ task.wait(0.05)
190
+
191
+ current = table.remove(self._queue, 1)
192
+ end
193
+
194
+ self._isShowing.Value = false
195
+ self._maid._processing = nil
196
+ end)
197
+ end
198
+
199
+ return PromptQueue
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "node_modules",
3
+ "globIgnorePaths": [ "**/.package-lock.json" ],
4
+ "tree": {
5
+ "$path": { "optional": "../node_modules" }
6
+ }
7
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "PromptQueueTest",
3
+ "globIgnorePaths": [ "**/.package-lock.json" ],
4
+ "tree": {
5
+ "$className": "DataModel",
6
+ "ServerScriptService": {
7
+ "promptqueue": {
8
+ "$path": ".."
9
+ }
10
+ }
11
+ }
12
+ }