Compare commits
No commits in common. "cb48515d691567f39bf849b8bfd9e32378f3e449" and "70c07a5e9099564812cbfc9ae87cb4b2e90e5f41" have entirely different histories.
cb48515d69
...
70c07a5e90
@ -8,5 +8,5 @@ script = ExtResource("3_fe16f")
|
|||||||
icon = ExtResource("1_vrj0d")
|
icon = ExtResource("1_vrj0d")
|
||||||
name = "Coin Flower"
|
name = "Coin Flower"
|
||||||
id = &"coin_flower"
|
id = &"coin_flower"
|
||||||
stackable = true
|
stackable = false
|
||||||
stack_limit = 8
|
stack_limit = 8
|
||||||
|
@ -59,17 +59,13 @@ func _physics_process(delta: float) -> void:
|
|||||||
## Process interactivity selection.
|
## Process interactivity selection.
|
||||||
if id == multiplayer.get_unique_id():
|
if id == multiplayer.get_unique_id():
|
||||||
var collider: Object = null
|
var collider: Object = null
|
||||||
if _line_of_sight.is_colliding():
|
if empty_handed() and _line_of_sight.is_colliding():
|
||||||
var possible_collider = _line_of_sight.get_collider(0)
|
collider = _line_of_sight.get_collider(0)
|
||||||
if empty_handed(): collider = possible_collider
|
|
||||||
elif possible_collider and \
|
|
||||||
GameState.are_bundles_stackable(held_thing, possible_collider.owner.item_bundle):
|
|
||||||
collider = possible_collider
|
|
||||||
if collider != _interaction_selection:
|
if collider != _interaction_selection:
|
||||||
if _interaction_selection != null:
|
if _interaction_selection != null:
|
||||||
_interaction_selection.get_parent().mark_non_interactive()
|
_interaction_selection.get_parent().mark_non_interactive()
|
||||||
if collider != null:
|
if collider != null:
|
||||||
collider.owner.mark_interactive()
|
collider.get_parent().mark_interactive()
|
||||||
_interaction_selection = collider
|
_interaction_selection = collider
|
||||||
|
|
||||||
# Add the gravity.
|
# Add the gravity.
|
||||||
@ -118,7 +114,7 @@ func hold_thing(p_bundle: Dictionary) -> void:
|
|||||||
base_node.add_child(model)
|
base_node.add_child(model)
|
||||||
else:
|
else:
|
||||||
# Create a icon sprite based one instead.
|
# Create a icon sprite based one instead.
|
||||||
var model := preload("res://src/ingame/quad_viewmodel.tscn").instantiate()
|
var model := preload("res://src/quad_viewmodel.tscn").instantiate()
|
||||||
model.reflect_bundle(p_bundle)
|
model.reflect_bundle(p_bundle)
|
||||||
base_node.add_child(model)
|
base_node.add_child(model)
|
||||||
|
|
||||||
@ -155,15 +151,10 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||||||
_camera_pivot.rotation.x = clamp(_camera_pivot.rotation.x, -1.2, 1.2)
|
_camera_pivot.rotation.x = clamp(_camera_pivot.rotation.x, -1.2, 1.2)
|
||||||
return
|
return
|
||||||
|
|
||||||
if event.is_action_pressed("pick"):
|
if event.is_action_pressed("pick") and empty_handed():
|
||||||
if _interaction_selection != null:
|
if _interaction_selection != null:
|
||||||
if empty_handed():
|
|
||||||
_interaction_selection.owner.get_picked_up.rpc()
|
_interaction_selection.owner.get_picked_up.rpc()
|
||||||
hold_thing.rpc(_interaction_selection.owner.item_bundle)
|
hold_thing.rpc(_interaction_selection.owner.item_bundle)
|
||||||
elif GameState.are_bundles_stackable(held_thing, _interaction_selection.owner.item_bundle):
|
|
||||||
_interaction_selection.owner.get_picked_up.rpc()
|
|
||||||
var bundle := GameState.combine_bundles(held_thing, _interaction_selection.owner.item_bundle)
|
|
||||||
hold_thing.rpc(bundle)
|
|
||||||
|
|
||||||
if event.is_action_pressed("fire") and not empty_handed():
|
if event.is_action_pressed("fire") and not empty_handed():
|
||||||
var new_projectile: Node3D = _projectile_scene.instantiate()
|
var new_projectile: Node3D = _projectile_scene.instantiate()
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
extends Node3D
|
|
||||||
|
|
||||||
func reflect_bundle(p_bundle: Dictionary) -> void:
|
|
||||||
var item = GameState.fetch().INVENTORY_ITEM_DB[p_bundle["item_id"]]
|
|
||||||
$Sprite3D.texture = item.icon
|
|
||||||
if item.stackable:
|
|
||||||
$CountLabel.text = str(p_bundle["count"]) + "/" + str(item.stack_limit)
|
|
||||||
else:
|
|
||||||
$CountLabel.text = str(p_bundle["count"])
|
|
@ -23,18 +23,3 @@ static func save() -> void:
|
|||||||
|
|
||||||
static func fetch() -> GameState:
|
static func fetch() -> GameState:
|
||||||
return _instance
|
return _instance
|
||||||
|
|
||||||
|
|
||||||
# TODO: better place for those?
|
|
||||||
static func are_bundles_stackable(p_a_bundle: Dictionary, p_b_bundle: Dictionary) -> bool:
|
|
||||||
var item = GameState.fetch().INVENTORY_ITEM_DB[p_a_bundle["item_id"]]
|
|
||||||
return p_a_bundle["item_id"] == p_b_bundle["item_id"] and \
|
|
||||||
item.stackable and p_a_bundle["count"] + p_b_bundle["count"] <= item.stack_limit
|
|
||||||
|
|
||||||
|
|
||||||
static func combine_bundles(p_a_bundle: Dictionary, p_b_bundle: Dictionary) -> Dictionary:
|
|
||||||
assert(are_bundles_stackable(p_a_bundle, p_b_bundle))
|
|
||||||
return {
|
|
||||||
"item_id": p_a_bundle["item_id"],
|
|
||||||
"count": p_a_bundle["count"] + p_b_bundle["count"],
|
|
||||||
}
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
class_name InventoryItem extends Resource
|
class_name InventoryItem
|
||||||
|
extends Resource
|
||||||
|
|
||||||
@export var icon: Texture2D = preload("res://icon.svg")
|
@export var icon: Texture2D = preload("res://icon.svg")
|
||||||
@export var model: PackedScene
|
@export var model: PackedScene
|
||||||
|
5
src/quad_viewmodel.gd
Normal file
5
src/quad_viewmodel.gd
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
extends Node3D
|
||||||
|
|
||||||
|
func reflect_bundle(p_bundle: Dictionary) -> void:
|
||||||
|
$Sprite3D.texture = GameState.fetch().INVENTORY_ITEM_DB[p_bundle["item_id"]].icon
|
||||||
|
$CountLabel.text = str(p_bundle["count"])
|
@ -1,11 +1,11 @@
|
|||||||
[gd_scene load_steps=3 format=3 uid="uid://dxb5f3il2h1ur"]
|
[gd_scene load_steps=3 format=3 uid="uid://dxb5f3il2h1ur"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://src/ingame/quad_viewmodel.gd" id="1_l2s4x"]
|
[ext_resource type="Script" path="res://src/quad_viewmodel.gd" id="1_vidqb"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dw3x3h3f34sy3" path="res://assets/coin_flower.png" id="2_7fi8t"]
|
[ext_resource type="Texture2D" uid="uid://dw3x3h3f34sy3" path="res://assets/coin_flower.png" id="2_3hbqi"]
|
||||||
|
|
||||||
[node name="QuadViewmodel" type="Node3D"]
|
[node name="QuadViewmodel" type="Node3D"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.179242, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.179242, 0)
|
||||||
script = ExtResource("1_l2s4x")
|
script = ExtResource("1_vidqb")
|
||||||
|
|
||||||
[node name="CountLabel" type="Label3D" parent="."]
|
[node name="CountLabel" type="Label3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.181474, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.181474, 0)
|
||||||
@ -16,4 +16,4 @@ text = "3"
|
|||||||
pixel_size = 0.015
|
pixel_size = 0.015
|
||||||
billboard = 1
|
billboard = 1
|
||||||
texture_filter = 0
|
texture_filter = 0
|
||||||
texture = ExtResource("2_7fi8t")
|
texture = ExtResource("2_3hbqi")
|
Loading…
Reference in New Issue
Block a user