From fdcae1a67418e8b2333e2b3055fd357adffa7bf2 Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Sat, 8 Mar 2025 15:58:25 -0500 Subject: [PATCH] Reworked test blocks --- scenes/world/world.gd | 39 ++++++++++++++++++++++----------------- scenes/world/world.tscn | 8 +++++++- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/scenes/world/world.gd b/scenes/world/world.gd index a47f216..0a8c567 100644 --- a/scenes/world/world.gd +++ b/scenes/world/world.gd @@ -2,36 +2,41 @@ class_name World extends Node3D +@export var blocks_container: Node3D +@export var dropped_items_container: Node3D + + func _ready() -> void: Input.mouse_mode = Input.MOUSE_MODE_CAPTURED - EntityManager.create_block.connect(create_block.bind()) - EntityManager.drop_block.connect(create_dropped_block.bind()) + EntityManager.create_block.connect(_create_block.bind()) + EntityManager.drop_block.connect(_create_dropped_block.bind()) _initialize_ground() - - create_block("001", Vector3(0, 1, -3)) - create_block("002", Vector3(1, 1, -3)) - create_block("003", Vector3(2, 1, -3)) - create_block("004", Vector3(3, 1, -3)) - - create_dropped_block("001", Vector3(0, 1, -2)) - create_dropped_block("002", Vector3(1, 1, -2)) - create_dropped_block("003", Vector3(2, 1, -2)) - create_dropped_block("004", Vector3(3, 1, -2)) + _create_test_blocks() -func create_block(id: String, block_position: Vector3) -> void: +func _create_block(id: String, block_position: Vector3) -> void: var block: Block = Globals.BLOCK_PREFAB.instantiate() block.position = block_position block.set_id(id) - add_child(block) + blocks_container.add_child(block) -func create_dropped_block(id: String, block_position: Vector3) -> void: +func _create_dropped_block(id: String, block_position: Vector3) -> void: var block: DroppedBlock = Globals.DROPPED_BLOCK_PREFAB.instantiate() - add_child(block) + dropped_items_container.add_child(block) block.initialize(id, block_position) +func _create_test_blocks() -> void: + var test_blocks: Array = ["001", "002", "003", "004"] + for index in range(0, test_blocks.size()): + _create_block("00" + str(index + 1), Vector3(index, 1, -3)) + _create_block("00" + str(index + 1), Vector3(index, 2, -4)) + _create_block("00" + str(index + 1), Vector3(index, 3, -5)) + _create_dropped_block("00" + str(index + 1), Vector3(index, 2, -3)) + + + func _initialize_ground() -> void: for x: int in range(-10, 11): for z: int in range(-10, 11): @@ -39,7 +44,7 @@ func _initialize_ground() -> void: var random: int = randi_range(0, 1) if random: - # Just for testing.. Would probably make mmore sense to just call create_block() directly if still in World + # Just for testing.. Would make more sense to just call _create_block() directly EntityManager.create_block.emit("001", ground_position) else: EntityManager.create_block.emit("002", ground_position) diff --git a/scenes/world/world.tscn b/scenes/world/world.tscn index 135f58f..fa84e3a 100644 --- a/scenes/world/world.tscn +++ b/scenes/world/world.tscn @@ -16,8 +16,10 @@ sky = SubResource("Sky_dphjl") tonemap_mode = 2 glow_enabled = true -[node name="World" type="Node3D"] +[node name="World" type="Node3D" node_paths=PackedStringArray("blocks_container", "dropped_items_container")] script = ExtResource("1_6m72w") +blocks_container = NodePath("BlocksContainer") +dropped_items_container = NodePath("DroppedItemsContainer") [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = SubResource("Environment_sl2e5") @@ -27,3 +29,7 @@ transform = Transform3D(-0.866025, -0.433013, 0.25, 0, 0.5, 0.866025, -0.5, 0.75 shadow_enabled = true [node name="Player" parent="." instance=ExtResource("2_sl2e5")] + +[node name="BlocksContainer" type="Node3D" parent="."] + +[node name="DroppedItemsContainer" type="Node3D" parent="."]