Skip to content

Commit

Permalink
Stylua
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleitnick committed Jul 7, 2022
1 parent ae7de41 commit 9619e75
Show file tree
Hide file tree
Showing 74 changed files with 952 additions and 1,150 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[lua]": {
"editor.defaultFormatter": "JohnnyMorganz.stylua",
"editor.formatOnSave": true
}
}
39 changes: 28 additions & 11 deletions modules/comm/Client/ClientComm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ end
end)
```
]=]
function ClientComm:GetFunction(name: string, inboundMiddleware: Types.ClientMiddleware?, outboundMiddleware: Types.ClientMiddleware?)
function ClientComm:GetFunction(
name: string,
inboundMiddleware: Types.ClientMiddleware?,
outboundMiddleware: Types.ClientMiddleware?
)
return Comm.GetFunction(self._instancesFolder, name, self._usePromise, inboundMiddleware, outboundMiddleware)
end

Expand All @@ -116,7 +120,11 @@ end
mySignal:Fire("Hello!")
```
]=]
function ClientComm:GetSignal(name: string, inboundMiddleware: Types.ClientMiddleware?, outboundMiddleware: Types.ClientMiddleware?)
function ClientComm:GetSignal(
name: string,
inboundMiddleware: Types.ClientMiddleware?,
outboundMiddleware: Types.ClientMiddleware?
)
return Comm.GetSignal(self._instancesFolder, name, inboundMiddleware, outboundMiddleware)
end

Expand Down Expand Up @@ -154,7 +162,11 @@ end
local success, info = mapInfo:OnReady():await()
```
]=]
function ClientComm:GetProperty(name: string, inboundMiddleware: Types.ClientMiddleware?, outboundMiddleware: Types.ClientMiddleware?)
function ClientComm:GetProperty(
name: string,
inboundMiddleware: Types.ClientMiddleware?,
outboundMiddleware: Types.ClientMiddleware?
)
return Comm.GetProperty(self._instancesFolder, name, inboundMiddleware, outboundMiddleware)
end

Expand Down Expand Up @@ -183,23 +195,29 @@ function ClientComm:BuildObject(inboundMiddleware: Types.ClientMiddleware?, outb
local reFolder = self._instancesFolder:FindFirstChild("RE")
local rpFolder = self._instancesFolder:FindFirstChild("RP")
if rfFolder then
for _,rf in ipairs(rfFolder:GetChildren()) do
if not rf:IsA("RemoteFunction") then continue end
for _, rf in ipairs(rfFolder:GetChildren()) do
if not rf:IsA("RemoteFunction") then
continue
end
local f = self:GetFunction(rf.Name, inboundMiddleware, outboundMiddleware)
obj[rf.Name] = function(_self, ...)
return f(...)
end
end
end
if reFolder then
for _,re in ipairs(reFolder:GetChildren()) do
if not re:IsA("RemoteEvent") then continue end
for _, re in ipairs(reFolder:GetChildren()) do
if not re:IsA("RemoteEvent") then
continue
end
obj[re.Name] = self:GetSignal(re.Name, inboundMiddleware, outboundMiddleware)
end
end
if rpFolder then
for _,re in ipairs(rpFolder:GetChildren()) do
if not re:IsA("RemoteEvent") then continue end
for _, re in ipairs(rpFolder:GetChildren()) do
if not re:IsA("RemoteEvent") then
continue
end
obj[re.Name] = self:GetProperty(re.Name, inboundMiddleware, outboundMiddleware)
end
end
Expand All @@ -209,7 +227,6 @@ end
--[=[
Destroys the ClientComm object.
]=]
function ClientComm:Destroy()
end
function ClientComm:Destroy() end

return ClientComm
11 changes: 8 additions & 3 deletions modules/comm/Client/ClientRemoteProperty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
-- Stephen Leitnick
-- December 20, 2021


local Promise = require(script.Parent.Parent.Parent.Promise)
local Signal = require(script.Parent.Parent.Parent.Signal)
local ClientRemoteSignal = require(script.Parent.ClientRemoteSignal)
Expand Down Expand Up @@ -30,7 +29,11 @@ local Types = require(script.Parent.Parent.Types)
local ClientRemoteProperty = {}
ClientRemoteProperty.__index = ClientRemoteProperty

function ClientRemoteProperty.new(re: RemoteEvent, inboundMiddleware: Types.ClientMiddleware?, outboudMiddleware: Types.ClientMiddleware?)
function ClientRemoteProperty.new(
re: RemoteEvent,
inboundMiddleware: Types.ClientMiddleware?,
outboudMiddleware: Types.ClientMiddleware?
)
local self = setmetatable({}, ClientRemoteProperty)
self._rs = ClientRemoteSignal.new(re, inboundMiddleware, outboudMiddleware)
self._ready = false
Expand All @@ -40,7 +43,9 @@ function ClientRemoteProperty.new(re: RemoteEvent, inboundMiddleware: Types.Clie
self._readyPromise = nil
self.Changed:Fire(self._value)
self._changed = self._rs:Connect(function(value)
if value == self._value then return end
if value == self._value then
return
end
self._value = value
self.Changed:Fire(value)
end)
Expand Down
11 changes: 7 additions & 4 deletions modules/comm/Client/ClientRemoteSignal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
-- Stephen Leitnick
-- December 20, 2021


local Signal = require(script.Parent.Parent.Parent.Signal)
local Types = require(script.Parent.Parent.Types)

Expand All @@ -20,7 +19,11 @@ ClientRemoteSignal.__index = ClientRemoteSignal
.Disconnect () -> ()
]=]

function ClientRemoteSignal.new(re: RemoteEvent, inboundMiddleware: Types.ClientMiddleware?, outboudMiddleware: Types.ClientMiddleware?)
function ClientRemoteSignal.new(
re: RemoteEvent,
inboundMiddleware: Types.ClientMiddleware?,
outboudMiddleware: Types.ClientMiddleware?
)
local self = setmetatable({}, ClientRemoteSignal)
self._re = re
if outboudMiddleware and #outboudMiddleware > 0 then
Expand All @@ -34,7 +37,7 @@ function ClientRemoteSignal.new(re: RemoteEvent, inboundMiddleware: Types.Client
self._signal = Signal.new()
self._reConn = self._re.OnClientEvent:Connect(function(...)
local args = table.pack(...)
for _,middlewareFunc in ipairs(inboundMiddleware) do
for _, middlewareFunc in ipairs(inboundMiddleware) do
local middlewareResult = table.pack(middlewareFunc(args))
if not middlewareResult[1] then
return
Expand All @@ -51,7 +54,7 @@ end

function ClientRemoteSignal:_processOutboundMiddleware(...: any)
local args = table.pack(...)
for _,middlewareFunc in ipairs(self._outbound) do
for _, middlewareFunc in ipairs(self._outbound) do
local middlewareResult = table.pack(middlewareFunc(args))
if not middlewareResult[1] then
return table.unpack(middlewareResult, 2, middlewareResult.n)
Expand Down
30 changes: 22 additions & 8 deletions modules/comm/Client/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ local ClientRemoteProperty = require(script.ClientRemoteProperty)

local Client = {}

function Client.GetFunction(parent: Instance, name: string, usePromise: boolean, inboundMiddleware: Types.ClientMiddleware?, outboundMiddleware: Types.ClientMiddleware?)
function Client.GetFunction(
parent: Instance,
name: string,
usePromise: boolean,
inboundMiddleware: Types.ClientMiddleware?,
outboundMiddleware: Types.ClientMiddleware?
)
assert(not Util.IsServer, "GetFunction must be called from the client")
local folder = Util.GetCommSubFolder(parent, "RF"):Expect("Failed to get Comm RF folder")
local rf = folder:WaitForChild(name, Util.WaitForChildTimeout)
assert(rf ~= nil, "Failed to find RemoteFunction: " .. name)
local hasInbound = type(inboundMiddleware) == "table" and #inboundMiddleware > 0
local hasOutbound = type(outboundMiddleware) == "table" and #outboundMiddleware > 0
local function ProcessOutbound(args)
for _,middlewareFunc in ipairs(outboundMiddleware) do
for _, middlewareFunc in ipairs(outboundMiddleware) do
local middlewareResult = table.pack(middlewareFunc(args))
if not middlewareResult[1] then
return table.unpack(middlewareResult, 2, middlewareResult.n)
Expand All @@ -36,7 +42,7 @@ function Client.GetFunction(parent: Instance, name: string, usePromise: boolean,
end
end)
if success then
for _,middlewareFunc in ipairs(inboundMiddleware) do
for _, middlewareFunc in ipairs(inboundMiddleware) do
local middlewareResult = table.pack(middlewareFunc(res))
if not middlewareResult[1] then
return table.unpack(middlewareResult, 2, middlewareResult.n)
Expand All @@ -57,7 +63,7 @@ function Client.GetFunction(parent: Instance, name: string, usePromise: boolean,
else
res = table.pack(rf:InvokeServer(...))
end
for _,middlewareFunc in ipairs(inboundMiddleware) do
for _, middlewareFunc in ipairs(inboundMiddleware) do
local middlewareResult = table.pack(middlewareFunc(res))
if not middlewareResult[1] then
return table.unpack(middlewareResult, 2, middlewareResult.n)
Expand Down Expand Up @@ -100,17 +106,25 @@ function Client.GetFunction(parent: Instance, name: string, usePromise: boolean,
end
end


function Client.GetSignal(parent: Instance, name: string, inboundMiddleware: Types.ClientMiddleware?, outboundMiddleware: Types.ClientMiddleware?)
function Client.GetSignal(
parent: Instance,
name: string,
inboundMiddleware: Types.ClientMiddleware?,
outboundMiddleware: Types.ClientMiddleware?
)
assert(not Util.IsServer, "GetSignal must be called from the client")
local folder = Util.GetCommSubFolder(parent, "RE"):Expect("Failed to get Comm RE folder")
local re = folder:WaitForChild(name, Util.WaitForChildTimeout)
assert(re ~= nil, "Failed to find RemoteEvent: " .. name)
return ClientRemoteSignal.new(re, inboundMiddleware, outboundMiddleware)
end


function Client.GetProperty(parent: Instance, name: string, inboundMiddleware: Types.ClientMiddleware?, outboundMiddleware: Types.ClientMiddleware?)
function Client.GetProperty(
parent: Instance,
name: string,
inboundMiddleware: Types.ClientMiddleware?,
outboundMiddleware: Types.ClientMiddleware?
)
assert(not Util.IsServer, "GetProperty must be called from the client")
local folder = Util.GetCommSubFolder(parent, "RP"):Expect("Failed to get Comm RP folder")
local re = folder:WaitForChild(name, Util.WaitForChildTimeout)
Expand Down
27 changes: 17 additions & 10 deletions modules/comm/Server/RemoteProperty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
-- Stephen Leitnick
-- December 20, 2021


local Players = game:GetService("Players")

local Util = require(script.Parent.Parent.Util)
Expand Down Expand Up @@ -51,7 +50,13 @@ local None = Util.None
local RemoteProperty = {}
RemoteProperty.__index = RemoteProperty

function RemoteProperty.new(parent: Instance, name: string, initialValue: any, inboundMiddleware: Types.ServerMiddleware?, outboundMiddleware: Types.ServerMiddleware?)
function RemoteProperty.new(
parent: Instance,
name: string,
initialValue: any,
inboundMiddleware: Types.ServerMiddleware?,
outboundMiddleware: Types.ServerMiddleware?
)
local self = setmetatable({}, RemoteProperty)
self._rs = RemoteSignal.new(parent, name, inboundMiddleware, outboundMiddleware)
self._value = initialValue
Expand Down Expand Up @@ -112,7 +117,7 @@ end
]=]
function RemoteProperty:SetTop(value: any)
self._value = value
for _,player in ipairs(Players:GetPlayers()) do
for _, player in ipairs(Players:GetPlayers()) do
if self._perPlayer[player] == nil then
self._rs:Fire(player, value)
end
Expand All @@ -134,7 +139,7 @@ end
```
]=]
function RemoteProperty:SetFilter(predicate: (Player, any) -> boolean, value: any)
for _,player in ipairs(Players:GetPlayers()) do
for _, player in ipairs(Players:GetPlayers()) do
if predicate(player, value) then
self:SetFor(player, value)
end
Expand Down Expand Up @@ -171,8 +176,8 @@ end
remoteProperty:SetForList(players, "CustomData")
```
]=]
function RemoteProperty:SetForList(players: {Player}, value: any)
for _,player in ipairs(players) do
function RemoteProperty:SetForList(players: { Player }, value: any)
for _, player in ipairs(players) do
self:SetFor(player, value)
end
end
Expand All @@ -199,7 +204,9 @@ end
```
]=]
function RemoteProperty:ClearFor(player: Player)
if self._perPlayer[player] == nil then return end
if self._perPlayer[player] == nil then
return
end
self._perPlayer[player] = nil
self._rs:Fire(player, self._value)
end
Expand All @@ -209,8 +216,8 @@ end
just loops through the list of players and calls
the `ClearFor` method for each player.
]=]
function RemoteProperty:ClearForList(players: {Player})
for _,player in ipairs(players) do
function RemoteProperty:ClearForList(players: { Player })
for _, player in ipairs(players) do
self:ClearFor(player)
end
end
Expand All @@ -220,7 +227,7 @@ end
for any player that passes the predicate.
]=]
function RemoteProperty:ClearFilter(predicate: (Player) -> boolean)
for _,player in ipairs(Players:GetPlayers()) do
for _, player in ipairs(Players:GetPlayers()) do
if predicate(player) then
self:ClearFor(player)
end
Expand Down
19 changes: 11 additions & 8 deletions modules/comm/Server/RemoteSignal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
-- Stephen Leitnick
-- December 20, 2021


local Players = game:GetService("Players")

local Signal = require(script.Parent.Parent.Parent.Signal)
local Types = require(script.Parent.Parent.Types)


--[=[
@class RemoteSignal
@server
Expand All @@ -24,7 +22,12 @@ RemoteSignal.__index = RemoteSignal
.Connected boolean
]=]

function RemoteSignal.new(parent: Instance, name: string, inboundMiddleware: Types.ServerMiddleware?, outboundMiddleware: Types.ServerMiddleware?)
function RemoteSignal.new(
parent: Instance,
name: string,
inboundMiddleware: Types.ServerMiddleware?,
outboundMiddleware: Types.ServerMiddleware?
)
local self = setmetatable({}, RemoteSignal)
self._re = Instance.new("RemoteEvent")
self._re.Name = name
Expand All @@ -40,7 +43,7 @@ function RemoteSignal.new(parent: Instance, name: string, inboundMiddleware: Typ
self._signal = Signal.new()
self._re.OnServerEvent:Connect(function(player, ...)
local args = table.pack(...)
for _,middlewareFunc in ipairs(inboundMiddleware) do
for _, middlewareFunc in ipairs(inboundMiddleware) do
local middlewareResult = table.pack(middlewareFunc(player, args))
if not middlewareResult[1] then
return
Expand Down Expand Up @@ -75,7 +78,7 @@ function RemoteSignal:_processOutboundMiddleware(player: Player?, ...: any)
return ...
end
local args = table.pack(...)
for _,middlewareFunc in ipairs(self._outbound) do
for _, middlewareFunc in ipairs(self._outbound) do
local middlewareResult = table.pack(middlewareFunc(player, args))
if not middlewareResult[1] then
return table.unpack(middlewareResult, 2, middlewareResult.n)
Expand Down Expand Up @@ -154,7 +157,7 @@ end
```
]=]
function RemoteSignal:FireFilter(predicate: (Player, ...any) -> boolean, ...: any)
for _,player in ipairs(Players:GetPlayers()) do
for _, player in ipairs(Players:GetPlayers()) do
if predicate(player, ...) then
self._re:FireClient(player, self:_processOutboundMiddleware(nil, ...))
end
Expand All @@ -177,8 +180,8 @@ end
remoteSignal:FireFor(players, "Hello, players!")
```
]=]
function RemoteSignal:FireFor(players: {Player}, ...: any)
for _,player in ipairs(players) do
function RemoteSignal:FireFor(players: { Player }, ...: any)
for _, player in ipairs(players) do
self._re:FireClient(player, self:_processOutboundMiddleware(nil, ...))
end
end
Expand Down
Loading

0 comments on commit 9619e75

Please sign in to comment.