Last active
September 22, 2022 00:35
-
-
Save B-Ricey763/dc625917644797acbf41eaa00504cb0b to your computer and use it in GitHub Desktop.
Bridge Extension rough draft. My setup is a folder called Bridge with these three files as descendants.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local ReplicatedStorage = game:GetService("ReplicatedStorage") | |
| local Comm = require(ReplicatedStorage.Packages.Comm) | |
| local Client = {} | |
| function Client.Starting(component) | |
| local inboundMiddleware = component.Middleware and component.Middleware.Inbound | |
| local outboundMiddleware = component.Middleware and component.Middleware.Outbound | |
| component.Server = Comm.ClientComm.new(component.Instance, true, component.Tag):BuildObject( | |
| inboundMiddleware, | |
| outboundMiddleware | |
| ) | |
| end | |
| function Client.Stopped(component) | |
| if component.Server then | |
| component.Server:Destroy() | |
| end | |
| end | |
| return Client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local RunService = game:GetService("RunService") | |
| local IS_SERVER = RunService:IsServer() | |
| local Client = require(script.Client) | |
| local Server = require(script.Server) | |
| return if IS_SERVER then Server else Client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local ReplicatedStorage = game:GetService("ReplicatedStorage") | |
| local TableUtil = require(ReplicatedStorage.Packages.TableUtil) | |
| local Comm = require(ReplicatedStorage.Packages.Comm) | |
| local Server = {} | |
| function Server.Starting(component) | |
| if not component.Client then | |
| return | |
| end | |
| local outboundMiddleware = component.Middleware and component.Middleware.Outbound | |
| local inboundMiddleware = component.Middleware and component.Middleware.Inbound | |
| component.Client = TableUtil.Copy(component.Client) | |
| component._comm = Comm.ServerComm.new(component.Instance, component.Tag) | |
| for k, v in pairs(component.Client) do | |
| if type(v) == "function" then | |
| component._comm:WrapMethod(component.Client, k, inboundMiddleware, outboundMiddleware) | |
| elseif tostring(v) == "SIGNAL_MARKER" then -- Allow Knit.CreateSignal() | |
| component.Client[k] = component._comm:CreateSignal(k, inboundMiddleware, outboundMiddleware) | |
| elseif type(v) == "table" and tostring(v[1]) == "PROPERTY_MARKER" then -- Same thing as Knit | |
| component.Client[k] = component._comm:CreateProperty(k, v[2], inboundMiddleware, outboundMiddleware) | |
| end | |
| end | |
| component.Client.Server = component | |
| end | |
| function Server.Stopped(component) | |
| if component._comm then | |
| component._comm:Destroy() | |
| end | |
| end | |
| return Server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment