26 lines
708 B
TypeScript
26 lines
708 B
TypeScript
import { Node, Variant } from 'godot'
|
|
import { export_, export_range } from 'godot.annotations'
|
|
import ItemData from './item_data'
|
|
import Interactor from './interactor'
|
|
import Inventory from './inventory'
|
|
|
|
export default class ItemPickup extends Node {
|
|
@export_(Variant.Type.TYPE_OBJECT, { class_: ItemData })
|
|
readonly resource!: ItemData
|
|
|
|
@export_range(0, 99)
|
|
readonly quantity: number = 1
|
|
|
|
add_to_inventory(interactor: Interactor) {
|
|
const inventory = Inventory.find_inventory(interactor.root_node)
|
|
|
|
if (inventory) {
|
|
inventory.add(this.resource, this.quantity)
|
|
} else {
|
|
console.error(interactor.root_node.get_name(), 'has no inventory')
|
|
}
|
|
|
|
this.queue_free()
|
|
}
|
|
}
|
|
|