♻️ systems refactoring

This commit is contained in:
anyreso 2024-05-08 10:25:06 -04:00
parent 5ab387571e
commit 69c8b65093
17 changed files with 186 additions and 168 deletions

8
systems/MapsManager.tscn Normal file
View file

@ -0,0 +1,8 @@
[gd_scene load_steps=3 format=3 uid="uid://c4h2mdvdwndxl"]
[ext_resource type="Script" path="res://systems/maps_manager.gd" id="1_a1ovw"]
[ext_resource type="PackedScene" uid="uid://btlkog4b87p4x" path="res://maps/desert/desert.tscn" id="2_v1r16"]
[node name="MapsManager" type="Node"]
script = ExtResource("1_a1ovw")
maps = Array[PackedScene]([ExtResource("2_v1r16")])

View file

@ -1,13 +0,0 @@
extends Node
## This is the mode currently used by the game.
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)

46
systems/global.gd Normal file
View file

@ -0,0 +1,46 @@
# 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/>.
extends Node
signal type_changed(type : Node)
## This is the type currently used by the game.
var type : Node:
set(new_type):
# clean up previous type
if type != null:
type.queue_free()
# swap types
if type != new_type:
# keep reference to new type
type = new_type
if type != null:
add_child(type)
type_changed.emit(type)
func _unhandled_input(event : InputEvent) -> void:
# 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("mouse_mode"):
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

View file

@ -15,6 +15,9 @@
## Manage environment settings and terrain maps within a scene.
extends Node
## The list of available maps.
@export var maps : Array[PackedScene]
## The default [Environment] used by the current scene in case the [Terrain3D]
## node does not have a [WorldEnvironment] as one of its children.
var environment := Environment.new()
@ -22,9 +25,6 @@ var environment := Environment.new()
## Random number generator instance
var _rng := RandomNumberGenerator.new()
var _maps_resource : ArrayPackedSceneResource = preload("res://maps/maps.tres")
var maps : Array[PackedScene] = _maps_resource.get_items()
## Reference to the current terrain map in the scene
var current_map : Terrain3D = null:
set(new_map):