added machine item slots so ican start building gameplay
This commit is contained in:
30
Objects/IItemSlot.tscn
Normal file
30
Objects/IItemSlot.tscn
Normal file
@@ -0,0 +1,30 @@
|
||||
[gd_scene format=3 uid="uid://qu5r32m0u141"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b37g0a5iakh5v" path="res://Objects/Scripts/SItemSlot.gd" id="1_ge8hl"]
|
||||
[ext_resource type="Script" uid="uid://dlcok7eixbdfg" path="res://Objects/Scripts/IItemSlot.gd" id="1_jcrx8"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_qfiyq"]
|
||||
transparency = 1
|
||||
albedo_color = Color(0, 1, 0, 0.25490198)
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_qfiyq"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_jcrx8"]
|
||||
|
||||
[node name="IItemSlot" type="Node3D" unique_id=2108535834]
|
||||
script = ExtResource("1_ge8hl")
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="." unique_id=987230634]
|
||||
script = ExtResource("1_jcrx8")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody3D" unique_id=175979558]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 0.18091178, 0, 0, 0)
|
||||
material_override = SubResource("StandardMaterial3D_qfiyq")
|
||||
mesh = SubResource("BoxMesh_qfiyq")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" unique_id=1181811379]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 0.18091178, 0, 0, 0)
|
||||
shape = SubResource("BoxShape3D_jcrx8")
|
||||
|
||||
[node name="Sprite3D" type="Sprite3D" parent="." unique_id=159015325]
|
||||
transform = Transform3D(5, 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0)
|
||||
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