Skip to content

Commit

Permalink
Add command types and tests in dev folder
Browse files Browse the repository at this point in the history
  • Loading branch information
jiwonz committed Oct 21, 2024
1 parent 30dd421 commit 0ebf7d8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
8 changes: 5 additions & 3 deletions dev/client/clientTests.client.luau
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ packets.myPacket.onClientReceived:connect(function(data)
print(data)
end)

RunService.Heartbeat:Connect(function()
packets.myPacket.sendToServer("ez")
end)
-- RunService.Heartbeat:Connect(function()
-- packets.myPacket.sendToServer("ez")
-- end)

packets.helloCommand()
8 changes: 5 additions & 3 deletions dev/server/serverTests.server.luau
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ packets.myPacket.onServerReceived:connect(function(data, player)
print(data)
end)

RunService.Heartbeat:Connect(function()
packets.myPacket.broadcast({true})
end)
-- RunService.Heartbeat:Connect(function()
-- packets.myPacket.broadcast("aa")
-- end)

packets.helloCommand()
3 changes: 3 additions & 0 deletions dev/shared/testPackets.luau
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ return HandyNet.defineNamespace("game", function()
myPacket = HandyNet.defineReliablePacket(
HandyNet.string(HandyNet.u8)
),
helloCommand = HandyNet.defineReliableCommand(function()
print("Merhaba!")
end)
}
end)
12 changes: 10 additions & 2 deletions src/types.luau
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ type EmptyEvent = nil & {
export type HandyNet = {
defineReliablePacket: <T>(value: T) -> Packet<T>,
defineUnreliablePacket: <T>(value: T) -> Packet<T>,
defineReliableCommand: (fn: () -> ()) -> (Player?) -> (),
defineUnreliableCommand: (fn: () -> ()) -> (Player?) -> (),
defineNamespace: <T>(name: string, namespace: () -> T) -> ({
server: { [string]: { sendToServer: nil, onClientReceived: EmptyEvent } } & T,
client: { [string]: { sendTo: nil, broadcast: nil, onServerReceived: EmptyEvent } } & T
server: { [string]: typeof(setmetatable(
{} :: { sendToServer: nil, onClientReceived: EmptyEvent },
{} :: { __call: (Player?) -> () }
)) } & T,
client: { [string]: typeof(setmetatable(
{} :: { sendTo: nil, broadcast: nil, onServerReceived: EmptyEvent },
{} :: { __call: () -> () }
)) } & T
}),

struct: <T>(format: T) -> T,
Expand Down

0 comments on commit 0ebf7d8

Please sign in to comment.