Finished basic PickupableItem

This commit is contained in:
Alexey 2025-08-01 13:11:26 +03:00
commit 88c56f8aed
21 changed files with 163 additions and 35 deletions

View file

@ -1,13 +1,10 @@
extends Resource
extends IdentifiedResource
class_name BasePickupableResource
## Item ID, make sure it's unique
@export var id: StringName
## Texture that will be used in node sprite
@export var texture: Texture2D
## Emitted when item picked up. Returns if PickupableItem should be freed
func _apply(_player: Player) -> bool:
return true
## Emitted when item picked up. Returns IdentifiedResource if it should be swapped
func _apply(_player: Player) -> IdentifiedResource:
return null

View file

@ -9,5 +9,8 @@ func _ready() -> void:
texture = content.texture
func _interact(_player: Player) -> void:
if content._apply(_player):
content = content._apply(_player)
if content == null:
queue_free()
return
_ready()

View file

@ -5,7 +5,7 @@ class_name WeaponPickupableResource
## Weapon that will be added on interaction
@export var weapon: PackedScene
func _apply(player: Player) -> bool:
func _apply(player: Player) -> IdentifiedResource:
var slot = player.weapons.first_free_slot()
# TODO: Implement proper swapping behavior when old or new weapon uses several slots
@ -13,15 +13,11 @@ func _apply(player: Player) -> bool:
slot = player.weapons.current_slot
var set_data = slot.set_weapon(weapon)
set_data.old_weapon.id = id
set_data.new_weapon.id = id
if slot == player.weapons.current_slot:
player.weapons.refresh_current_slot()
return update_by_id(set_data.new_weapon)
# TODO: implement proper updating
func update_by_id(new_id: StringName) -> bool:
id = new_id
return id == ""
var new_res = ResourceHandler.get_resource(set_data.old_weapon) as WeaponPickupableResource
print(new_res)
return new_res