93 lines
2.9 KiB
GDScript
93 lines
2.9 KiB
GDScript
## freeftf
|
|
## Copyright (C) 2024 Patrick_Pluto
|
|
##
|
|
## This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
##
|
|
## This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
##
|
|
## You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
extends Control
|
|
|
|
var elevated = false
|
|
var done
|
|
var map_name = "mansion"
|
|
|
|
func _ready():
|
|
$player_customization/name.text = Game.settings["username"]
|
|
var username_cmdline
|
|
var roomname_cmdline
|
|
for argument in OS.get_cmdline_args():
|
|
if argument == "--username":
|
|
username_cmdline = "ready"
|
|
continue
|
|
if argument == "--roomname":
|
|
roomname_cmdline = "ready"
|
|
continue
|
|
if argument == "--autojoin":
|
|
_on_join_pressed()
|
|
if username_cmdline == "ready":
|
|
username_cmdline = null
|
|
$player_customization/name.text = argument
|
|
if roomname_cmdline == "ready":
|
|
roomname_cmdline = null
|
|
$player_customization/ip.text = argument
|
|
multiplayer.connected_to_server.connect(_on_connected_ok)
|
|
multiplayer.peer_connected.connect(_sync_options)
|
|
|
|
func server_prepare():
|
|
if Game.is_server:
|
|
$player_customization/ip.hide()
|
|
$player_customization/ip.text = "localhost"
|
|
$player_customization/ip.editable = false
|
|
$start/start.show()
|
|
$start/start.disabled = false
|
|
$player_list/list.text = " "
|
|
$options.show()
|
|
$options/map_name/OptionButton.disabled = false
|
|
|
|
func _process(_delta):
|
|
server_prepare()
|
|
done = 0
|
|
for id in Game.player_list:
|
|
if done == 1:
|
|
$player_list/list.text = str($player_list/list.text +"\n" + Game.player_list[id])
|
|
else:
|
|
$player_list/list.text = Game.player_list[id]
|
|
done = 1
|
|
|
|
|
|
func _on_start_pressed():
|
|
for id in Game.player_list:
|
|
Client.rpc_id(id,"start_game")
|
|
|
|
func _input(_event):
|
|
if Input.is_action_just_pressed("escape"):
|
|
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
|
|
|
|
|
func _on_join_pressed():
|
|
if $player_customization/name.text != "" and $player_customization/name.text.length() <= 20 and $player_customization/ip.text != "":
|
|
Game.room_name = $player_customization/ip.text
|
|
Game.player_name = $player_customization/name.text
|
|
Client.join_game()
|
|
|
|
func _on_connected_ok():
|
|
$player_customization/join.hide()
|
|
$player_customization/join.disabled = true
|
|
$player_customization/name.editable = false
|
|
$player_customization/ip.editable = false
|
|
|
|
|
|
func _on_option_button_item_selected(index):
|
|
match index:
|
|
0:
|
|
map_name = "mansion"
|
|
_:
|
|
map_name = "mansion"
|
|
for id in Game.player_list:
|
|
Client.rpc_id(id, "sync_level", map_name)
|
|
|
|
func _sync_options():
|
|
for id in Game.player_list:
|
|
Client.rpc_id(id, "sync_level", map_name)
|