-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inventory.adept
153 lines (127 loc) · 4.74 KB
/
Inventory.adept
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import 'main.adept'
struct MaybePet (struct Pet, has bool)
struct Inventory (shown bool, position, count int, moving, lock bool, pets 8 MaybePet, info Label) {
func init {
this.shown = false
this.position = 0
this.count = 8
this.moving = false
this.lock = true
this.info.clear()
}
func update {
original_position int = this.position
if captKeyHeld(GLFW_KEY_LEFT) {
unless this.lock {
this.position = this.position == 0 ? this.count - 1 : this.position - 1
this.lock = true
if this.moving, this.swapPets(original_position, this.position)
}
} else if captKeyHeld(GLFW_KEY_RIGHT) {
unless this.lock {
this.position = this.position == this.count - 1 ? 0 : this.position + 1
this.lock = true
if this.moving, this.swapPets(original_position, this.position)
}
} else if captKeyHeld(GLFW_KEY_UP) {
unless this.lock {
this.moving = true
this.lock = true
}
} else if captKeyHeld(GLFW_KEY_DOWN) {
unless this.lock {
if !this.moving && this.getTotalPets() > 1, this.pets[this.position].has = false
this.moving = false
this.lock = true
}
} else {
this.lock = false
}
if this.pets[this.position].has {
pet *Pet = cast *Pet &this.pets[this.position]
this.info.set(pet.getName() + "\n" + pet.getHealthBar() + "\n" + pet.getXpBar())
} else {
this.info.set("")
}
}
func addPetInBucket(pet POD Pet, bucket int) successful {
if this.pets[bucket].has, return false
*cast *Pet &this.pets[bucket] = pet
this.pets[bucket].has = true
return true
}
func removePetInBucket(bucket int) {
this.pets[bucket].has = false
}
func getPetInBucket(bucket int) MaybePet {
return this.pets[bucket]
}
func addPet(pet POD Pet) successful {
repeat this.count {
unless this.pets[idx].has {
*cast *Pet &this.pets[idx] = pet
this.pets[idx].has = true
return true
}
}
return false
}
func removePet(index int) {
counted int = 0
repeat this.count {
if this.pets[idx].has {
if counted == index, this.pets[idx].has = false; return
counted++
}
}
}
func getPet(index int) Pet {
return *this.getPetPointer(index)
}
func getPetPointer(index int) *Pet {
counted int = 0
repeat this.count {
if this.pets[idx].has {
if counted == index, return cast *Pet &this.pets[idx]
counted++
}
}
print("ERROR: Inventory.getPet() got bad index, giving first bucket")
return cast *Pet &this.pets[0]
}
func getTotalPets int {
amount int = 0
repeat this.count, if this.pets[idx].has, amount++
return amount
}
func swapPets(index1, index2 int) {
tmp POD MaybePet = POD this.pets[index1]
this.pets[index1] = POD this.pets[index2]
this.pets[index2] = POD tmp
}
func clear {
repeat this.count, this.pets[idx].has = false
}
func draw {
inventory_x float = 64.0f
inventory_y float = 64.0f
drawTiled(textures.inventory, inventory_x, inventory_y, 32.0f, 32.0f, 512.0f, 352.0f)
//captDrawTexture(textures.inventory_selection, inventory_x + 64.0f, inventory_y + 64.0f, 40.0f, 40.0f)
//repeat 8,
// captDrawTexture(textures.inventory_slot, inventory_x + 64.0f + 48.0f * idx as float, inventory_y + 64.0f, 40.0f, 40.0f)
repeat this.count {
texture CaptTexture = this.position == idx as int ? textures.inventory_selection : textures.inventory_slot
x_offset float = 64.0f + 48.0f * idx as float
y_offset float = 64.0f + cast float !(this.position == idx as int && this.moving) * 48.0f
captDrawTexture(texture, inventory_x + x_offset, inventory_y + y_offset, 40.0f, 40.0f)
if this.pets[idx].has {
captDrawTexture(this.pets[idx].texture, inventory_x + x_offset + 4.0f, inventory_y + y_offset + 4.0f, 32.0f, 32.0f)
}
}
this.info.draw(64.0f + 64.0f, 256.0f)
}
func toggle {
this.shown = !this.shown
if this.shown, this.moving = false
}
}