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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
extends Node
class_name PlayerInventory
@export var action : PlayerAction
@export var machette_pivot : Node2D
@export var bow : Node2D
@export var bow_cooldown : float = 0.35
@export var machette : Node2D
@export var machette_cooldown : float = 0.2
@export var masks : Array[Node2D]
enum MaskType {
Dash = 0,
Grapple = 1,
Freeze = 3,
Minions = 2,
}
var prev_inv : Array[int] = [-1, -1, -1, -1, -1, -1]
@export var mask_inventory : Array[int] = [-1, -1, -1, -1, -1, -1]
var has_machette : bool = false
var using_bow : bool = true
func _ready():
UIConnector.update_masks(mask_inventory)
func _input(_event: InputEvent) -> void:
if Input.is_action_just_pressed("switch_tool") && has_machette:
UIConnector.switch_tool()
if using_bow:
action.curr_weapon = machette
machette_pivot.visible = true
bow.visible = false
machette.process_mode = Node.PROCESS_MODE_INHERIT
bow.process_mode = Node.PROCESS_MODE_DISABLED
action.get_node("Cooldown").wait_time = machette_cooldown
else:
action.curr_weapon = bow
machette_pivot.visible = false
bow.visible = true
machette.process_mode = Node.PROCESS_MODE_DISABLED
bow.process_mode = Node.PROCESS_MODE_INHERIT
action.get_node("Cooldown").wait_time = bow_cooldown
using_bow = !using_bow
if Input.is_action_just_pressed("switch_mask"):
var curr_mask = mask_inventory[0]
mask_inventory[0] = mask_inventory[1]
mask_inventory[1] = curr_mask
UIConnector.update_masks(mask_inventory)
$"../PlayerMovement".grapple_velocity = Vector2.ZERO
func _process(_delta: float) -> void:
if prev_inv.hash() != mask_inventory.hash():
print("changed")
for mask in masks:
mask.visible = false
mask.process_mode = Node.PROCESS_MODE_DISABLED
if mask_inventory[0] != -1:
print("YEAH")
masks[mask_inventory[0]].visible = true
masks[mask_inventory[0]].process_mode = Node.PROCESS_MODE_INHERIT
prev_inv = mask_inventory.duplicate()
func give_machette() -> void:
has_machette = true
UIConnector.add_machette()
func ungive_machette() -> void:
has_machette = false
UIConnector.remove_machette()
func add_mask(mask : MaskType):
print("the mask is ", mask)
if !(mask in mask_inventory):
for i in range(2, 6):
if mask_inventory[i] == -1:
mask_inventory[i] = mask
break
UIConnector.update_masks(mask_inventory)
UIConnector.show_mask_bubble()
|