From 43f9e25dd06c70efb94a0efd85fbd624ae9cb71e Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Sun, 9 Mar 2025 13:14:04 -0400 Subject: [PATCH] Moving DBItems from singleton to autoload --- {data_structure => autoloads}/db_items.gd | 12 ------------ {data_structure => autoloads}/db_items.gd.uid | 0 data_structure/db_items.tscn | 6 ------ project.godot | 2 +- .../block.gd => resources/block_resource.gd | 0 .../block.gd.uid => resources/block_resource.gd.uid | 0 resources/blocks/001_dirt.tres | 2 +- resources/blocks/002_stone.tres | 2 +- resources/blocks/003_wood.tres | 2 +- resources/blocks/004_leaves.tres | 2 +- data_structure/item.gd => resources/item_resource.gd | 0 .../item.gd.uid => resources/item_resource.gd.uid | 0 root.tscn | 5 +---- scenes/blocks/block.gd | 2 +- scenes/ui/waila.gd | 2 +- 15 files changed, 8 insertions(+), 29 deletions(-) rename {data_structure => autoloads}/db_items.gd (66%) rename {data_structure => autoloads}/db_items.gd.uid (100%) delete mode 100644 data_structure/db_items.tscn rename data_structure/block.gd => resources/block_resource.gd (100%) rename data_structure/block.gd.uid => resources/block_resource.gd.uid (100%) rename data_structure/item.gd => resources/item_resource.gd (100%) rename data_structure/item.gd.uid => resources/item_resource.gd.uid (100%) diff --git a/data_structure/db_items.gd b/autoloads/db_items.gd similarity index 66% rename from data_structure/db_items.gd rename to autoloads/db_items.gd index 0f61d3d..8f224bf 100644 --- a/data_structure/db_items.gd +++ b/autoloads/db_items.gd @@ -1,18 +1,6 @@ -class_name DBItems extends Node -#region Singleton -static var ref: DBItems - -func _init() -> void: - if not ref: - ref = self - else: - queue_free() -#endregion - - @onready var data: Dictionary = { "001": preload("res://resources/blocks/001_dirt.tres"), "002": preload("res://resources/blocks/002_stone.tres"), diff --git a/data_structure/db_items.gd.uid b/autoloads/db_items.gd.uid similarity index 100% rename from data_structure/db_items.gd.uid rename to autoloads/db_items.gd.uid diff --git a/data_structure/db_items.tscn b/data_structure/db_items.tscn deleted file mode 100644 index 1547757..0000000 --- a/data_structure/db_items.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://c0epfh4sqjcjq"] - -[ext_resource type="Script" uid="uid://bm3oi0opccjif" path="res://data_structure/db_items.gd" id="1_jp5j0"] - -[node name="DBItems" type="Node"] -script = ExtResource("1_jp5j0") diff --git a/project.godot b/project.godot index 8f0e814..ed4e80c 100644 --- a/project.godot +++ b/project.godot @@ -20,6 +20,7 @@ config/icon="res://icon.svg" Globals="*res://autoloads/globals.gd" EntityManager="*res://autoloads/entity_manager.gd" InventoryManager="*res://autoloads/inventory_manager.gd" +DBItems="*res://autoloads/db_items.gd" [debug] @@ -34,7 +35,6 @@ folder_colors={ "res://assets/": "red", "res://assets/ui/": "green", "res://autoloads/": "orange", -"res://data_structure/": "blue", "res://resources/": "blue", "res://scenes/": "yellow", "res://scenes/ui/": "green" diff --git a/data_structure/block.gd b/resources/block_resource.gd similarity index 100% rename from data_structure/block.gd rename to resources/block_resource.gd diff --git a/data_structure/block.gd.uid b/resources/block_resource.gd.uid similarity index 100% rename from data_structure/block.gd.uid rename to resources/block_resource.gd.uid diff --git a/resources/blocks/001_dirt.tres b/resources/blocks/001_dirt.tres index 3adafe2..405f023 100644 --- a/resources/blocks/001_dirt.tres +++ b/resources/blocks/001_dirt.tres @@ -1,6 +1,6 @@ [gd_resource type="Resource" script_class="BlockResource" load_steps=3 format=3 uid="uid://bu0yoee1rs1se"] -[ext_resource type="Script" uid="uid://dwrmy4mx0mw18" path="res://data_structure/block.gd" id="1_ljghb"] +[ext_resource type="Script" uid="uid://dwrmy4mx0mw18" path="res://resources/block_resource.gd" id="1_ljghb"] [ext_resource type="Material" uid="uid://uex0dq00xomt" path="res://assets/materials/dirt.tres" id="1_n1cq6"] [resource] diff --git a/resources/blocks/002_stone.tres b/resources/blocks/002_stone.tres index 4244e16..3aa0d3f 100644 --- a/resources/blocks/002_stone.tres +++ b/resources/blocks/002_stone.tres @@ -1,7 +1,7 @@ [gd_resource type="Resource" script_class="BlockResource" load_steps=3 format=3 uid="uid://cpddnknmxpohc"] [ext_resource type="Material" uid="uid://cx7m27qa4ds4s" path="res://assets/materials/stone.tres" id="1_6chm7"] -[ext_resource type="Script" uid="uid://dwrmy4mx0mw18" path="res://data_structure/block.gd" id="1_63t5s"] +[ext_resource type="Script" uid="uid://dwrmy4mx0mw18" path="res://resources/block_resource.gd" id="1_63t5s"] [resource] script = ExtResource("1_63t5s") diff --git a/resources/blocks/003_wood.tres b/resources/blocks/003_wood.tres index 48f02e6..3e1c06e 100644 --- a/resources/blocks/003_wood.tres +++ b/resources/blocks/003_wood.tres @@ -1,7 +1,7 @@ [gd_resource type="Resource" script_class="BlockResource" load_steps=4 format=3 uid="uid://bvudydis6w27b"] [ext_resource type="Material" uid="uid://bnqiumcb3ixan" path="res://assets/materials/wood_ends.tres" id="1_1n8h6"] -[ext_resource type="Script" uid="uid://dwrmy4mx0mw18" path="res://data_structure/block.gd" id="2_1n8h6"] +[ext_resource type="Script" uid="uid://dwrmy4mx0mw18" path="res://resources/block_resource.gd" id="2_1n8h6"] [ext_resource type="Material" uid="uid://h0naiw6swfkl" path="res://assets/materials/wood_side.tres" id="2_o823h"] [resource] diff --git a/resources/blocks/004_leaves.tres b/resources/blocks/004_leaves.tres index 9bb8889..5e69168 100644 --- a/resources/blocks/004_leaves.tres +++ b/resources/blocks/004_leaves.tres @@ -1,7 +1,7 @@ [gd_resource type="Resource" script_class="BlockResource" load_steps=3 format=3 uid="uid://4knt6o2ohku3"] [ext_resource type="Material" uid="uid://d15n1p3spu3jg" path="res://assets/materials/leaves.tres" id="1_dbmit"] -[ext_resource type="Script" uid="uid://dwrmy4mx0mw18" path="res://data_structure/block.gd" id="3_kuops"] +[ext_resource type="Script" uid="uid://dwrmy4mx0mw18" path="res://resources/block_resource.gd" id="3_kuops"] [resource] script = ExtResource("3_kuops") diff --git a/data_structure/item.gd b/resources/item_resource.gd similarity index 100% rename from data_structure/item.gd rename to resources/item_resource.gd diff --git a/data_structure/item.gd.uid b/resources/item_resource.gd.uid similarity index 100% rename from data_structure/item.gd.uid rename to resources/item_resource.gd.uid diff --git a/root.tscn b/root.tscn index 194c3f5..2909961 100644 --- a/root.tscn +++ b/root.tscn @@ -1,13 +1,10 @@ -[gd_scene load_steps=4 format=3 uid="uid://cgx0nawwjjj7g"] +[gd_scene load_steps=3 format=3 uid="uid://cgx0nawwjjj7g"] -[ext_resource type="PackedScene" uid="uid://c0epfh4sqjcjq" path="res://data_structure/db_items.tscn" id="1_pyidc"] [ext_resource type="PackedScene" uid="uid://mkfitwqnerku" path="res://scenes/world/world.tscn" id="2_vvh5c"] [ext_resource type="PackedScene" uid="uid://c7fj7wla8bd70" path="res://scenes/ui/ui.tscn" id="3_vvh5c"] [node name="Root" type="Node"] -[node name="DBItems" parent="." instance=ExtResource("1_pyidc")] - [node name="World" parent="." instance=ExtResource("2_vvh5c")] [node name="UI" parent="." instance=ExtResource("3_vvh5c")] diff --git a/scenes/blocks/block.gd b/scenes/blocks/block.gd index ba5b734..e3f64cb 100644 --- a/scenes/blocks/block.gd +++ b/scenes/blocks/block.gd @@ -71,4 +71,4 @@ func _load_resource_data() -> void: printerr("Block ID was expected but was not received") return - resource = DBItems.ref.data[id] + resource = DBItems.data[id] diff --git a/scenes/ui/waila.gd b/scenes/ui/waila.gd index fbd8558..ed262e5 100644 --- a/scenes/ui/waila.gd +++ b/scenes/ui/waila.gd @@ -31,7 +31,7 @@ func get_target() -> Block: func hook_target(id: String) -> void: if not Globals.enable_waila: return - var item: ItemResource = DBItems.ref.data[id] + var item: ItemResource = DBItems.data[id] name_label.text = item.name + " (" + id + ")" description_label.text = item.description position_label.text = str(_target.position)