2021-11-15 15:43:33 -06:00
|
|
|
extends Node
|
|
|
|
|
2021-11-15 16:25:13 -06:00
|
|
|
const MultiplayerClient = preload("multiplayer_client.gd")
|
2021-11-15 15:43:33 -06:00
|
|
|
|
2021-11-15 16:25:13 -06:00
|
|
|
onready var client = MultiplayerClient.new()
|
2021-11-15 15:43:33 -06:00
|
|
|
|
2021-11-16 23:47:59 -06:00
|
|
|
const MULTIPLAYER_URL = "wss://webrtc-signaller.deno.dev/"
|
2021-11-15 15:43:33 -06:00
|
|
|
|
|
|
|
func _ready():
|
2021-11-15 16:25:13 -06:00
|
|
|
client.connect("lobby_joined", self, "_lobby_joined")
|
|
|
|
client.connect("connected", self, "_connected")
|
|
|
|
add_child(client)
|
2021-11-15 15:43:33 -06:00
|
|
|
|
|
|
|
func start_singleplayer_game():
|
|
|
|
print("Starting singleplayer game...")
|
2021-11-15 16:25:13 -06:00
|
|
|
get_tree().change_scene("res://game.tscn")
|
|
|
|
|
|
|
|
func join_lobby():
|
|
|
|
get_tree().change_scene("res://join_lobby.tscn")
|
|
|
|
|
|
|
|
func create_lobby():
|
|
|
|
join_lobby_with_code("")
|
|
|
|
|
|
|
|
func _lobby_joined(_lobby):
|
|
|
|
print("Joined!")
|
|
|
|
goto_lobby()
|
|
|
|
|
|
|
|
func goto_lobby():
|
|
|
|
print("Going to lobby...")
|
|
|
|
get_tree().change_scene("res://lobby.tscn")
|
2021-11-15 15:43:33 -06:00
|
|
|
|
|
|
|
func leave_game():
|
2021-11-15 16:25:13 -06:00
|
|
|
client.stop()
|
2021-11-15 15:43:33 -06:00
|
|
|
print("Leaving game...")
|
2021-11-15 16:25:13 -06:00
|
|
|
get_tree().change_scene("res://main.tscn")
|
|
|
|
|
|
|
|
func join_lobby_with_code(code):
|
|
|
|
client.start(MULTIPLAYER_URL, code)
|