GD-Polo/scripts/menu.gd
Anthony Foxclaw dbac16804c Project reorganization
Reorganized the project so it's a little less all over the place. For example, world scenes are now in scenes/world. I also moved all scripts to the script directory.
2020-06-28 14:58:49 -04:00

50 lines
1.7 KiB
GDScript

extends Control
var host_port = 2675
var host_playermax = 2
var ip = "127.0.0.1"
var port = 2670
# Called when the node enters the scene tree for the first time.
func _ready():
if OS.has_environment("USERNAME"):
$GeneralPanel/player_name.text = OS.get_environment("USERNAME")
else:
var desktop_path = OS.get_system_dir(0).replace("\\", "/").split("/")
$GeneralPanel/player_name.text = desktop_path[desktop_path.size() - 2]
func _on_singleplayer_button_up():
var _letsgo = get_tree().change_scene("res://scenes/world/World.tscn")
func _on_JoinGameBtn_button_up():
ip = $JoinPanel/join_ip
port = $JoinPanel/join_port
print("Netplay - Attempting to join game at IP ",ip," via port ",port)
join_game()
func _on_HostGameBtn_button_up():
var host_port = $HostPanel/host_port.value
print("Netplay - Attempting to host game on port ",host_port,"...")
host_game(host_port)
func host_game(port):
var maxplayers = $HostPanel/playercount.value
var host = NetworkedMultiplayerENet.new()
print("Netplay - Returned: ",host)
host.create_server(port, maxplayers) # ports, maxplayers
get_tree().set_network_peer(host)
print("Netplay - Hosting on port ",port,". Max players: ",maxplayers)
print("Netplay - Are you the server ... ",get_tree().is_network_server())
$HostPanel/HostGameBtn.disabled = 1
$HostPanel/HostGameBtn.hint_tooltip = "Cannot start another server, Server already started."
$JoinPanel/JoinGameBtn.disabled = 1
$JoinPanel/JoinGameBtn.hint_tooltip = "Cannot join another server, Server already started."
#Goto a lobby instance
func join_game():
var host = NetworkedMultiplayerENet.new()
host.create_client(ip, port)
get_tree().set_network_peer(host)
print("Maybe it joined...?")