open-fpsz/main.tscn
2024-05-07 14:21:10 +00:00

93 lines
3.9 KiB
Plaintext

[gd_scene load_steps=5 format=3 uid="uid://dr8salxjlpsba"]
[ext_resource type="PackedScene" uid="uid://boviiugcnfyrj" path="res://modes/singleplayer/demo.tscn" id="1_vgk6g"]
[ext_resource type="PackedScene" uid="uid://bvwxfgygm2xb8" path="res://modes/multiplayer/multiplayer.tscn" id="2_iumx3"]
[ext_resource type="PackedScene" uid="uid://bjctlqvs33nqy" path="res://interfaces/menus/boot/boot.tscn" id="3_s8c8j"]
[sub_resource type="GDScript" id="GDScript_e61dq"]
script/source = "# This file is part of open-fpsz.
#
# 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/>.
class_name Game extends Node3D
@export_category(\"Modes\")
@export var SINGLEPLAYER : PackedScene
@export var MULTIPLAYER : PackedScene
func _ready() -> void:
# only run server in headless
if DisplayServer.get_name() == \"headless\":
GameManager.mode = MULTIPLAYER.instantiate()
GameManager.mode.start_server(9000, MapsManager.maps[MapsManager._rng.randi_range(0, len(MapsManager.maps) - 1)])
return
# connect boot menu signals
$BootMenu.start_demo.connect(_start_demo)
$BootMenu/MultiplayerPanelContainer.start_server.connect(_start_server)
$BootMenu/MultiplayerPanelContainer.join_server.connect(_join_server)
# do not set initial window mode for debug build
if not OS.is_debug_build():
DisplayServer.window_set_mode(Settings.get_value(\"video\", \"window_mode\"))
func _unhandled_input(event : InputEvent) -> void:
if event.is_action_pressed(\"exit\"):
if GameManager.mode is Multiplayer:
$BootMenu._on_multiplayer_pressed()
else:
$BootMenu._on_main_menu_pressed()
# reset game mode and get back to main menu
GameManager.mode = null
if DisplayServer.get_name() != \"headless\":
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
return
# switch window mode
if event.is_action_pressed(\"window_mode\"):
if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
# switch mouse mode
if OS.is_debug_build() and Input.is_action_just_pressed(\"toggle_mouse_capture\"):
if Input.mouse_mode == Input.MOUSE_MODE_VISIBLE:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
elif Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
func _start_demo() -> void:
GameManager.mode = SINGLEPLAYER.instantiate()
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
$BootMenu.hide()
func _start_server(port : int, nickname : String) -> void:
GameManager.mode = MULTIPLAYER.instantiate()
GameManager.mode.start_server(port, MapsManager.maps[$BootMenu/MultiplayerPanelContainer.map_selector.selected], nickname)
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
$BootMenu.hide()
func _join_server(host : String, port : int, nickname : String) -> void:
GameManager.mode = MULTIPLAYER.instantiate()
GameManager.mode.connected_to_server.connect($BootMenu/MultiplayerPanelContainer._on_connected_to_server)
GameManager.mode.connection_failed.connect($BootMenu/MultiplayerPanelContainer._on_connection_failed)
GameManager.mode.join_server(host, port, nickname)
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
"
[node name="Game" type="Node3D"]
script = SubResource("GDScript_e61dq")
SINGLEPLAYER = ExtResource("1_vgk6g")
MULTIPLAYER = ExtResource("2_iumx3")
[node name="BootMenu" parent="." instance=ExtResource("3_s8c8j")]