@quenty/loader 10.0.0 → 10.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 +8 -0
- package/default.project.json +1 -1
- package/package.json +2 -2
- package/src/LoaderUtils.lua +2 -235
- package/src/Utils.lua +1 -1
- package/src/init.lua +154 -103
- package/src/BounceTemplate.lua +0 -17
- package/src/BounceTemplateUtils.lua +0 -66
- package/src/GroupInfoUtils.lua +0 -167
- package/src/LegacyLoader.lua +0 -131
- package/src/Loader.lua +0 -52
- package/src/LoaderConstants.lua +0 -12
- package/src/PackageInfoUtils.lua +0 -232
- package/src/Queue.lua +0 -109
- package/src/ScriptInfoUtils.lua +0 -153
- package/src/StaticLegacyLoader.lua +0 -211
- package/src2/LoaderUtils.lua +0 -3
- package/src2/Utils.lua +0 -106
- package/src2/init.lua +0 -171
- /package/{src2 → src}/Dependencies/DependencyUtils.lua +0 -0
- /package/{src2 → src}/Dependencies/PackageTracker.lua +0 -0
- /package/{src2 → src}/Dependencies/PackageTrackerProvider.lua +0 -0
- /package/{src2 → src}/LoaderLink/LoaderLink.lua +0 -0
- /package/{src2 → src}/LoaderLink/LoaderLinkCreator.lua +0 -0
- /package/{src2 → src}/LoaderLink/LoaderLinkUtils.lua +0 -0
- /package/{src2 → src}/Maid.lua +0 -0
- /package/{src2 → src}/Replication/ReplicationType.lua +0 -0
- /package/{src2 → src}/Replication/ReplicationTypeUtils.lua +0 -0
- /package/{src2 → src}/Replication/Replicator.lua +0 -0
- /package/{src2 → src}/Replication/ReplicatorReferences.lua +0 -0
- /package/{src2 → src}/Replication/ReplicatorUtils.lua +0 -0
package/src/ScriptInfoUtils.lua
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
--[=[
|
|
2
|
-
@private
|
|
3
|
-
@class ScriptInfoUtils
|
|
4
|
-
]=]
|
|
5
|
-
|
|
6
|
-
local CollectionService = game:GetService("CollectionService")
|
|
7
|
-
|
|
8
|
-
local loader = script.Parent
|
|
9
|
-
local Utils = require(script.Parent.Utils)
|
|
10
|
-
local BounceTemplateUtils = require(script.Parent.BounceTemplateUtils)
|
|
11
|
-
|
|
12
|
-
local ScriptInfoUtils = {}
|
|
13
|
-
|
|
14
|
-
ScriptInfoUtils.DEPENDENCY_FOLDER_NAME = "node_modules";
|
|
15
|
-
ScriptInfoUtils.ModuleReplicationTypes = Utils.readonly({
|
|
16
|
-
CLIENT = "client";
|
|
17
|
-
SERVER = "server";
|
|
18
|
-
SHARED = "shared";
|
|
19
|
-
IGNORE = "ignore";
|
|
20
|
-
PLUGIN = "plugin";
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
function ScriptInfoUtils.createScriptInfo(instance, name, replicationMode)
|
|
24
|
-
assert(typeof(instance) == "Instance", "Bad instance")
|
|
25
|
-
assert(type(name) == "string", "Bad name")
|
|
26
|
-
assert(type(replicationMode) == "string", "Bad replicationMode")
|
|
27
|
-
|
|
28
|
-
return Utils.readonly({
|
|
29
|
-
name = name;
|
|
30
|
-
replicationMode = replicationMode;
|
|
31
|
-
instance = instance;
|
|
32
|
-
})
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
function ScriptInfoUtils.createScriptInfoLookup()
|
|
36
|
-
-- Server/client also contain shared entries
|
|
37
|
-
return Utils.readonly({
|
|
38
|
-
[ScriptInfoUtils.ModuleReplicationTypes.SERVER] = {}; -- [string name] = scriptInfo
|
|
39
|
-
[ScriptInfoUtils.ModuleReplicationTypes.CLIENT] = {};
|
|
40
|
-
[ScriptInfoUtils.ModuleReplicationTypes.SHARED] = {};
|
|
41
|
-
[ScriptInfoUtils.ModuleReplicationTypes.PLUGIN] = {};
|
|
42
|
-
})
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
function ScriptInfoUtils.getScriptInfoLookupForMode(scriptInfoLookup, replicationMode)
|
|
46
|
-
assert(type(scriptInfoLookup) == "table", "Bad scriptInfoLookup")
|
|
47
|
-
assert(type(replicationMode) == "string", "Bad replicationMode")
|
|
48
|
-
|
|
49
|
-
return scriptInfoLookup[replicationMode]
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
function ScriptInfoUtils.populateScriptInfoLookup(instance, scriptInfoLookup, lastReplicationMode)
|
|
53
|
-
assert(typeof(instance) == "Instance", "Bad instance")
|
|
54
|
-
assert(type(scriptInfoLookup) == "table", "Bad scriptInfoLookup")
|
|
55
|
-
assert(type(lastReplicationMode) == "string", "Bad lastReplicationMode")
|
|
56
|
-
|
|
57
|
-
if instance:IsA("Folder") or instance:IsA("Camera") then
|
|
58
|
-
local replicationMode = ScriptInfoUtils.getFolderReplicationMode(instance.Name, lastReplicationMode)
|
|
59
|
-
if replicationMode ~= ScriptInfoUtils.ModuleReplicationTypes.IGNORE then
|
|
60
|
-
for _, item in pairs(instance:GetChildren()) do
|
|
61
|
-
if not BounceTemplateUtils.isBounceTemplate(item) then
|
|
62
|
-
if item:IsA("Folder") or item:IsA("Camera") then
|
|
63
|
-
ScriptInfoUtils.populateScriptInfoLookup(item, scriptInfoLookup, replicationMode)
|
|
64
|
-
elseif item:IsA("ModuleScript") then
|
|
65
|
-
ScriptInfoUtils.addToInfoMap(scriptInfoLookup,
|
|
66
|
-
ScriptInfoUtils.createScriptInfo(item, item.Name, replicationMode))
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
elseif instance:IsA("ModuleScript") then
|
|
72
|
-
if not BounceTemplateUtils.isBounceTemplate(instance) then
|
|
73
|
-
if instance == loader then
|
|
74
|
-
-- STRICT hack to support this module script as "loader" over "Nevermore" in replicated scenario
|
|
75
|
-
ScriptInfoUtils.addToInfoMap(scriptInfoLookup,
|
|
76
|
-
ScriptInfoUtils.createScriptInfo(instance, "loader", lastReplicationMode))
|
|
77
|
-
else
|
|
78
|
-
ScriptInfoUtils.addToInfoMap(scriptInfoLookup,
|
|
79
|
-
ScriptInfoUtils.createScriptInfo(instance, instance.Name, lastReplicationMode))
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
elseif instance:IsA("ObjectValue") then
|
|
83
|
-
error("ObjectValue links are not supported at this time for retrieving inline module scripts")
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
local AVAILABLE_IN_SHARED = {
|
|
88
|
-
["IKService"] = true;
|
|
89
|
-
["IKServiceClient"] = true;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function ScriptInfoUtils.isAvailableInShared(scriptInfo)
|
|
93
|
-
if CollectionService:HasTag(scriptInfo.instance, "LinkToShared") then
|
|
94
|
-
return true
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
-- Hack because we can't tag things in Rojo yet
|
|
98
|
-
return AVAILABLE_IN_SHARED[scriptInfo.name]
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
function ScriptInfoUtils.addToInfoMap(scriptInfoLookup, scriptInfo)
|
|
102
|
-
assert(type(scriptInfoLookup) == "table", "Bad scriptInfoLookup")
|
|
103
|
-
assert(type(scriptInfo) == "table", "Bad scriptInfo")
|
|
104
|
-
|
|
105
|
-
local replicationMode = assert(scriptInfo.replicationMode, "Bad replicationMode")
|
|
106
|
-
local replicationMap = assert(scriptInfoLookup[replicationMode], "Bad replicationMode")
|
|
107
|
-
|
|
108
|
-
ScriptInfoUtils.addToInfoMapForMode(replicationMap, scriptInfo)
|
|
109
|
-
|
|
110
|
-
if replicationMode == ScriptInfoUtils.ModuleReplicationTypes.SHARED then
|
|
111
|
-
ScriptInfoUtils.addToInfoMapForMode(
|
|
112
|
-
scriptInfoLookup[ScriptInfoUtils.ModuleReplicationTypes.SERVER], scriptInfo)
|
|
113
|
-
ScriptInfoUtils.addToInfoMapForMode(
|
|
114
|
-
scriptInfoLookup[ScriptInfoUtils.ModuleReplicationTypes.CLIENT], scriptInfo)
|
|
115
|
-
elseif ScriptInfoUtils.isAvailableInShared(scriptInfo) then
|
|
116
|
-
ScriptInfoUtils.addToInfoMapForMode(
|
|
117
|
-
scriptInfoLookup[ScriptInfoUtils.ModuleReplicationTypes.SHARED], scriptInfo)
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
function ScriptInfoUtils.addToInfoMapForMode(replicationMap, scriptInfo)
|
|
122
|
-
if replicationMap[scriptInfo.name] then
|
|
123
|
-
warn(("Duplicate module %q in same package under same replication scope. Only using first one. \n- %q\n- %q")
|
|
124
|
-
:format(scriptInfo.name,
|
|
125
|
-
scriptInfo.instance:GetFullName(),
|
|
126
|
-
replicationMap[scriptInfo.name].instance:GetFullName()))
|
|
127
|
-
return
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
replicationMap[scriptInfo.name] = scriptInfo
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
function ScriptInfoUtils.getFolderReplicationMode(folderName, lastReplicationMode)
|
|
134
|
-
assert(type(folderName) == "string", "Bad folderName")
|
|
135
|
-
assert(type(lastReplicationMode) == "string", "Bad lastReplicationMode")
|
|
136
|
-
|
|
137
|
-
--Plugin always replicates further
|
|
138
|
-
if folderName == ScriptInfoUtils.DEPENDENCY_FOLDER_NAME then
|
|
139
|
-
return ScriptInfoUtils.ModuleReplicationTypes.IGNORE
|
|
140
|
-
elseif lastReplicationMode == ScriptInfoUtils.ModuleReplicationTypes.PLUGIN then
|
|
141
|
-
return lastReplicationMode
|
|
142
|
-
elseif folderName == "Shared" then
|
|
143
|
-
return ScriptInfoUtils.ModuleReplicationTypes.SHARED
|
|
144
|
-
elseif folderName == "Client" then
|
|
145
|
-
return ScriptInfoUtils.ModuleReplicationTypes.CLIENT
|
|
146
|
-
elseif folderName == "Server" then
|
|
147
|
-
return ScriptInfoUtils.ModuleReplicationTypes.SERVER
|
|
148
|
-
else
|
|
149
|
-
return lastReplicationMode
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
return ScriptInfoUtils
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
--[=[
|
|
2
|
-
@private
|
|
3
|
-
@class StaticLegacyLoader
|
|
4
|
-
]=]
|
|
5
|
-
|
|
6
|
-
local loader = script.Parent
|
|
7
|
-
local ScriptInfoUtils = require(script.Parent.ScriptInfoUtils)
|
|
8
|
-
local LoaderUtils = require(script.Parent.LoaderUtils)
|
|
9
|
-
local BounceTemplateUtils = require(script.Parent.BounceTemplateUtils)
|
|
10
|
-
|
|
11
|
-
local StaticLegacyLoader = {}
|
|
12
|
-
StaticLegacyLoader.ClassName = "StaticLegacyLoader"
|
|
13
|
-
StaticLegacyLoader.__index = StaticLegacyLoader
|
|
14
|
-
|
|
15
|
-
function StaticLegacyLoader.new()
|
|
16
|
-
local self = setmetatable({
|
|
17
|
-
_packageLookups = {};
|
|
18
|
-
}, StaticLegacyLoader)
|
|
19
|
-
|
|
20
|
-
return self
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
function StaticLegacyLoader:__call(value)
|
|
24
|
-
return self:Require(value)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
function StaticLegacyLoader:Lock()
|
|
28
|
-
error("Cannot start loader while not running")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
function StaticLegacyLoader:Require(root, value)
|
|
32
|
-
if type(value) == "number" then
|
|
33
|
-
return require(value)
|
|
34
|
-
elseif type(value) == "string" then
|
|
35
|
-
-- use very slow module recovery mechanism
|
|
36
|
-
local module = self:_findModule(root, value)
|
|
37
|
-
if module then
|
|
38
|
-
self:_ensureFakeLoader(module)
|
|
39
|
-
return require(module)
|
|
40
|
-
else
|
|
41
|
-
error("Error: Library '" .. tostring(value) .. "' does not exist.", 2)
|
|
42
|
-
end
|
|
43
|
-
elseif typeof(value) == "Instance" and value:IsA("ModuleScript") then
|
|
44
|
-
return require(value)
|
|
45
|
-
else
|
|
46
|
-
error(("Error: module must be a string or ModuleScript, got '%s' for '%s'")
|
|
47
|
-
:format(typeof(value), tostring(value)))
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
function StaticLegacyLoader:_findModule(root, name)
|
|
52
|
-
assert(typeof(root) == "Instance", "Bad root")
|
|
53
|
-
assert(type(name) == "string", "Bad name")
|
|
54
|
-
|
|
55
|
-
-- Implement the node_modules recursive find algorithm
|
|
56
|
-
local packageRoot = self:_findPackageRoot(root)
|
|
57
|
-
while packageRoot do
|
|
58
|
-
-- Build lookup
|
|
59
|
-
local highLevelLookup = self:_getOrCreateLookup(packageRoot)
|
|
60
|
-
if highLevelLookup[name] then
|
|
61
|
-
return highLevelLookup[name]
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
-- Ok, search our package dependencies
|
|
65
|
-
local dependencies = packageRoot:FindFirstChild(ScriptInfoUtils.DEPENDENCY_FOLDER_NAME)
|
|
66
|
-
if dependencies then
|
|
67
|
-
for _, instance in pairs(dependencies:GetChildren()) do
|
|
68
|
-
if instance:IsA("Folder") and instance.Name:sub(1, 1) == "@" then
|
|
69
|
-
for _, child in pairs(instance:GetChildren()) do
|
|
70
|
-
local lookup = self:_getPackageFolderLookup(child)
|
|
71
|
-
if lookup[name] then
|
|
72
|
-
return lookup[name]
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
else
|
|
76
|
-
local lookup = self:_getPackageFolderLookup(instance)
|
|
77
|
-
if lookup[name] then
|
|
78
|
-
return lookup[name]
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
-- We failed to find anything... search up a level...
|
|
85
|
-
packageRoot = self:_findPackageRoot(packageRoot)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
return nil
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
function StaticLegacyLoader:GetLoader(moduleScript)
|
|
92
|
-
assert(typeof(moduleScript) == "Instance", "Bad moduleScript")
|
|
93
|
-
|
|
94
|
-
return setmetatable({}, {
|
|
95
|
-
__call = function(_self, value)
|
|
96
|
-
return self:Require(moduleScript, value)
|
|
97
|
-
end;
|
|
98
|
-
__index = function(_self, key)
|
|
99
|
-
return self:Require(moduleScript, key)
|
|
100
|
-
end;
|
|
101
|
-
})
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
function StaticLegacyLoader:_getPackageFolderLookup(instance)
|
|
105
|
-
if instance:IsA("ObjectValue") then
|
|
106
|
-
if instance.Value then
|
|
107
|
-
return self:_getOrCreateLookup(instance.Value)
|
|
108
|
-
else
|
|
109
|
-
warn("[StaticLegacyLoader] - Bad link in packageFolder")
|
|
110
|
-
return {}
|
|
111
|
-
end
|
|
112
|
-
elseif instance:IsA("Folder") or instance:IsA("Camera") then
|
|
113
|
-
return self:_getOrCreateLookup(instance)
|
|
114
|
-
elseif instance:IsA("ModuleScript") then
|
|
115
|
-
return self:_getOrCreateLookup(instance)
|
|
116
|
-
else
|
|
117
|
-
warn(("Unknown instance %q (%s) in dependencyFolder - %q")
|
|
118
|
-
:format(instance.Name, instance.ClassName, instance:GetFullName()))
|
|
119
|
-
return {}
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
function StaticLegacyLoader:_getOrCreateLookup(packageFolderOrModuleScript)
|
|
124
|
-
assert(typeof(packageFolderOrModuleScript) == "Instance", "Bad packageFolderOrModuleScript")
|
|
125
|
-
|
|
126
|
-
if self._packageLookups[packageFolderOrModuleScript] then
|
|
127
|
-
return self._packageLookups[packageFolderOrModuleScript]
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
local lookup = {}
|
|
131
|
-
|
|
132
|
-
self:_buildLookup(lookup, packageFolderOrModuleScript)
|
|
133
|
-
|
|
134
|
-
self._packageLookups[packageFolderOrModuleScript] = lookup
|
|
135
|
-
return lookup
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
function StaticLegacyLoader:_buildLookup(lookup, instance)
|
|
139
|
-
if instance:IsA("Folder") or instance:IsA("Camera") then
|
|
140
|
-
if instance.Name ~= ScriptInfoUtils.DEPENDENCY_FOLDER_NAME then
|
|
141
|
-
for _, item in pairs(instance:GetChildren()) do
|
|
142
|
-
self:_buildLookup(lookup, item)
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
elseif instance:IsA("ModuleScript") then
|
|
146
|
-
lookup[instance.Name] = instance
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
function StaticLegacyLoader:_findPackageRoot(instance)
|
|
151
|
-
assert(typeof(instance) == "Instance", "Bad instance")
|
|
152
|
-
|
|
153
|
-
local current = instance.Parent
|
|
154
|
-
|
|
155
|
-
while current and current ~= game do
|
|
156
|
-
if LoaderUtils.isPackage(current) then
|
|
157
|
-
return current
|
|
158
|
-
elseif self:_couldBePackageRootTopLevel(current) then
|
|
159
|
-
return current
|
|
160
|
-
else
|
|
161
|
-
current = current.Parent
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
return nil
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
function StaticLegacyLoader:_couldBePackageRootTopLevel(current)
|
|
169
|
-
for _, instance in pairs(current:GetChildren()) do
|
|
170
|
-
if instance:IsA("Folder") and instance.Name:sub(1, 1) == "@" then
|
|
171
|
-
for _, item in pairs(instance:GetChildren()) do
|
|
172
|
-
if LoaderUtils.isPackage(item) then
|
|
173
|
-
return true
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
return true
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
function StaticLegacyLoader:_ensureFakeLoader(module)
|
|
183
|
-
assert(typeof(module) == "Instance", "Bad module")
|
|
184
|
-
|
|
185
|
-
local parent = module.Parent
|
|
186
|
-
if not parent then
|
|
187
|
-
warn("[StaticLegacyLoader] - No parent")
|
|
188
|
-
return
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
-- NexusUnitTest
|
|
192
|
-
-- luacheck: ignore
|
|
193
|
-
-- selene: allow(undefined_variable)
|
|
194
|
-
local shouldBeArchivable = Load and true or false
|
|
195
|
-
|
|
196
|
-
-- Already have link
|
|
197
|
-
local found = parent:FindFirstChild("loader")
|
|
198
|
-
if found then
|
|
199
|
-
if BounceTemplateUtils.isBounceTemplate(found) then
|
|
200
|
-
found.Archivable = shouldBeArchivable
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
return
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
local link = BounceTemplateUtils.create(loader, "loader")
|
|
207
|
-
link.Archivable = shouldBeArchivable
|
|
208
|
-
link.Parent = parent
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
return StaticLegacyLoader
|
package/src2/LoaderUtils.lua
DELETED
package/src2/Utils.lua
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
--[=[
|
|
2
|
-
@private
|
|
3
|
-
@class Utils
|
|
4
|
-
]=]
|
|
5
|
-
|
|
6
|
-
local Utils = {}
|
|
7
|
-
|
|
8
|
-
local function errorOnIndex(_, index)
|
|
9
|
-
error(string.format("Bad index %q", tostring(index)), 2)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
local READ_ONLY_METATABLE = {
|
|
13
|
-
__index = errorOnIndex;
|
|
14
|
-
__newindex = errorOnIndex;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function Utils.readonly(_table)
|
|
18
|
-
return setmetatable(_table, READ_ONLY_METATABLE)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
function Utils.count(_table)
|
|
22
|
-
local count = 0
|
|
23
|
-
for _, _ in pairs(_table) do
|
|
24
|
-
count = count + 1
|
|
25
|
-
end
|
|
26
|
-
return count
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
function Utils.getOrCreateValue(parent, instanceType, name, defaultValue)
|
|
30
|
-
assert(typeof(parent) == "Instance", "Bad argument 'parent'")
|
|
31
|
-
assert(type(instanceType) == "string", "Bad argument 'instanceType'")
|
|
32
|
-
assert(type(name) == "string", "Bad argument 'name'")
|
|
33
|
-
|
|
34
|
-
local foundChild = parent:FindFirstChild(name)
|
|
35
|
-
if foundChild then
|
|
36
|
-
if not foundChild:IsA(instanceType) then
|
|
37
|
-
warn(("[Utils.getOrCreateValue] - Value of type %q of name %q is of type %q in %s instead")
|
|
38
|
-
:format(instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
return foundChild
|
|
42
|
-
else
|
|
43
|
-
local newChild = Instance.new(instanceType)
|
|
44
|
-
newChild.Name = name
|
|
45
|
-
newChild.Value = defaultValue
|
|
46
|
-
newChild.Parent = parent
|
|
47
|
-
|
|
48
|
-
return newChild
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
function Utils.getValue(parent, instanceType, name, default)
|
|
53
|
-
assert(typeof(parent) == "Instance", "Bad argument 'parent'")
|
|
54
|
-
assert(type(instanceType) == "string", "Bad argument 'instanceType'")
|
|
55
|
-
assert(type(name) == "string", "Bad argument 'name'")
|
|
56
|
-
|
|
57
|
-
local foundChild = parent:FindFirstChild(name)
|
|
58
|
-
if foundChild then
|
|
59
|
-
if foundChild:IsA(instanceType) then
|
|
60
|
-
return foundChild.Value
|
|
61
|
-
else
|
|
62
|
-
warn(("[Utils.getValue] - Value of type %q of name %q is of type %q in %s instead")
|
|
63
|
-
:format(instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
|
|
64
|
-
return nil
|
|
65
|
-
end
|
|
66
|
-
else
|
|
67
|
-
return default
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
function Utils.setValue(parent, instanceType, name, value)
|
|
72
|
-
assert(typeof(parent) == "Instance", "Bad argument 'parent'")
|
|
73
|
-
assert(type(instanceType) == "string", "Bad argument 'instanceType'")
|
|
74
|
-
assert(type(name) == "string", "Bad argument 'name'")
|
|
75
|
-
|
|
76
|
-
local foundChild = parent:FindFirstChild(name)
|
|
77
|
-
if foundChild then
|
|
78
|
-
if not foundChild:IsA(instanceType) then
|
|
79
|
-
warn(("[Utils.setValue] - Value of type %q of name %q is of type %q in %s instead")
|
|
80
|
-
:format(instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
foundChild.Value = value
|
|
84
|
-
else
|
|
85
|
-
local newChild = Instance.new(instanceType)
|
|
86
|
-
newChild.Name = name
|
|
87
|
-
newChild.Value = value
|
|
88
|
-
newChild.Parent = parent
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
function Utils.getOrCreateFolder(parent, folderName)
|
|
94
|
-
local found = parent:FindFirstChild(folderName)
|
|
95
|
-
if found then
|
|
96
|
-
return found
|
|
97
|
-
else
|
|
98
|
-
local folder = Instance.new("Folder")
|
|
99
|
-
folder.Name = folderName
|
|
100
|
-
folder.Parent = parent
|
|
101
|
-
return folder
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return Utils
|
package/src2/init.lua
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
--[=[
|
|
2
|
-
Primary loader which handles bootstrapping different scenarios quickly
|
|
3
|
-
|
|
4
|
-
@class loader
|
|
5
|
-
]=]
|
|
6
|
-
|
|
7
|
-
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
8
|
-
local RunService = game:GetService("RunService")
|
|
9
|
-
|
|
10
|
-
local DependencyUtils = require(script.Dependencies.DependencyUtils)
|
|
11
|
-
local LoaderLinkCreator = require(script.LoaderLink.LoaderLinkCreator)
|
|
12
|
-
local LoaderLinkUtils = require(script.LoaderLink.LoaderLinkUtils)
|
|
13
|
-
local Maid = require(script.Maid)
|
|
14
|
-
local PackageTrackerProvider = require(script.Dependencies.PackageTrackerProvider)
|
|
15
|
-
local ReplicationType = require(script.Replication.ReplicationType)
|
|
16
|
-
local ReplicationTypeUtils = require(script.Replication.ReplicationTypeUtils)
|
|
17
|
-
local Replicator = require(script.Replication.Replicator)
|
|
18
|
-
local ReplicatorReferences = require(script.Replication.ReplicatorReferences)
|
|
19
|
-
|
|
20
|
-
local GLOBAL_PACKAGE_TRACKER = PackageTrackerProvider.new()
|
|
21
|
-
|
|
22
|
-
local Loader = {}
|
|
23
|
-
Loader.__index = Loader
|
|
24
|
-
Loader.ClassName = "Loader"
|
|
25
|
-
|
|
26
|
-
function Loader.new(packages, replicationType)
|
|
27
|
-
assert(typeof(packages) == "Instance", "Bad packages")
|
|
28
|
-
assert(ReplicationTypeUtils.isReplicationType(replicationType), "Bad replicationType")
|
|
29
|
-
|
|
30
|
-
local self = setmetatable({}, Loader)
|
|
31
|
-
|
|
32
|
-
self._maid = Maid.new()
|
|
33
|
-
|
|
34
|
-
self._replicationType = assert(replicationType, "No replicationType")
|
|
35
|
-
self._packages = assert(packages, "No packages")
|
|
36
|
-
|
|
37
|
-
return self
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
function Loader.bootstrapGame(packages)
|
|
41
|
-
assert(typeof(packages) == "Instance", "Bad packages")
|
|
42
|
-
|
|
43
|
-
local self = Loader.new(packages, ReplicationTypeUtils.inferReplicationType())
|
|
44
|
-
|
|
45
|
-
if self._replicationType == ReplicationType.SERVER then
|
|
46
|
-
self:_setupLoaderPopulation()
|
|
47
|
-
|
|
48
|
-
-- Trade off security for performance
|
|
49
|
-
if RunService:IsStudio() then
|
|
50
|
-
packages.Parent = ReplicatedStorage
|
|
51
|
-
else
|
|
52
|
-
self:_setupClientReplication()
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
GLOBAL_PACKAGE_TRACKER:AddPackageRoot(packages)
|
|
57
|
-
|
|
58
|
-
return self
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
function Loader.bootstrapPlugin(packages)
|
|
62
|
-
assert(typeof(packages) == "Instance", "Bad packages")
|
|
63
|
-
|
|
64
|
-
local self = Loader.new(packages, ReplicationType.PLUGIN)
|
|
65
|
-
|
|
66
|
-
self:_setupLoaderPopulation()
|
|
67
|
-
|
|
68
|
-
GLOBAL_PACKAGE_TRACKER:AddPackageRoot(packages)
|
|
69
|
-
|
|
70
|
-
return self
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
function Loader.load(packagesOrModuleScript)
|
|
74
|
-
assert(typeof(packagesOrModuleScript) == "Instance", "Bad packagesOrModuleScript")
|
|
75
|
-
|
|
76
|
-
local self = Loader.new(packagesOrModuleScript, ReplicationTypeUtils.inferReplicationType())
|
|
77
|
-
|
|
78
|
-
return self
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
function Loader:__index(request)
|
|
82
|
-
if Loader[request] then
|
|
83
|
-
return Loader[request]
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
return self:_findDependency(request)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
function Loader:__call(request)
|
|
90
|
-
if type(request) == "string" then
|
|
91
|
-
local module = self:_findDependency(request)
|
|
92
|
-
return require(module)
|
|
93
|
-
else
|
|
94
|
-
return require(request)
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
function Loader:_findDependency(request)
|
|
99
|
-
assert(type(request) == "string", "Bad request")
|
|
100
|
-
|
|
101
|
-
local packageTracker = GLOBAL_PACKAGE_TRACKER:FindPackageTracker(self._packages)
|
|
102
|
-
if packageTracker then
|
|
103
|
-
local foundDependency = packageTracker:ResolveDependency(request, self._replicationType)
|
|
104
|
-
if foundDependency then
|
|
105
|
-
return foundDependency
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
-- Otherwise let's fail with an error acknowledging that the module exists
|
|
109
|
-
if self._replicationType == ReplicationType.SERVER or self._replicationType == ReplicationType.SHARED then
|
|
110
|
-
local foundClientDependency = packageTracker:ResolveDependency(request, ReplicationType.CLIENT)
|
|
111
|
-
if foundClientDependency then
|
|
112
|
-
error(string.format("[Loader] - %q is only available on the client", foundClientDependency.Name))
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
if self._replicationType == ReplicationType.CLIENT or self._replicationType == ReplicationType.SHARED then
|
|
117
|
-
local foundServerDependency = packageTracker:ResolveDependency(request, ReplicationType.SERVER)
|
|
118
|
-
if foundServerDependency then
|
|
119
|
-
error(string.format("[Loader] - %q is only available on the server", foundServerDependency.Name))
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
-- Just standard dependency search
|
|
125
|
-
local foundBackup = DependencyUtils.findDependency(self._packages, request, self._replicationType)
|
|
126
|
-
if foundBackup then
|
|
127
|
-
if RunService:IsRunning() then
|
|
128
|
-
warn(string.format("[Loader] - Failed to find package %q in package tracker", request))
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
-- Ensure hoarcekat story has a link to use
|
|
132
|
-
-- TODO: Maybe add to global package cache instead...
|
|
133
|
-
local parent = foundBackup.Parent
|
|
134
|
-
if parent and not parent:FindFirstChild("loader") then
|
|
135
|
-
local link = LoaderLinkUtils.create(script, "loader")
|
|
136
|
-
link.Parent = parent
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
return foundBackup
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
-- TODO: Track location and provider install command
|
|
143
|
-
error(string.format("[Loader] - %q is not available. Please make this module or install it to the package requiring it.", request))
|
|
144
|
-
return nil
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
function Loader:_setupClientReplication()
|
|
148
|
-
local copy = self._maid:Add(Instance.new("Folder"))
|
|
149
|
-
copy.Name = self._packages.Name
|
|
150
|
-
|
|
151
|
-
local references = ReplicatorReferences.new()
|
|
152
|
-
|
|
153
|
-
local replicator = self._maid:Add(Replicator.new(references))
|
|
154
|
-
replicator:SetTarget(copy)
|
|
155
|
-
replicator:ReplicateFrom(self._packages)
|
|
156
|
-
|
|
157
|
-
self._maid:Add(LoaderLinkCreator.new(copy, references, true))
|
|
158
|
-
|
|
159
|
-
copy.Parent = ReplicatedStorage
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
function Loader:_setupLoaderPopulation()
|
|
163
|
-
self._maid:Add(LoaderLinkCreator.new(self._packages, nil, true))
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
function Loader:Destroy()
|
|
167
|
-
self._maid:DoCleaning()
|
|
168
|
-
setmetatable(self, nil)
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
return Loader
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{src2 → src}/Maid.lua
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|