Skip to content

Commit

Permalink
p2
Browse files Browse the repository at this point in the history
  • Loading branch information
NancokPS2 committed Jan 27, 2024
1 parent e32b67f commit 0032f52
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions scenes/items/consumables/healthpotion/HealthPotion.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ func _init():
item_class = "HealthPotion"
item_type = ITEM_TYPE.CONSUMABLE
boost.hp = 25
amount_max = 6
18 changes: 17 additions & 1 deletion scenes/player/inventory/InventoryPanel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ const DEFAULT_FONT: Font = preload("res://addons/gut/fonts/LobsterTwo-Regular.tt

@export var item: Item:
set(new_item):
if item is Item and item.amount_changed.is_connected(on_item_amount_changed):
item.amount_changed.disconnect(on_item_amount_changed)

item = new_item
if item:

if item is Item:
if not item.amount_changed.is_connected(on_item_amount_changed):
item.amount_changed.connect(on_item_amount_changed)
$TextureRect.texture = item.get_node("Icon").texture
else:

$TextureRect.texture = null

queue_redraw()

@onready var inventory: Inventory = $"../.."
@onready var drag_panel = $"../../DragPanel"
Expand All @@ -25,6 +34,9 @@ func _ready():
mouse_exited.connect(_on_mouse_exited)





func _draw():
if item is Item:
var font_height: int = 14
Expand Down Expand Up @@ -68,3 +80,7 @@ func _on_mouse_entered():

func _on_mouse_exited():
inventory.mouse_above_this_panel = null


func on_item_amount_changed(item: Item, amount: int):
queue_redraw()
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func add_item(item: Item) -> bool:
if item.amount > 0:
add_item(item)

sync_item_amount.rpc_id(target_node.peer_id, item.uuid, item.amount)

return true

#Adding the item from scratch
Expand Down Expand Up @@ -88,9 +90,14 @@ func remove_item(item_uuid: String, amount: int = 1):
return false

var item: Item = get_item(item_uuid)

if item != null:
items.erase(item)
sync_remove_item.rpc_id(target_node.peer_id, item_uuid)
item.amount -= amount
if item.amount <= 0:
items.erase(item)
sync_remove_item.rpc_id(target_node.peer_id, item_uuid)
else:
sync_item_amount.rpc_id(target_node.peer_id, item.uuid, item.amount)
return item


Expand Down

0 comments on commit 0032f52

Please sign in to comment.