jecs/examples/networking/remotes.luau

37 lines
952 B
Text
Raw Normal View History

2025-11-30 07:59:04 +00:00
local ReplicatedStorage = require("@game/ReplicatedStorage")
local types = require("./types")
2025-06-05 20:48:13 +00:00
type Remote<T...> = {
2025-07-24 00:24:25 +00:00
FireClient: (Remote<T...>, Player, T...) -> (),
2025-06-05 20:48:13 +00:00
FireAllClients: (Remote<T...>, T...) -> (),
2025-07-24 00:24:25 +00:00
FireServer: (Remote<T...>, T...) -> (),
OnServerEvent: RBXScriptSignal<(Player, T...)>,
OnClientEvent: RBXScriptSignal<T...>
2025-06-05 20:48:13 +00:00
}
2025-07-24 00:24:25 +00:00
local function stream_ensure(name)
2025-06-05 20:48:13 +00:00
local remote = ReplicatedStorage:FindFirstChild(name)
if not remote then
remote = Instance.new("RemoteEvent")
remote.Name = name
remote.Parent = ReplicatedStorage
end
2025-07-24 00:24:25 +00:00
return remote
2025-06-05 20:48:13 +00:00
end
2025-07-24 00:24:25 +00:00
local function datagram_ensure(name)
2025-06-05 20:48:13 +00:00
local remote = ReplicatedStorage:FindFirstChild(name)
if not remote then
remote = Instance.new("UnreliableRemoteEvent")
remote.Name = name
remote.Parent = ReplicatedStorage
end
2025-07-24 00:24:25 +00:00
return remote
2025-06-05 20:48:13 +00:00
end
return {
input = datagram_ensure("input") :: Remote<string>,
2025-11-30 07:59:04 +00:00
replication = stream_ensure("replication") :: Remote<types.snapshot>,
2025-06-05 20:48:13 +00:00
}