open-fpsz/main.tscn
2024-04-28 06:15:19 +00:00

110 lines
4 KiB
Plaintext

[gd_scene load_steps=6 format=3 uid="uid://ma1if3sjox6i"]
[ext_resource type="PackedScene" uid="uid://boviiugcnfyrj" path="res://modes/singleplayer/demo.tscn" id="1_50a80"]
[ext_resource type="PackedScene" uid="uid://bjctlqvs33nqy" path="res://interfaces/menus/boot/boot.tscn" id="1_acy5o"]
[ext_resource type="PackedScene" uid="uid://bvwxfgygm2xb8" path="res://modes/multiplayer/multiplayer.tscn" id="2_g8xeb"]
[ext_resource type="Resource" uid="uid://dut5f1sq0wfeb" path="res://maps/maps.tres" id="3_1ipir"]
[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
@export_category(\"Maps\")
@export var _maps_resource : ArrayPackedSceneResource
@onready var maps : Array[PackedScene] = _maps_resource.get_items()
# current mode, when the value is set to null we're in the main menu
var mode : Node:
set(new_mode):
# clean up previous mode
if mode != null:
mode.queue_free()
# keep reference to new mode
mode = new_mode
# setup new mode
if new_mode != null:
add_child(new_mode)
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
else:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
func _ready() -> void:
$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\"):
# reset game mode
mode = null
# make it easier to exit the game during development
if OS.is_debug_build():
get_tree().quit(0)
else:
$BootMenu.show()
# 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:
mode = SINGLEPLAYER.instantiate()
$BootMenu.hide()
func _start_server(port : int, nickname : String) -> void:
mode = MULTIPLAYER.instantiate()
mode.start_server({
\"port\": port,
\"nickname\": nickname,
\"map\": maps[clamp($BootMenu/MultiplayerPanelContainer.map_selector.selected, 0, len(maps))]
})
$BootMenu.hide()
func _join_server(host : String, port : int, nickname : String) -> void:
mode = MULTIPLAYER.instantiate()
mode.connected_to_server.connect($BootMenu/MultiplayerPanelContainer._on_connected_to_server)
mode.connection_failed.connect($BootMenu/MultiplayerPanelContainer._on_connection_failed)
mode.join_server(host, port, nickname)
"
[node name="Game" type="Node3D"]
script = SubResource("GDScript_e61dq")
SINGLEPLAYER = ExtResource("1_50a80")
MULTIPLAYER = ExtResource("2_g8xeb")
_maps_resource = ExtResource("3_1ipir")
[node name="BootMenu" parent="." instance=ExtResource("1_acy5o")]