/
MainStatusPsynergy.ts
246 lines (193 loc) · 8.56 KB
/
MainStatusPsynergy.ts
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import {StatusComponent} from "./StatusComponent";
import {TextObj, Window} from "../Window";
import {GoldenSun} from "../GoldenSun";
import {CursorManager, PointVariants} from "../utils/CursorManager";
import {Ability} from "../Ability";
import {MainStatusMenu} from "../main_menus/MainStatusMenu";
export class MainStatusPsynergy extends StatusComponent {
private static readonly CURSOR = {
X: 65,
Y: 66,
};
private static readonly HIGHLIGHT = {
X: 80,
Y: 24,
WIDTH: 152,
HEIGHT: 8,
};
private static readonly PSYNERGY = {
ICON_X: 81,
ICON_Y: 19,
NAME_X: 96,
NAME_Y: 24,
PP_LABEL_X: 184,
PP_LABEL_Y: 8,
PP_VALUE_END_X: 194,
PP_VALUE_Y: 24,
STAR_X: 201,
STAR_Y: 25,
RANGE_CENTER_X: 220,
RANGE_Y: 24,
};
private static readonly USE_TEXT = {
X: 8,
Y: 104,
};
private static readonly MAX_LINES = 5;
private static readonly SHIFT = 16;
private ability_pages: Ability[][];
private use_text: TextObj;
public constructor(
game: Phaser.Game,
data: GoldenSun,
window: Window,
manager: MainStatusMenu,
pos?: {line: number; col: number}
) {
super(game, data, window, manager, pos);
}
public select_option() {
const highlight = {
x: MainStatusPsynergy.HIGHLIGHT.X,
y: MainStatusPsynergy.HIGHLIGHT.Y + MainStatusPsynergy.SHIFT * this.current_line,
width: MainStatusPsynergy.HIGHLIGHT.WIDTH,
height: MainStatusPsynergy.HIGHLIGHT.HEIGHT,
};
this.update_highlight(highlight);
const cursor_x = MainStatusPsynergy.CURSOR.X;
const cursor_y = MainStatusPsynergy.CURSOR.Y + MainStatusPsynergy.SHIFT * this.current_line;
const cursor_tween = {type: CursorManager.CursorTweens.POINT, variant: PointVariants.NORMAL};
this.data.cursor_manager.move_to({x: cursor_x, y: cursor_y}, {animate: false, tween_config: cursor_tween});
this.window.page_indicator.select_page(this.current_col);
}
public on_change() {
if (!this.ability_pages[this.current_col][this.current_line])
this.current_line = this.ability_pages[this.current_col].length - 1;
const chosen_ability = this.ability_pages[this.current_col][this.current_line];
this.select_option();
this.update_description(chosen_ability.description);
let use_text = "Can be used in ";
if (chosen_ability.is_field_psynergy || chosen_ability.effects_outside_battle) use_text += "Towns";
else use_text += "Battle";
this.window.update_text(use_text, this.use_text);
}
public on_left() {
if (this.ability_pages.length <= 1) return;
const pages = this.ability_pages.length;
this.current_col = (this.current_col + pages - 1) % pages;
if (!this.ability_pages[this.current_col][this.current_line])
this.current_line = this.ability_pages[this.current_col].length - 1;
this.reset();
}
public on_right() {
if (this.ability_pages.length <= 1) return;
const pages = this.ability_pages.length;
this.current_col = (this.current_col + 1) % pages;
if (!this.ability_pages[this.current_col][this.current_line])
this.current_line = this.ability_pages[this.current_col].length - 1;
this.reset();
}
public on_up() {
if (this.ability_pages[this.current_col].length <= 1) return;
const len = this.ability_pages[this.current_col].length;
this.current_line = (this.current_line + len - 1) % len;
this.on_change();
}
public on_down() {
if (this.ability_pages[this.current_col].length <= 1) return;
const len = this.ability_pages[this.current_col].length;
this.current_line = (this.current_line + 1) % len;
this.on_change();
}
public initialize() {
this.update_abilities();
if (!this.ability_pages[this.current_col]) this.current_col = this.ability_pages.length - 1;
const abilities = this.ability_pages[this.current_col];
abilities.forEach((ability, index) => {
const icon_key = ability.key_name;
const name = ability.name;
const pp_cost = ability.pp_cost;
const range = String(ability.range);
let x_pos = MainStatusPsynergy.PSYNERGY.ICON_X;
let y_pos = MainStatusPsynergy.PSYNERGY.ICON_Y + index * MainStatusPsynergy.SHIFT;
const icon = this.window.create_at_group(x_pos, y_pos, "abilities_icons", {
frame: icon_key,
internal_group_key: MainStatusPsynergy.GROUP_KEY,
});
this.state_sprites.push(icon);
x_pos = MainStatusPsynergy.PSYNERGY.NAME_X;
y_pos = MainStatusPsynergy.PSYNERGY.NAME_Y + index * MainStatusPsynergy.SHIFT;
const name_text = this.window.set_text_in_position(name, x_pos, y_pos, {
internal_group_key: MainStatusPsynergy.GROUP_KEY,
});
this.state_sprites.push(name_text.text, name_text.shadow);
x_pos = MainStatusPsynergy.PSYNERGY.PP_VALUE_END_X;
y_pos = MainStatusPsynergy.PSYNERGY.PP_VALUE_Y + index * MainStatusPsynergy.SHIFT;
const pp_value = this.window.set_text_in_position(String(pp_cost), x_pos, y_pos, {
right_align: true,
internal_group_key: MainStatusPsynergy.GROUP_KEY,
});
this.state_sprites.push(pp_value.text, pp_value.shadow);
x_pos = MainStatusPsynergy.PSYNERGY.STAR_X;
y_pos = MainStatusPsynergy.PSYNERGY.STAR_Y + index * MainStatusPsynergy.SHIFT;
const star = this.window.create_at_group(x_pos, y_pos, "stars", {
frame: ability.element,
internal_group_key: MainStatusPsynergy.GROUP_KEY,
});
this.state_sprites.push(star);
x_pos = MainStatusPsynergy.PSYNERGY.RANGE_CENTER_X;
y_pos = MainStatusPsynergy.PSYNERGY.RANGE_Y + index * MainStatusPsynergy.SHIFT;
const range_icon = this.window.create_at_group(x_pos, y_pos, "ranges", {
frame: range,
internal_group_key: MainStatusPsynergy.GROUP_KEY,
});
range_icon.x -= (range_icon.width / 2) | 0;
this.state_sprites.push(range_icon);
});
let x_pos = MainStatusPsynergy.PSYNERGY.PP_LABEL_X;
let y_pos = MainStatusPsynergy.PSYNERGY.PP_LABEL_Y;
const pp_label = this.window.set_text_in_position("PP", x_pos, y_pos, {
internal_group_key: MainStatusPsynergy.GROUP_KEY,
});
this.state_sprites.push(pp_label.text, pp_label.shadow);
x_pos = MainStatusPsynergy.USE_TEXT.X;
y_pos = MainStatusPsynergy.USE_TEXT.Y;
this.use_text = this.window.set_text_in_position("", x_pos, y_pos, {
internal_group_key: MainStatusPsynergy.GROUP_KEY,
});
this.state_sprites.push(this.use_text.text, this.use_text.shadow);
this.window.page_indicator.initialize(this.ability_pages.length, this.current_line);
this.select_option();
}
private update_abilities() {
const all_abilities = this.selected_char.abilities;
const battle_psy = all_abilities.filter((key_name: string) => {
const a = this.data.info.abilities_list[key_name];
if (!a) return true;
return !(a.is_field_psynergy || a.effects_outside_battle);
});
const field_psy = all_abilities.filter((key_name: string) => {
const a = this.data.info.abilities_list[key_name];
if (!a) return false;
return a.is_field_psynergy || a.effects_outside_battle;
});
const sorted_abilities = field_psy.concat(battle_psy);
let page_abilities = [];
this.ability_pages = [];
let count = 0;
sorted_abilities.forEach((key_name: string) => {
if (count === MainStatusPsynergy.MAX_LINES) {
this.ability_pages.push(page_abilities);
page_abilities = [];
count = 0;
}
if (!this.data.info.abilities_list[key_name]) {
this.data.logger.log_message(`Ability "${key_name}" does not exist in the database.`);
} else {
page_abilities.push(this.data.info.abilities_list[key_name]);
count++;
}
});
if (page_abilities.length > 0) this.ability_pages.push(page_abilities);
}
}