2024-08-05 22:35:50 +02:00
## freeftf
## Copyright (C) 2024 Patrick_Pluto
2024-08-02 22:38:08 +02:00
##
2024-08-05 22:35:50 +02:00
## 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.
2024-08-02 22:38:08 +02:00
##
2024-08-05 22:35:50 +02:00
## 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.
2024-08-02 22:38:08 +02:00
##
2024-08-05 22:35:50 +02:00
## You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
2024-08-02 22:38:08 +02:00
2024-08-02 20:13:42 +02:00
extends Control
2024-08-05 22:35:50 +02:00
var elevated = false
2024-08-08 21:49:24 +02:00
var done
2024-08-13 22:12:37 +02:00
var map_name = " mansion "
2024-08-05 22:35:50 +02:00
2024-08-02 20:13:42 +02:00
func _ready ( ) :
2024-08-13 22:12:37 +02:00
$ 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
2024-08-06 23:28:40 +02:00
multiplayer . connected_to_server . connect ( _on_connected_ok )
2024-08-13 22:12:37 +02:00
multiplayer . peer_connected . connect ( _sync_options )
2024-08-08 21:49:24 +02:00
func server_prepare ( ) :
if Game . is_server :
2024-08-04 13:41:19 +02:00
$ 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 = " "
2024-08-13 22:12:37 +02:00
$ options . show ( )
$ options / map_name / OptionButton . disabled = false
2024-08-08 21:49:24 +02:00
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
2024-08-02 20:13:42 +02:00
func _on_start_pressed ( ) :
2024-08-08 21:49:24 +02:00
for id in Game . player_list :
Client . rpc_id ( id , " start_game " )
2024-08-03 22:24:08 +02:00
2024-08-08 21:49:24 +02:00
func _input ( _event ) :
2024-08-03 22:24:08 +02:00
if Input . is_action_just_pressed ( " escape " ) :
get_tree ( ) . change_scene_to_file ( " res://menus/main_menu.tscn " )
2024-08-04 13:41:19 +02:00
func _on_join_pressed ( ) :
2024-08-06 23:28:40 +02:00
if $ player_customization / name . text != " " and $ player_customization / name . text . length ( ) < = 20 and $ player_customization / ip . text != " " :
2024-08-08 21:49:24 +02:00
Game . room_name = $ player_customization / ip . text
Game . player_name = $ player_customization / name . text
Client . join_game ( )
2024-08-06 23:28:40 +02:00
func _on_connected_ok ( ) :
$ player_customization / join . hide ( )
$ player_customization / join . disabled = true
$ player_customization / name . editable = false
$ player_customization / ip . editable = false
2024-08-13 22:12:37 +02:00
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 )