added a small storage contianer, fixed the damn item slot (i relly think they are done now)
This commit is contained in:
@@ -3,6 +3,7 @@ extends StaticBody3D
|
||||
@export var isFirstPlace = true
|
||||
|
||||
func _ready() -> void:
|
||||
# Defers execution slightly to guarantee MeshInstance3D has finished mounting
|
||||
initialize_material.call_deferred()
|
||||
|
||||
func initialize_material() -> void:
|
||||
@@ -10,8 +11,13 @@ func initialize_material() -> void:
|
||||
$MeshInstance3D.material_override.albedo_color = Color("00000041")
|
||||
|
||||
if isFirstPlace:
|
||||
# Freshly placed machine in the world defaults to air
|
||||
placeItem("base:air")
|
||||
isFirstPlace = false
|
||||
else:
|
||||
# The machine was loaded from a save! Restore the data that was saved on the parent
|
||||
if $"..".ItemID != "" and $"..".ItemID != "base:air":
|
||||
placeItem($"..".ItemID)
|
||||
|
||||
func startHighlight():
|
||||
$MeshInstance3D.material_override.albedo_color = Color("00FF0041")
|
||||
@@ -30,6 +36,7 @@ func placeItem(ItemID: String):
|
||||
$"..".ItemTexture = itemResource.texture
|
||||
$"..".ItemID = itemResource.ID
|
||||
|
||||
# Mark initialized so it saves its state properly
|
||||
isFirstPlace = false
|
||||
|
||||
func removeItem():
|
||||
@@ -42,6 +49,6 @@ func _interact_press(isRight):
|
||||
placeItem(MainGame.currentHeldItemID)
|
||||
InventoryBus.removeHeldItem.emit()
|
||||
elif isRight:
|
||||
if $"..".ItemID != "base:air":
|
||||
if $"..".ItemID != "base:air" and $"..".ItemID != "":
|
||||
InventoryBus.givePlayerItem.emit($"..".ItemID)
|
||||
removeItem()
|
||||
|
||||
@@ -3,6 +3,7 @@ extends Node3D
|
||||
signal removeItemS
|
||||
signal placeItemS(ID: String)
|
||||
|
||||
# Simple export storage properties that Godot's PackedScene can easily serialize
|
||||
@export_storage var ItemTexture: Texture2D:
|
||||
set(value):
|
||||
ItemTexture = value
|
||||
@@ -19,7 +20,7 @@ func update_visuals() -> void:
|
||||
$Sprite3D.texture = ItemTexture
|
||||
$Sprite3D.pixel_size = 0.2 / ItemTexture.get_height()
|
||||
else:
|
||||
$Sprite3D.texture = null
|
||||
$Sprite3D.texture = null # This safely wipes the image when null is passed
|
||||
|
||||
func placeItem(ID: String):
|
||||
$StaticBody3D.placeItem(ID)
|
||||
|
||||
Reference in New Issue
Block a user