@quenty/transitionmodel 1.1.0-canary.67644c5.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.1.0-canary.67644c5.0 (2023-03-05)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add TransitionModel package ([67644c5](https://github.com/Quenty/NevermoreEngine/commit/67644c5978f4a895d352eb7394c9fcb50f9ec4d4))
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2014-2022 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
+ ## TransitionModel
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
+ Helps with Gui visiblity showing and hiding
16
+
17
+ <div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/TransitionModelUtils">View docs →</a></div>
18
+
19
+ ## Installation
20
+
21
+ ```
22
+ npm install @quenty/transitionmodel --save
23
+ ```
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "transitionmodel",
3
+ "tree": {
4
+ "$path": "src"
5
+ }
6
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@quenty/transitionmodel",
3
+ "version": "1.1.0-canary.67644c5.0",
4
+ "description": "Helps with Gui visiblity showing and hiding",
5
+ "keywords": [
6
+ "Roblox",
7
+ "Nevermore",
8
+ "Lua",
9
+ "transitionmodel"
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/transitionmodel/"
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": "6.2.0-canary.67644c5.0",
29
+ "@quenty/basicpane": "7.7.0-canary.67644c5.0",
30
+ "@quenty/blend": "6.10.0-canary.67644c5.0",
31
+ "@quenty/loader": "6.2.0-canary.67644c5.0",
32
+ "@quenty/maid": "2.5.0-canary.67644c5.0",
33
+ "@quenty/promise": "6.3.0-canary.67644c5.0",
34
+ "@quenty/signal": "2.3.0"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "gitHead": "67644c5978f4a895d352eb7394c9fcb50f9ec4d4"
40
+ }
@@ -0,0 +1,105 @@
1
+ --[=[
2
+ @class SpringTransitionModel
3
+ ]=]
4
+
5
+ local require = require(script.Parent.loader).load(script)
6
+
7
+ local BasicPane = require("BasicPane")
8
+ local TransitionModel = require("TransitionModel")
9
+ local SpringObject = require("SpringObject")
10
+ local Promise = require("Promise")
11
+ local Maid = require("Maid")
12
+
13
+ local SpringTransitionModel = setmetatable({}, BasicPane)
14
+ SpringTransitionModel.ClassName = "SpringTransitionModel"
15
+ SpringTransitionModel.__index = SpringTransitionModel
16
+
17
+ function SpringTransitionModel.new(showTarget, hideTarget)
18
+ local self = setmetatable(BasicPane.new(), SpringTransitionModel)
19
+
20
+ self._transitionModel = TransitionModel.new()
21
+ self._transitionModel:BindToPaneVisbility(self)
22
+ self._maid:GiveTask(self._transitionModel)
23
+
24
+ self._showTarget = showTarget or 1
25
+ if hideTarget then
26
+ self._hideTarget = hideTarget
27
+ else
28
+ self._hideTarget = 0*self._showTarget
29
+ end
30
+
31
+ self._springObject = SpringObject.new(self._hideTarget)
32
+ self._springObject.Speed = 30
33
+ self._maid:GiveTask(self._springObject)
34
+
35
+ self._transitionModel:SetPromiseShow(function(maid, doNotAnimate)
36
+ return self:_promiseShow(maid, doNotAnimate)
37
+ end)
38
+ self._transitionModel:SetPromiseHide(function(maid, doNotAnimate)
39
+ return self:_promiseHide(maid, doNotAnimate)
40
+ end)
41
+
42
+ return self
43
+ end
44
+
45
+ function SpringTransitionModel:BindToPaneVisbility(pane)
46
+ local maid = Maid.new()
47
+
48
+ maid:GiveTask(pane.VisibleChanged:Connect(function(isVisible, doNotAnimate)
49
+ self:SetVisible(isVisible, doNotAnimate)
50
+ end))
51
+
52
+ self:SetVisible(pane:IsVisible())
53
+
54
+ self._maid._visibleBinding = maid
55
+
56
+ return function()
57
+ if self._maid._visibleBinding == maid then
58
+ self._maid._visibleBinding = nil
59
+ end
60
+ end
61
+ end
62
+
63
+ function SpringTransitionModel:SetSpeed(speed)
64
+ self._springObject.Speed = speed
65
+ end
66
+
67
+ function SpringTransitionModel:SetDamper(damper)
68
+ self._springObject.Damper = damper
69
+ end
70
+
71
+ function SpringTransitionModel:ObserveRenderStepped()
72
+ return self._springObject:ObserveRenderStepped()
73
+ end
74
+
75
+ function SpringTransitionModel:PromiseShow(doNotAnimate)
76
+ return self._transitionModel:PromiseShow(doNotAnimate)
77
+ end
78
+
79
+ function SpringTransitionModel:PromiseHide(doNotAnimate)
80
+ return self._transitionModel:PromiseHide(doNotAnimate)
81
+ end
82
+
83
+ function SpringTransitionModel:PromiseToggle(doNotAnimate)
84
+ return self._transitionModel:PromiseToggle(doNotAnimate)
85
+ end
86
+
87
+ function SpringTransitionModel:_promiseShow(maid)
88
+ local promise = Promise.new()
89
+ maid:GiveTask(promise)
90
+
91
+ self._springObject.t = self._showTarget
92
+
93
+ return maid:GivePromise(self._springObject:PromiseFinished())
94
+ end
95
+
96
+ function SpringTransitionModel:_promiseHide(maid)
97
+ local promise = Promise.new()
98
+ maid:GiveTask(promise)
99
+
100
+ self._springObject.t = self._hideTarget
101
+
102
+ return maid:GivePromise(self._springObject:PromiseFinished())
103
+ end
104
+
105
+ return SpringTransitionModel
@@ -0,0 +1,201 @@
1
+ --[=[
2
+ This model deduplicates and handles transitions for showing, hiding, and
3
+ toggling.
4
+
5
+ @class TransitionModel
6
+ ]=]
7
+
8
+ local require = require(script.Parent.loader).load(script)
9
+
10
+ local BasicPane = require("BasicPane")
11
+ local Promise = require("Promise")
12
+ local Maid = require("Maid")
13
+
14
+ local TransitionModel = setmetatable({}, BasicPane)
15
+ TransitionModel.ClassName = "TransitionModel"
16
+ TransitionModel.__index = TransitionModel
17
+
18
+ function TransitionModel.new()
19
+ local self = setmetatable(BasicPane.new(), TransitionModel)
20
+
21
+ self._isShowingComplete = Instance.new("BoolValue")
22
+ self._isShowingComplete.Value = false
23
+ self._maid:GiveTask(self._isShowingComplete)
24
+
25
+ self._isHidingComplete = Instance.new("BoolValue")
26
+ self._isHidingComplete.Value = false
27
+ self._maid:GiveTask(self._isHidingComplete)
28
+
29
+ self._maid:GiveTask(self.VisibleChanged:Connect(function(visible, doNotAnimate)
30
+ if visible then
31
+ self:_executeShow(doNotAnimate)
32
+ else
33
+ self:_executeHide(doNotAnimate)
34
+ end
35
+ end))
36
+
37
+ return self
38
+ end
39
+
40
+ function TransitionModel:PromiseShow(doNotAnimate)
41
+ self:Show(doNotAnimate)
42
+
43
+ return self:_promiseIsShown()
44
+ end
45
+
46
+ function TransitionModel:PromiseHide(doNotAnimate)
47
+ self:Hide(doNotAnimate)
48
+
49
+ return self:_promiseIsHidden()
50
+ end
51
+
52
+ function TransitionModel:PromiseToggle(doNotAnimate)
53
+ if self:IsVisible() then
54
+ return self:PromiseShow(doNotAnimate)
55
+ else
56
+ return self:PromiseHide(doNotAnimate)
57
+ end
58
+ end
59
+
60
+ function TransitionModel:BindToPaneVisbility(pane)
61
+ local maid = Maid.new()
62
+
63
+ maid:GiveTask(pane.VisibleChanged:Connect(function(isVisible, doNotAnimate)
64
+ self:SetVisible(isVisible, doNotAnimate)
65
+ end))
66
+
67
+ self:SetVisible(pane:IsVisible())
68
+
69
+ self._maid._visibleBinding = maid
70
+
71
+ return function()
72
+ if self._maid._visibleBinding == maid then
73
+ self._maid._visibleBinding = nil
74
+ end
75
+ end
76
+ end
77
+
78
+ function TransitionModel:SetPromiseShow(showCallback)
79
+ assert(type(showCallback) == "function", "Bad showCallback")
80
+
81
+ self._showCallback = showCallback
82
+ end
83
+
84
+ function TransitionModel:SetPromiseHide(hideCallback)
85
+ assert(type(hideCallback) == "function", "Bad hideCallback")
86
+
87
+ self._hideCallback = hideCallback
88
+ end
89
+
90
+ function TransitionModel:_promiseIsShown()
91
+ if self._isShowingComplete.Value then
92
+ return Promise.resolved()
93
+ end
94
+
95
+ local promise = Promise.new()
96
+
97
+ local maid = Maid.new()
98
+ self._maid[promise] = maid
99
+
100
+ maid:GiveTask(self._isShowingComplete.Changed:Connect(function()
101
+ if self._isShowingComplete.Value then
102
+ promise:Resolve()
103
+ end
104
+ end))
105
+
106
+ maid:GiveTask(self.VisibleChanged:Connect(function(isVisible)
107
+ if not isVisible then
108
+ promise:Reject()
109
+ end
110
+ end))
111
+
112
+ promise:Finally(function()
113
+ self._maid[promise] = nil
114
+ end)
115
+
116
+ return promise
117
+ end
118
+
119
+ function TransitionModel:_promiseIsHidden()
120
+ if self._isHidingComplete.Value then
121
+ return Promise.resolved()
122
+ end
123
+
124
+ local promise = Promise.new()
125
+
126
+ local maid = Maid.new()
127
+ self._maid[promise] = maid
128
+
129
+ maid:GiveTask(self._isHidingComplete.Changed:Connect(function()
130
+ if self._isHidingComplete.Value then
131
+ promise:Resolve()
132
+ end
133
+ end))
134
+
135
+ maid:GiveTask(self.VisibleChanged:Connect(function(isVisible)
136
+ if isVisible then
137
+ promise:Reject()
138
+ end
139
+ end))
140
+
141
+ promise:Finally(function()
142
+ self._maid[promise] = nil
143
+ end)
144
+
145
+ return promise
146
+ end
147
+
148
+ function TransitionModel:_executeShow(doNotAnimate)
149
+ local maid = Maid.new()
150
+
151
+ local promise = Promise.new()
152
+ maid:GiveTask(promise)
153
+
154
+ self._isHidingComplete.Value = false
155
+ self._isShowingComplete.Value = false
156
+
157
+ if self._showCallback then
158
+ local result = self._showCallback(maid, doNotAnimate)
159
+ if Promise.isPromise(result) then
160
+ promise:Resolve(result)
161
+ else
162
+ promise:Reject()
163
+ error(string.format("[TransitionModel] - Expected promise to be returned from showCallback, got %q", tostring(result)))
164
+ end
165
+ end
166
+
167
+ promise:Then(function()
168
+ self._isShowingComplete.Value = true
169
+ end)
170
+
171
+ self._maid._transition = maid
172
+ end
173
+
174
+ function TransitionModel:_executeHide(doNotAnimate)
175
+ local maid = Maid.new()
176
+
177
+ self._isHidingComplete.Value = false
178
+ self._isShowingComplete.Value = false
179
+
180
+ local promise = Promise.new()
181
+ maid:GiveTask(promise)
182
+
183
+ if self._hideCallback then
184
+ local result = self._hideCallback(maid, doNotAnimate)
185
+ if Promise.isPromise(result) then
186
+ promise:Resolve(result)
187
+ else
188
+ promise:Reject()
189
+ error(string.format("[TransitionModel] - Expected promise to be returned from showCallback, got %q", tostring(result)))
190
+ end
191
+ end
192
+
193
+ promise:Then(function()
194
+ self._isHidingComplete.Value = true
195
+ end)
196
+
197
+ self._maid._transition = maid
198
+ end
199
+
200
+
201
+ return TransitionModel
@@ -0,0 +1,18 @@
1
+ --[=[
2
+ @class TransitionUtils
3
+ ]=]
4
+
5
+ local require = require(script.Parent.loader).load(script)
6
+
7
+ local BasicPane = require("BasicPane")
8
+
9
+ local TransitionUtils = {}
10
+
11
+ function TransitionUtils.isTransition(value)
12
+ return BasicPane.isBasicPane(value)
13
+ and type(value.PromiseShow) == "function"
14
+ and type(value.PromiseHide) == "function"
15
+ and type(value.PromiseToggle) == "function"
16
+ end
17
+
18
+ return TransitionUtils
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "node_modules",
3
+ "globIgnorePaths": [ "**/.package-lock.json" ],
4
+ "tree": {
5
+ "$path": { "optional": "../node_modules" }
6
+ }
7
+ }