added machine item slots so ican start building gameplay
This commit is contained in:
47
Objects/Scripts/IItemSlot.gd
Normal file
47
Objects/Scripts/IItemSlot.gd
Normal file
@@ -0,0 +1,47 @@
|
||||
extends StaticBody3D
|
||||
|
||||
@export var isFirstPlace = true
|
||||
|
||||
func _ready() -> void:
|
||||
initialize_material.call_deferred()
|
||||
|
||||
func initialize_material() -> void:
|
||||
$MeshInstance3D.material_override = $MeshInstance3D.material_override.duplicate()
|
||||
$MeshInstance3D.material_override.albedo_color = Color("00000041")
|
||||
|
||||
if isFirstPlace:
|
||||
placeItem("base:air")
|
||||
isFirstPlace = false
|
||||
|
||||
func startHighlight():
|
||||
$MeshInstance3D.material_override.albedo_color = Color("00FF0041")
|
||||
|
||||
func stopHighlight():
|
||||
$MeshInstance3D.material_override.albedo_color = Color("00000041")
|
||||
|
||||
func placeItem(ItemID: String):
|
||||
var segments = ItemID.split(":")
|
||||
|
||||
var itemResource: ItemData = load("res://GameShit/ItemHandlers/{namespace}/{id}.tres".format({"namespace": segments[0], "id": segments[1]}))
|
||||
if itemResource == null:
|
||||
itemResource = load("res://GameShit/ItemHandlers/base/air.tres")
|
||||
|
||||
if "texture" in itemResource:
|
||||
$"..".ItemTexture = itemResource.texture
|
||||
$"..".ItemID = itemResource.ID
|
||||
|
||||
isFirstPlace = false
|
||||
|
||||
func removeItem():
|
||||
$"..".ItemTexture = null
|
||||
$"..".ItemID = "base:air"
|
||||
|
||||
func _interact_press(isRight):
|
||||
if !isRight:
|
||||
if $"..".ItemID == "base:air":
|
||||
placeItem(MainGame.currentHeldItemID)
|
||||
InventoryBus.removeHeldItem.emit()
|
||||
elif isRight:
|
||||
if $"..".ItemID != "base:air":
|
||||
InventoryBus.givePlayerItem.emit($"..".ItemID)
|
||||
removeItem()
|
||||
1
Objects/Scripts/IItemSlot.gd.uid
Normal file
1
Objects/Scripts/IItemSlot.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dlcok7eixbdfg
|
||||
28
Objects/Scripts/SItemSlot.gd
Normal file
28
Objects/Scripts/SItemSlot.gd
Normal file
@@ -0,0 +1,28 @@
|
||||
extends Node3D
|
||||
|
||||
signal removeItemS
|
||||
signal placeItemS(ID: String)
|
||||
|
||||
@export_storage var ItemTexture: Texture2D:
|
||||
set(value):
|
||||
ItemTexture = value
|
||||
update_visuals()
|
||||
|
||||
@export_storage var ItemID: String
|
||||
|
||||
func _ready() -> void:
|
||||
update_visuals()
|
||||
|
||||
func update_visuals() -> void:
|
||||
if has_node("Sprite3D"):
|
||||
if ItemTexture != null:
|
||||
$Sprite3D.texture = ItemTexture
|
||||
$Sprite3D.pixel_size = 0.2 / ItemTexture.get_height()
|
||||
else:
|
||||
$Sprite3D.texture = null
|
||||
|
||||
func placeItem(ID: String):
|
||||
$StaticBody3D.placeItem(ID)
|
||||
|
||||
func removeItem():
|
||||
$StaticBody3D.removeItem()
|
||||
1
Objects/Scripts/SItemSlot.gd.uid
Normal file
1
Objects/Scripts/SItemSlot.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b37g0a5iakh5v
|
||||
Reference in New Issue
Block a user