freeftf/scripts/create.gd

55 lines
2 KiB
GDScript3
Raw Normal View History

## freeftf
## Copyright (C) 2024 Patrick_Pluto
2024-08-02 22:38:08 +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
##
## 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
##
## 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
var elevated = false
2024-08-02 20:13:42 +02:00
func _ready():
multiplayer.connected_to_server.connect(_on_connected_ok)
if Server.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 = " "
func _process(delta):
if Server.is_server:
Server.sync_playerlist.rpc($player_list/list.text, multiplayer.get_unique_id())
if Server.is_server and !elevated:
_ready()
Server.send_playerinfo($player_customization/name.text, multiplayer.get_unique_id())
elevated = true
2024-08-02 20:13:42 +02:00
func _on_start_pressed():
Server.start_game.rpc(Server.players)
2024-08-03 22:24:08 +02:00
func _input(event):
if Input.is_action_just_pressed("escape"):
Game.reset()
Server.reset()
2024-08-03 22:24:08 +02:00
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 != "":
if !Server.is_server:
Server.join_game($player_customization/ip.text)
func _on_connected_ok():
$player_customization/join.hide()
$player_customization/join.disabled = true
$player_customization/name.editable = false
$player_customization/ip.editable = false
await get_tree().create_timer(1).timeout
Server.send_playerinfo.rpc($player_customization/name.text, multiplayer.get_unique_id())