2026-04-20 13:03:39 -05:00
|
|
|
class_name MainMenu extends Node
|
2026-04-15 12:10:17 -05:00
|
|
|
|
|
|
|
|
@onready var main_menu: Container = %MainMenu
|
|
|
|
|
@onready var create_session: Container = %CreateSession
|
|
|
|
|
@onready var join_session: Container = %JoinSession
|
|
|
|
|
@onready var lobby: Lobby = %Lobby
|
|
|
|
|
|
|
|
|
|
|
2026-04-20 13:03:39 -05:00
|
|
|
func _init() -> void:
|
|
|
|
|
Globals.main_menu = self
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
Globals.game.players_changed.connect(lobby.load_players)
|
|
|
|
|
|
|
|
|
|
|
2026-04-15 12:10:17 -05:00
|
|
|
func handle_create_session(player: Player) -> void:
|
|
|
|
|
Globals.game.this_player = player
|
2026-04-20 13:03:39 -05:00
|
|
|
Globals.game.tube_client.create_session()
|
|
|
|
|
Globals.game.this_player.id = Globals.game.tube_client.peer_id
|
|
|
|
|
Globals.game.add_player.rpc(player.serialize())
|
2026-04-15 12:10:17 -05:00
|
|
|
create_session.hide()
|
|
|
|
|
lobby.show()
|
|
|
|
|
lobby.set_session_id(Globals.game.tube_client.session_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func handle_join_session(session_id: String, player: Player) -> void:
|
2026-04-20 13:03:39 -05:00
|
|
|
Globals.game.this_player = player
|
2026-04-15 12:10:17 -05:00
|
|
|
Globals.game.tube_client.join_session(session_id)
|
|
|
|
|
await Globals.game.tube_client.peer_connected
|
2026-04-20 13:03:39 -05:00
|
|
|
Globals.game.this_player.id = Globals.game.tube_client.peer_id
|
|
|
|
|
Globals.game.add_player.rpc(player.serialize())
|
|
|
|
|
Globals.game.sync_players.rpc()
|
2026-04-15 12:10:17 -05:00
|
|
|
join_session.hide()
|
|
|
|
|
lobby.show()
|
|
|
|
|
lobby.set_session_id(session_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_create_session_pressed():
|
|
|
|
|
main_menu.hide()
|
|
|
|
|
create_session.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_join_session_pressed():
|
|
|
|
|
main_menu.hide()
|
|
|
|
|
join_session.show()
|
2026-04-20 13:03:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_single_player_pressed():
|
|
|
|
|
Globals.game.tube_client.create_session()
|
|
|
|
|
Globals.game.this_player = Player.new()
|
|
|
|
|
Globals.game.this_player.name = "one"
|
|
|
|
|
Globals.game.add_player(Globals.game.this_player.serialize())
|
|
|
|
|
#var two = Player.new()
|
|
|
|
|
#two.name = "two"
|
|
|
|
|
#var three = Player.new()
|
|
|
|
|
#three.name = "three"
|
|
|
|
|
#var four = Player.new()
|
|
|
|
|
#four.name = "four"
|
|
|
|
|
#Globals.game.add_player(two.serialize())
|
|
|
|
|
#Globals.game.add_player(three.serialize())
|
|
|
|
|
#Globals.game.add_player(four.serialize())
|
|
|
|
|
Globals.game.start_game()
|