Untested PickupableItem

This commit is contained in:
Alexey 2025-07-31 15:33:31 +03:00
commit 63e87e86d5
19 changed files with 200 additions and 17 deletions

View file

@ -0,0 +1,13 @@
extends Resource
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

View file

@ -0,0 +1 @@
uid://cfovybsk5c606

View file

@ -0,0 +1,26 @@
extends Sprite3D
class_name InteractiveObject
var player: Player = null
func _ready() -> void:
pass
func _process(_delta: float) -> void:
if player == null:
return
if Input.is_action_just_pressed('interact'):
_interact(player)
func _on_body_entered(body: Node3D) -> void:
if body is Player:
player = body
func _on_body_exited(body: Node3D) -> void:
if body is Player:
player = null
## Invoked when interact action was used when player is in object's area
func _interact(_player: Player) -> void:
pass

View file

@ -0,0 +1 @@
uid://junnt60g6c7x

View file

@ -0,0 +1,13 @@
extends InteractiveObject
class_name PickupableItem
@export var content: BasePickupableResource
func _ready() -> void:
if content.texture != null:
texture = content.texture
func _interact(_player: Player) -> void:
if content._apply(_player):
queue_free()

View file

@ -0,0 +1 @@
uid://v2v4keo0ydlc

View file

@ -0,0 +1,27 @@
extends BasePickupableResource
class_name WeaponPickupableResource
## Weapon that will be added on interaction
@export var weapon: PackedScene
func _apply(player: Player) -> bool:
var slot = player.weapons.first_free_slot()
# TODO: Implement proper swapping behavior when old or new weapon uses several slots
if slot == null:
slot = player.weapons.current_slot
var set_data = slot.set_weapon(weapon)
set_data.old_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 == ""

View file

@ -0,0 +1 @@
uid://dob8q3jclxrtd