mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-19 19:44:46 +00:00
104 lines
4 KiB
Plaintext
104 lines
4 KiB
Plaintext
[gd_scene load_steps=5 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"]
|
|
|
|
[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
|
|
|
|
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)
|
|
|
|
func _ready() -> void:
|
|
# only run server in headless
|
|
if DisplayServer.get_name() == \"headless\":
|
|
mode = MULTIPLAYER.instantiate()
|
|
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 mode is Multiplayer:
|
|
$BootMenu._on_multiplayer_pressed()
|
|
else:
|
|
$BootMenu._on_main_menu_pressed()
|
|
# reset game mode and get back to main menu
|
|
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:
|
|
mode = SINGLEPLAYER.instantiate()
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
$BootMenu.hide()
|
|
|
|
func _start_server(port : int, nickname : String) -> void:
|
|
mode = MULTIPLAYER.instantiate()
|
|
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:
|
|
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)
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
"
|
|
|
|
[node name="Game" type="Node3D"]
|
|
script = SubResource("GDScript_e61dq")
|
|
SINGLEPLAYER = ExtResource("1_50a80")
|
|
MULTIPLAYER = ExtResource("2_g8xeb")
|
|
|
|
[node name="BootMenu" parent="." instance=ExtResource("1_acy5o")]
|