From ff835bd158505af0b1dee8a5feac4461d02d738d Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Tue, 4 Mar 2025 10:49:59 -0500 Subject: [PATCH] Updating how matierals are applied --- scenes/blocks/block.gd | 11 ++++++++--- scenes/world/world.gd | 9 +++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/scenes/blocks/block.gd b/scenes/blocks/block.gd index 8fa8d90..1e59de0 100644 --- a/scenes/blocks/block.gd +++ b/scenes/blocks/block.gd @@ -1,13 +1,18 @@ class_name Block extends StaticBody3D + +const Materials: Dictionary[Types, StandardMaterial3D] = { + Block.Types.DIRT: preload("res://assets/materials/dirt.tres"), + Block.Types.STONE: preload("res://assets/materials/stone.tres"), +} enum Types { DIRT, STONE, } - @export var material: StandardMaterial3D +@export var type: Types @onready var block_faces: Node3D = $BlockFaces @@ -16,8 +21,8 @@ func _ready() -> void: _apply_materials() -func set_material(block_material: StandardMaterial3D): - material = block_material +func apply_material(): + material = Materials[type] func _apply_materials() -> void: for face: MeshInstance3D in block_faces.get_children(): diff --git a/scenes/world/world.gd b/scenes/world/world.gd index 6e07cd7..1dc3368 100644 --- a/scenes/world/world.gd +++ b/scenes/world/world.gd @@ -2,12 +2,8 @@ class_name World extends Node3D -const BLOCK_PREFAB: PackedScene = preload("res://scenes/blocks/block.tscn") -const BLOCK_MATERIALS: Dictionary[Block.Types, StandardMaterial3D] = { - Block.Types.DIRT: preload("res://assets/materials/dirt.tres"), - Block.Types.STONE: preload("res://assets/materials/stone.tres"), -} +const BLOCK_PREFAB: PackedScene = preload("res://scenes/blocks/block.tscn") func _ready() -> void: @@ -19,5 +15,6 @@ func create_block(block_type: Block.Types, block_position: Vector3) -> void: var block: Block = BLOCK_PREFAB.instantiate() block.position = block_position block.name = "%s" % [block_position] - block.set_material(BLOCK_MATERIALS[block_type]) + block.type = block_type + block.apply_material() add_child(block)