From 101cd700ae2482eed6280f28613d6b23c0c700a9 Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Sun, 17 Nov 2024 11:53:13 -0700 Subject: [PATCH] Added world container --- project.godot | 6 +++++- src/world/world.gd | 27 +++++++++++++++++++++++++++ src/world/world.tscn | 34 ++++++++++------------------------ 3 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 src/world/world.gd diff --git a/project.godot b/project.godot index a9aa130..5f48923 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="GFOLF 2" config/description="GFOLF: Combat Golf Action" -run/main_scene="res://levels/debug_level/debug_level.tscn" +run/main_scene="res://src/world/world.tscn" config/features=PackedStringArray("4.3", "Forward Plus") run/max_fps=60 @@ -56,6 +56,10 @@ config/controls/camera/x_axis_acceleration=30.0 config/controls/camera/y_axis_acceleration=30.0 config/controls/camera/invert_pitch=false +[global_group] + +WorldGroup="Singleton group for the active world instance, if any." + [gui] theme/custom="res://src/ui/main_theme.tres" diff --git a/src/world/world.gd b/src/world/world.gd new file mode 100644 index 0000000..8365fec --- /dev/null +++ b/src/world/world.gd @@ -0,0 +1,27 @@ +class_name World extends Node +## Container scene for a game world instance. +## +## A world contains player(s) and the active level, manages player states, +## and transitions between active levels. + +@export var initial_level: PackedScene = preload("res://levels/debug_level/debug_level.tscn") + +@onready var level: Node3D = %Level +@onready var ui: Control = %UI + + +func _ready() -> void: + load_level(initial_level) + + +## Instantiate and mantle the given level scene. +## +## This will free any currently-loaded level! +func load_level(level_scene: PackedScene) -> void: + # Remove any currently-loaded level assets + for c: Node in level.get_children(): + c.queue_free() + + # Load the level + var instance: Node3D = level_scene.instantiate() + level.add_child(instance) diff --git a/src/world/world.tscn b/src/world/world.tscn index 933c31f..1eeb712 100644 --- a/src/world/world.tscn +++ b/src/world/world.tscn @@ -1,33 +1,19 @@ -[gd_scene load_steps=4 format=3 uid="uid://cwnwcd8kushl3"] +[gd_scene load_steps=2 format=3 uid="uid://cwnwcd8kushl3"] -[ext_resource type="Shader" path="res://src/shaders/retro_postprocessing.gdshader" id="1_3gv54"] -[ext_resource type="PackedScene" uid="uid://bm2o3mex10v11" path="res://levels/debug_level/debug_level.tscn" id="1_pge3b"] +[ext_resource type="Script" path="res://src/world/world.gd" id="1_ybjyx"] -[sub_resource type="ShaderMaterial" id="ShaderMaterial_sc4r2"] -shader = ExtResource("1_3gv54") -shader_parameter/change_color_depth = true -shader_parameter/target_color_depth = 8 -shader_parameter/dithering = true -shader_parameter/scale_resolution = true -shader_parameter/target_resolution_scale = 3 -shader_parameter/enable_recolor = false +[node name="World" type="Node" groups=["WorldGroup"]] +script = ExtResource("1_ybjyx") -[node name="World" type="Node"] +[node name="Level" type="Node3D" parent="."] +unique_name_in_owner = true -[node name="SubViewportContainer" type="SubViewportContainer" parent="."] -material = SubResource("ShaderMaterial_sc4r2") +[node name="UI" type="Control" parent="."] +unique_name_in_owner = true +layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -stretch = true - -[node name="SubViewport" type="SubViewport" parent="SubViewportContainer"] -handle_input_locally = false -size = Vector2i(1280, 720) -render_target_update_mode = 4 - -[node name="Level" type="Node3D" parent="SubViewportContainer/SubViewport"] - -[node name="TestLevel" parent="SubViewportContainer/SubViewport/Level" instance=ExtResource("1_pge3b")] +mouse_filter = 1