@quenty/templateprovider 4.0.0-canary.236.5597d0a.0 → 4.1.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 +60 -1
- package/README.md +5 -3
- package/package.json +8 -8
- package/src/Shared/ModuleProvider.lua +11 -2
- package/src/Shared/ModuleProviderFakeLoader.lua +16 -0
- package/src/Shared/TaggedTemplateProvider.lua +4 -3
- package/src/Shared/TemplateContainerUtils.lua +4 -3
- package/src/Shared/TemplateProvider.lua +92 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,66 @@
|
|
|
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
|
-
# [4.
|
|
6
|
+
# [4.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/templateprovider@4.0.0...@quenty/templateprovider@4.1.0) (2022-03-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Make ModuleProvider work with loader ([97361ba](https://github.com/Quenty/NevermoreEngine/commit/97361ba14b02f4a911846147980d3099a028ddc4))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [4.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/templateprovider@3.8.0...@quenty/templateprovider@4.0.0) (2022-03-06)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @quenty/templateprovider
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [3.8.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/templateprovider@3.7.1...@quenty/templateprovider@3.8.0) (2022-01-17)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package @quenty/templateprovider
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## [3.7.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/templateprovider@3.7.0...@quenty/templateprovider@3.7.1) (2022-01-16)
|
|
34
|
+
|
|
35
|
+
**Note:** Version bump only for package @quenty/templateprovider
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# [3.7.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/templateprovider@3.6.0...@quenty/templateprovider@3.7.0) (2022-01-07)
|
|
42
|
+
|
|
43
|
+
**Note:** Version bump only for package @quenty/templateprovider
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# [3.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/templateprovider@3.5.1...@quenty/templateprovider@3.6.0) (2022-01-03)
|
|
50
|
+
|
|
51
|
+
**Note:** Version bump only for package @quenty/templateprovider
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## [3.5.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/templateprovider@3.5.0...@quenty/templateprovider@3.5.1) (2021-12-30)
|
|
58
|
+
|
|
59
|
+
**Note:** Version bump only for package @quenty/templateprovider
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# [3.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/templateprovider@3.4.0...@quenty/templateprovider@3.5.0) (2021-12-18)
|
|
7
66
|
|
|
8
67
|
**Note:** Version bump only for package @quenty/templateprovider
|
|
9
68
|
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
## TemplateProvider
|
|
2
2
|
<div align="center">
|
|
3
|
-
<a href="http://quenty.github.io/
|
|
4
|
-
<img src="https://
|
|
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/
|
|
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,6 +13,8 @@
|
|
|
13
13
|
|
|
14
14
|
Base of a template retrieval system
|
|
15
15
|
|
|
16
|
+
<div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/TemplateProvider">View docs →</a></div>
|
|
17
|
+
|
|
16
18
|
## Installation
|
|
17
19
|
```
|
|
18
20
|
npm install @quenty/templateprovider --save
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/templateprovider",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Base of a template retrieval system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/baseobject": "
|
|
29
|
-
"@quenty/insertserviceutils": "4.
|
|
30
|
-
"@quenty/loader": "
|
|
31
|
-
"@quenty/maid": "2.0
|
|
32
|
-
"@quenty/promise": "4.
|
|
33
|
-
"@quenty/string": "2.2.
|
|
28
|
+
"@quenty/baseobject": "^4.1.0",
|
|
29
|
+
"@quenty/insertserviceutils": "^4.1.0",
|
|
30
|
+
"@quenty/loader": "^4.0.0",
|
|
31
|
+
"@quenty/maid": "^2.2.0",
|
|
32
|
+
"@quenty/promise": "^4.1.0",
|
|
33
|
+
"@quenty/string": "^2.2.1"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "0797de955876b050fb24875de0423453e268b2ce"
|
|
39
39
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Creates a service that provides modules from a parent module, either by name, or by list!
|
|
3
|
+
@class ModuleProvider
|
|
4
|
+
]=]
|
|
3
5
|
|
|
4
6
|
local ModuleProvider = {}
|
|
5
7
|
ModuleProvider.ClassName = "ModuleProvider"
|
|
@@ -73,6 +75,13 @@ function ModuleProvider:_addToRegistery(moduleScript)
|
|
|
73
75
|
:format(moduleScript.Name))
|
|
74
76
|
end
|
|
75
77
|
|
|
78
|
+
if not moduleScript.Parent:FindFirstChild("loader") then
|
|
79
|
+
local fakeLoader = script.Parent.ModuleProviderFakeLoader:Clone()
|
|
80
|
+
fakeLoader.Name = "loader"
|
|
81
|
+
fakeLoader.Archivable = false
|
|
82
|
+
fakeLoader.Parent = moduleScript.Parent
|
|
83
|
+
end
|
|
84
|
+
|
|
76
85
|
local _module
|
|
77
86
|
xpcall(function()
|
|
78
87
|
_module = require(moduleScript)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
Creates a service that provides modules from a parent module, either by name, or by list!
|
|
3
|
+
@class ModuleProviderFakeLoader
|
|
4
|
+
]=]
|
|
5
|
+
|
|
6
|
+
local function load(script)
|
|
7
|
+
local moduleProvider = script:FindFirstAncestorWhichIsA("ModuleScript")
|
|
8
|
+
assert(moduleProvider, "No moduleProvider")
|
|
9
|
+
|
|
10
|
+
local loader = require(moduleProvider.Parent.loader)
|
|
11
|
+
return loader.load(moduleProvider)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
load = load
|
|
16
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Like a template provider, but it also reparents and retrieves tagged objects
|
|
3
|
+
@class TaggedTemplateProvider
|
|
4
|
+
]=]
|
|
4
5
|
|
|
5
6
|
local require = require(script.Parent.loader).load(script)
|
|
6
7
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Utility functions for the TemplateProvider
|
|
3
|
+
@class TemplateContainerUtils
|
|
4
|
+
]=]
|
|
4
5
|
|
|
5
6
|
local Workspace = game:GetService("Workspace")
|
|
6
7
|
local RunService = game:GetService("RunService")
|
|
@@ -1,5 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Base of a template retrieval system. Templates can be retrieved from Roblox, or from the cloud,
|
|
3
|
+
and then retrieved by name. Folders are ignored, so assets may be organized however you want.
|
|
4
|
+
|
|
5
|
+
Templates can repliate to client if desired.
|
|
6
|
+
|
|
7
|
+
```lua
|
|
8
|
+
-- shared/Templates.lua
|
|
9
|
+
|
|
10
|
+
return TemplateProvider.new(182451181, script) -- Load from Roblox cloud
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```lua
|
|
14
|
+
-- Server
|
|
15
|
+
local serviceBag = ServiceBag.new()
|
|
16
|
+
local templates = serviceBag:GetService(packages.Templates)
|
|
17
|
+
serviceBag:Init()
|
|
18
|
+
serviceBag:Start()
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```lua
|
|
22
|
+
-- Client
|
|
23
|
+
local serviceBag = ServiceBag.new()
|
|
24
|
+
local templates = serviceBag:GetService(packages.Templates)
|
|
25
|
+
serviceBag:Init()
|
|
26
|
+
serviceBag:Start()
|
|
27
|
+
|
|
28
|
+
templates:PromiseClone("Crate"):Then(function(crate)
|
|
29
|
+
print("Got crate from the cloud!")
|
|
30
|
+
end)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
@class TemplateProvider
|
|
34
|
+
]=]
|
|
3
35
|
|
|
4
36
|
local require = require(script.Parent.loader).load(script)
|
|
5
37
|
|
|
@@ -15,7 +47,11 @@ local TemplateProvider = {}
|
|
|
15
47
|
TemplateProvider.ClassName = "TemplateProvider"
|
|
16
48
|
TemplateProvider.__index = TemplateProvider
|
|
17
49
|
|
|
18
|
-
--
|
|
50
|
+
--[=[
|
|
51
|
+
Constructs a new [TemplateProvider].
|
|
52
|
+
@param container Instance | table | number -- Value
|
|
53
|
+
@param replicationParent Instance? -- Place to replicate instances to.
|
|
54
|
+
]=]
|
|
19
55
|
function TemplateProvider.new(container, replicationParent)
|
|
20
56
|
local self = setmetatable({}, TemplateProvider)
|
|
21
57
|
|
|
@@ -48,7 +84,9 @@ function TemplateProvider.new(container, replicationParent)
|
|
|
48
84
|
return self
|
|
49
85
|
end
|
|
50
86
|
|
|
51
|
-
--
|
|
87
|
+
--[=[
|
|
88
|
+
Initializes the container provider. Should be done via [ServiceBag].
|
|
89
|
+
]=]
|
|
52
90
|
function TemplateProvider:Init()
|
|
53
91
|
assert(not self._initialized, "Already initialized")
|
|
54
92
|
|
|
@@ -64,6 +102,11 @@ function TemplateProvider:Init()
|
|
|
64
102
|
end
|
|
65
103
|
end
|
|
66
104
|
|
|
105
|
+
--[=[
|
|
106
|
+
Promises to clone the template as soon as it exists.
|
|
107
|
+
@param templateName string
|
|
108
|
+
@return Promise<Instance>
|
|
109
|
+
]=]
|
|
67
110
|
function TemplateProvider:PromiseClone(templateName)
|
|
68
111
|
assert(type(templateName) == "string", "templateName must be a string")
|
|
69
112
|
|
|
@@ -84,7 +127,7 @@ function TemplateProvider:PromiseClone(templateName)
|
|
|
84
127
|
self._maid[promise] = nil
|
|
85
128
|
end)
|
|
86
129
|
|
|
87
|
-
delay(5, function()
|
|
130
|
+
task.delay(5, function()
|
|
88
131
|
if promise:IsPending() then
|
|
89
132
|
warn(("[TemplateProvider.PromiseClone] - May fail to replicate template %q from cloud. %s")
|
|
90
133
|
:format(templateName, self:_getReplicationHint()))
|
|
@@ -109,7 +152,16 @@ function TemplateProvider:_getReplicationHint()
|
|
|
109
152
|
return hint
|
|
110
153
|
end
|
|
111
154
|
|
|
112
|
-
--
|
|
155
|
+
--[=[
|
|
156
|
+
Clones the template.
|
|
157
|
+
|
|
158
|
+
:::info
|
|
159
|
+
If the template name has a prefix of "Template" then it will remove it on the cloned instance.
|
|
160
|
+
:::
|
|
161
|
+
|
|
162
|
+
@param templateName string
|
|
163
|
+
@return Instance?
|
|
164
|
+
]=]
|
|
113
165
|
function TemplateProvider:Clone(templateName)
|
|
114
166
|
assert(type(templateName) == "string", "templateName must be a string")
|
|
115
167
|
|
|
@@ -126,7 +178,12 @@ function TemplateProvider:Clone(templateName)
|
|
|
126
178
|
return newItem
|
|
127
179
|
end
|
|
128
180
|
|
|
129
|
-
--
|
|
181
|
+
--[=[
|
|
182
|
+
Returns the raw template
|
|
183
|
+
|
|
184
|
+
@param templateName string
|
|
185
|
+
@return Instance?
|
|
186
|
+
]=]
|
|
130
187
|
function TemplateProvider:Get(templateName)
|
|
131
188
|
assert(type(templateName) == "string", "templateName must be a string")
|
|
132
189
|
self:_verifyInit()
|
|
@@ -134,7 +191,11 @@ function TemplateProvider:Get(templateName)
|
|
|
134
191
|
return self._registry[templateName]
|
|
135
192
|
end
|
|
136
193
|
|
|
137
|
-
--
|
|
194
|
+
--[=[
|
|
195
|
+
Adds a new container to the provider for provision of assets.
|
|
196
|
+
|
|
197
|
+
@param container Instance | number
|
|
198
|
+
]=]
|
|
138
199
|
function TemplateProvider:AddContainer(container)
|
|
139
200
|
assert(typeof(container) == "Instance" or type(container) == "number", "Bad container")
|
|
140
201
|
self:_verifyInit()
|
|
@@ -151,6 +212,11 @@ function TemplateProvider:AddContainer(container)
|
|
|
151
212
|
end
|
|
152
213
|
end
|
|
153
214
|
|
|
215
|
+
--[=[
|
|
216
|
+
Removes a container from the provisioning set.
|
|
217
|
+
|
|
218
|
+
@param container Instance | number
|
|
219
|
+
]=]
|
|
154
220
|
function TemplateProvider:RemoveContainer(container)
|
|
155
221
|
assert(typeof(container) == "Instance", "Bad container")
|
|
156
222
|
self:_verifyInit()
|
|
@@ -159,7 +225,11 @@ function TemplateProvider:RemoveContainer(container)
|
|
|
159
225
|
self._maid[container] = nil
|
|
160
226
|
end
|
|
161
227
|
|
|
162
|
-
--
|
|
228
|
+
--[=[
|
|
229
|
+
Returns whether or not a template is registered at the time
|
|
230
|
+
@param templateName string
|
|
231
|
+
@return boolean
|
|
232
|
+
]=]
|
|
163
233
|
function TemplateProvider:IsAvailable(templateName)
|
|
164
234
|
assert(type(templateName) == "string", "templateName must be a string")
|
|
165
235
|
self:_verifyInit()
|
|
@@ -167,7 +237,11 @@ function TemplateProvider:IsAvailable(templateName)
|
|
|
167
237
|
return self._registry[templateName] ~= nil
|
|
168
238
|
end
|
|
169
239
|
|
|
170
|
-
--
|
|
240
|
+
--[=[
|
|
241
|
+
Returns all current registered items.
|
|
242
|
+
|
|
243
|
+
@return { Instance }
|
|
244
|
+
]=]
|
|
171
245
|
function TemplateProvider:GetAll()
|
|
172
246
|
self:_verifyInit()
|
|
173
247
|
|
|
@@ -179,7 +253,11 @@ function TemplateProvider:GetAll()
|
|
|
179
253
|
return list
|
|
180
254
|
end
|
|
181
255
|
|
|
182
|
-
--
|
|
256
|
+
--[=[
|
|
257
|
+
Gets all current the containers.
|
|
258
|
+
|
|
259
|
+
@return { Instance | number }
|
|
260
|
+
]=]
|
|
183
261
|
function TemplateProvider:GetContainers()
|
|
184
262
|
self:_verifyInit()
|
|
185
263
|
|
|
@@ -300,6 +378,9 @@ function TemplateProvider:_removeFromRegistry(child)
|
|
|
300
378
|
end
|
|
301
379
|
end
|
|
302
380
|
|
|
381
|
+
--[=[
|
|
382
|
+
Cleans up the provider
|
|
383
|
+
]=]
|
|
303
384
|
function TemplateProvider:Destroy()
|
|
304
385
|
self._maid:DoCleaning()
|
|
305
386
|
end
|