harvest/game/scripts/gdsync_link.gd
2026-10-04 12:07:36 -04:00

24 lines
772 B
GDScript

class_name GDSyncLink
extends CoopLink
## The co-op wire over GD-Sync (the GDSync autoload; LAN or online): every message is a remote
## call of CoopSession.net_receive on the other machine (the same node path on both, since both
## run main.tscn), reliable or unreliable. The session exposes that function to GD-Sync.
var gdsync: Node
var peer: int = -1
var session: Node
func _init(p_gdsync: Node, p_peer: int, p_session: Node) -> void:
gdsync = p_gdsync
peer = p_peer
session = p_session
func _deliver(kind: String, data: Variant, reliable: bool) -> void:
if closed or gdsync == null or peer < 0:
return
if reliable:
gdsync.call_func_on(peer, session.net_receive, kind, data)
else:
gdsync.call_func_on_unreliable(peer, session.net_receive, kind, data)