Untested PickupableItem
This commit is contained in:
parent
a2c062e8bb
commit
63e87e86d5
19 changed files with 200 additions and 17 deletions
13
base/scripts/interactive/base_pickupable_resource.gd
Normal file
13
base/scripts/interactive/base_pickupable_resource.gd
Normal 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
|
1
base/scripts/interactive/base_pickupable_resource.gd.uid
Normal file
1
base/scripts/interactive/base_pickupable_resource.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://cfovybsk5c606
|
26
base/scripts/interactive/interactive_object.gd
Normal file
26
base/scripts/interactive/interactive_object.gd
Normal 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
|
1
base/scripts/interactive/interactive_object.gd.uid
Normal file
1
base/scripts/interactive/interactive_object.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://junnt60g6c7x
|
13
base/scripts/interactive/pickupable_item.gd
Normal file
13
base/scripts/interactive/pickupable_item.gd
Normal 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()
|
1
base/scripts/interactive/pickupable_item.gd.uid
Normal file
1
base/scripts/interactive/pickupable_item.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://v2v4keo0ydlc
|
27
base/scripts/interactive/weapon_pickupable_resource.gd
Normal file
27
base/scripts/interactive/weapon_pickupable_resource.gd
Normal 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 == ""
|
|
@ -0,0 +1 @@
|
|||
uid://dob8q3jclxrtd
|
Loading…
Add table
Add a link
Reference in a new issue