Skip to content

Commit

Permalink
Give typing to remotes accessed by absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
hoontee committed Apr 1, 2024
1 parent b9f0eb3 commit 49ee8c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions Pronghorn/Remotes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ local TypeChecker = require(script.TypeChecker)
-- Helper Variables
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-- Types
type GenericRemote = {
Fire: (self: GenericRemote, players: Player | {Player}, ...any?) -> ();
FireAll: (self: GenericRemote, ...any?) -> ();
FireAllExcept: (self: GenericRemote, ignorePlayer: Player, ...any?) -> ();
SetListener: (self: GenericRemote, newFunction: (Player, ...any) -> (...any)) -> ();
AddListener: (self: GenericRemote, newFunction: (Player, ...any) -> ()) -> RBXScriptConnection;
}

-- Objects
local remotesFolder: Folder;

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -49,7 +59,7 @@ local function connectEventClient(remote: RemoteFunction | UnreliableRemoteEvent
if not Remotes[moduleName] then
Remotes[moduleName] = {}
end
Remotes[moduleName][remote.Name] = setmetatable(actions, metaTable)
Remotes[moduleName][remote.Name] = setmetatable(actions, metaTable) :: GenericRemote

if remote:IsA("RemoteFunction") then

Expand Down Expand Up @@ -122,7 +132,7 @@ function Remotes:CreateToClient(name: string, requiredParameterTypes: {string},
if not Remotes[moduleName] then
Remotes[moduleName] = {}
end
Remotes[moduleName][remote.Name] = actions
Remotes[moduleName][remote.Name] = actions :: GenericRemote

if remoteType == "Returns" then
actions.Fire = function(_, player: Player, ...: any?)
Expand Down Expand Up @@ -160,7 +170,7 @@ function Remotes:CreateToClient(name: string, requiredParameterTypes: {string},
end
end

return actions
return actions :: any
end

--- Creates a Remote that receives information from Clients.
Expand Down Expand Up @@ -192,7 +202,7 @@ function Remotes:CreateToServer(name: string, requiredParameterTypes: {string},
if not Remotes[moduleName] then
Remotes[moduleName] = {}
end
Remotes[moduleName][remote.Name] = actions
Remotes[moduleName][remote.Name] = actions :: GenericRemote

local function getTypeCheckedFunction(newFunction: (Player, ...any) -> (...any))
return function(player: Player, ...: any)
Expand Down
2 changes: 1 addition & 1 deletion Pronghorn/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
║ ██████▀██▓▌▀▌ ▄ ▄▓▌▐▓█▌ ║
║ ║
║ ║
║ Pronghorn Framework Rev. B58
║ Pronghorn Framework Rev. B59
║ https://github.com/Iron-Stag-Games/Pronghorn ║
║ GNU Lesser General Public License v2.1 ║
║ ║
Expand Down

0 comments on commit 49ee8c4

Please sign in to comment.