-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinventory_slot.gd
52 lines (41 loc) · 1.41 KB
/
inventory_slot.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
extends Node2D
class_name InventorySlot
@export var held_item:Item = null
@export var accepted_item_types:Array[Item.Type] = [Item.Type.FOOD, Item.Type.CLOTHING]
@export var normal_color:Color
@export var reject_color:Color
@export var accept_color:Color
signal AcceptedItem(item:Item)
signal RemovedItem(item:Item)
# Called when the node enters the scene tree for the first time.
func _ready():
$DropArea.will_accept = self.will_accept
func will_accept(draggable:Draggable):
if not draggable.owner_class is Item:
return false
var as_item:Item = draggable.owner_class
return as_item.item_type in accepted_item_types
func OnHover(draggable:Draggable, accepted:bool):
if accepted:
$DropArea.debug_color = accept_color
else:
$DropArea.debug_color = reject_color
func OnStopHover(draggable:Draggable, accepted:bool):
$DropArea.debug_color = normal_color
func RecieveItem(draggable:Draggable):
if not draggable.owner_class is Item:
return
var new_item:Item = draggable.owner_class
held_item = new_item
held_item.ChangedInventory.connect(RemoveItem)
AcceptedItem.emit(held_item)
func RemoveItem(from:InventorySlot, to:InventorySlot):
if to == self:
return
var old_item = held_item
held_item.ChangedInventory.disconnect(RemoveItem)
held_item = null
RemovedItem.emit(old_item)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass