Leaving and game starting works rudimentarily

This commit is contained in:
Daniel Flanagan 2021-12-09 22:11:02 -06:00
parent 41e7769249
commit 2aea604aba
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
5 changed files with 4 additions and 6 deletions

View file

@ -32,7 +32,6 @@ signal connection_failure
signal disconnected signal disconnected
onready var websocket: WebSocketClient = WebSocketClient.new() onready var websocket: WebSocketClient = WebSocketClient.new()
# TODO: setget these?
onready var client_id = null onready var client_id = null
onready var display_name = DEFAULT_DISPLAY_NAME setget set_display_name onready var display_name = DEFAULT_DISPLAY_NAME setget set_display_name
onready var peer_id = null onready var peer_id = null

View file

@ -3,6 +3,7 @@ extends Node2D
onready var player = preload("res://objects/player.tscn") onready var player = preload("res://objects/player.tscn")
func _ready(): func _ready():
# TODO: probably have to wait for all peers to be ready before we add players
rpc("add_player", get_tree().get_network_unique_id()) rpc("add_player", get_tree().get_network_unique_id())
func _process(delta): func _process(delta):

View file

@ -1,7 +1,5 @@
extends Control extends Control
# TODO: rename to server browser
onready var is_loaded = false onready var is_loaded = false
onready var lobbies_grid = $v/body/p/lobbies onready var lobbies_grid = $v/body/p/lobbies
@ -58,7 +56,6 @@ func _on_join_pressed():
Global.signaller_client.join_lobby(lobbies.get_item_metadata(items[0])["id"]) Global.signaller_client.join_lobby(lobbies.get_item_metadata(items[0])["id"])
func _lobby_data(new_lobbies: Array): func _lobby_data(new_lobbies: Array):
# TODO: handle scrolling so that the user is never too jarred (like chat)
for l in new_lobbies: for l in new_lobbies:
if lobbies.has(l.id): _update_lobby(l.id, l) if lobbies.has(l.id): _update_lobby(l.id, l)
else: _add_lobby(l.id, l) else: _add_lobby(l.id, l)

View file

@ -141,6 +141,7 @@ remotesync func set_ready(ready):
var from = get_tree().get_rpc_sender_id() var from = get_tree().get_rpc_sender_id()
print(from) print(from)
peer_by_peer_id(from).ready = ready peer_by_peer_id(from).ready = ready
if is_host: update_can_start()
func _on_TextEdit_text_entered(_new_text): func _on_TextEdit_text_entered(_new_text):
if !send_button.disabled: if !send_button.disabled:

View file

@ -8,7 +8,7 @@ type ID = string;
// app state // app state
const allLobbies = new Map<ID, Lobby>(); const allLobbies = new Map<ID, Lobby>();
const allClients = new Map<ID, Client>(); const allClients = new Map<ID, Client>();
// TODO: client index by id // TODO: client index by id?
interface DataMessage { interface DataMessage {
type: string; type: string;
@ -336,7 +336,7 @@ function parseMessage(message: string): { type: string; data?: ServerData } {
// events // events
function onMessage(client: Client, ev: MessageEvent) { function onMessage(client: Client, ev: MessageEvent) {
// TODO: log who from? // TODO: log who from? IPs etc.?
const msg = parseMessage(ev.data); const msg = parseMessage(ev.data);
if (msg.type === "pong") return; if (msg.type === "pong") return;
console.log("Client Message Received", msg); console.log("Client Message Received", msg);