This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.luau
43 lines (37 loc) · 1.63 KB
/
init.luau
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
local IS_SERVER = game:GetService("RunService"):IsServer()
local Comm = require(script.Parent.Comm)
local TableUtil = require(script.Parent.TableUtil)
Comm = if IS_SERVER then Comm.ServerComm else Comm.ClientComm
local RemoteComponentExtension = {}
function RemoteComponentExtension.Starting(component)
local objectInstance = component.Instance
local nameSpace = component.RemoteNamespace or component.Tag
if IS_SERVER then
if component.Client then
component.Client = TableUtil.Copy(component.Client, true)
if objectInstance:FindFirstChild(nameSpace) then
objectInstance[nameSpace]:Destroy()
end
component._serverComm = Comm.new(objectInstance, nameSpace)
for k,v in pairs(component.Client) do
if type(v) == "function" then
component._serverComm:WrapMethod(component.Client, k)
elseif tostring(v) == "SIGNAL_MARKER" then -- Allow Knit.CreateSignal()
component.Client[k] = component._serverComm:CreateSignal(k)
elseif type(v) == "table" and tostring(v[1]) == "PROPERTY_MARKER" then
component.Client[k] = component._serverComm:CreateProperty(k, v[2])
elseif tostring(v) == "UNRELIABLE_SIGNAL_MARKER" then
component.Client[k] = component._serverComm:CreateSignal(k, true)
end
end
component.Client.Server = component
end
else
component.Server = Comm.new(objectInstance, component.UsePromisesForMethods, nameSpace):BuildObject()
end
end
function RemoteComponentExtension.Stopping(component)
local target = IS_SERVER and "_serverComm" or "_clientComm"
if component[target] then component[target]:Destroy() end
end
return RemoteComponentExtension