/
StatusComponent.ts
170 lines (130 loc) · 5.85 KB
/
StatusComponent.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
import {BitmapText} from "phaser-ce";
import {elemental_stats} from "../Player";
import {Djinn, djinn_status} from "../Djinn";
import {GoldenSun} from "../GoldenSun";
import {MainChar} from "../MainChar";
import {MainStatusMenu} from "../main_menus/MainStatusMenu";
import {directions, elements, reverse_directions} from "../utils";
import {Window} from "../Window";
import {BattleStatusWindow} from "../windows/battle/BattleStatusWindow";
export enum StatusModes {
BATTLE,
MENU,
}
export abstract class StatusComponent {
protected static readonly GROUP_KEY = "status_component";
protected game: Phaser.Game;
protected data: GoldenSun;
protected window: Window;
protected current_line: number;
protected current_col: number;
protected mode: StatusModes;
protected highlight: Phaser.Graphics;
protected state_sprites: (Phaser.Sprite | BitmapText | Phaser.Group)[];
protected manager: BattleStatusWindow | MainStatusMenu;
public constructor(
game: Phaser.Game,
data: GoldenSun,
window: Window,
manager: BattleStatusWindow | MainStatusMenu,
pos?: {line: number; col: number},
mode?: StatusModes
) {
this.game = game;
this.data = data;
this.window = window;
this.mode = mode ? mode : StatusModes.BATTLE;
if (this.mode === StatusModes.BATTLE) this.manager = this.manager as BattleStatusWindow;
else if (this.mode === StatusModes.MENU) this.manager = this.manager as MainStatusMenu;
if (!this.window.get_internal_group(StatusComponent.GROUP_KEY))
this.window.define_internal_group(StatusComponent.GROUP_KEY, {x: 0, y: 0});
this.highlight = this.game.add.graphics(0, 0);
this.highlight.blendMode = PIXI.blendModes.SCREEN;
this.window.add_to_internal_group(StatusComponent.GROUP_KEY, this.highlight);
this.state_sprites = [];
this.manager = manager;
this.current_col = pos ? pos.col : 0;
this.current_line = pos ? pos.line : 0;
}
public abstract select_option(): void;
public abstract on_change(): void;
public abstract on_left(): void;
public abstract on_right(): void;
public abstract on_up(): void;
public abstract on_down(): void;
public abstract initialize(): void;
protected get selected_char(): MainChar {
let manager = null;
if (this.mode === StatusModes.BATTLE) manager = this.manager as BattleStatusWindow;
else if (this.mode === StatusModes.MENU) manager = this.manager as MainStatusMenu;
return manager.selected_character;
}
protected get battle_status_effects() {
let manager = null;
if (this.mode === StatusModes.BATTLE) manager = this.manager as BattleStatusWindow;
else if (this.mode === StatusModes.MENU) manager = this.manager as MainStatusMenu;
return manager.battle_effects_array;
}
protected update_description(line1: string, line2?: string) {
let manager = null;
if (this.mode === StatusModes.BATTLE) manager = this.manager as BattleStatusWindow;
else if (this.mode === StatusModes.MENU) manager = this.manager as MainStatusMenu;
manager.update_description(line1, line2);
}
protected update_highlight(highlight: {x: number; y: number; width: number; height: number}) {
this.highlight.clear();
this.highlight.beginFill(this.window.color, 1);
this.highlight.drawRect(highlight.x, highlight.y, highlight.width, highlight.height);
this.highlight.endFill();
}
public get current_pos() {
return {line: this.current_line, col: this.current_col};
}
public reset(pos?: {line: number; col: number}, keep_separator?: boolean) {
if (pos) {
this.current_line = pos.line;
this.current_col = pos.col;
}
this.clear(keep_separator);
this.initialize();
this.select_option();
this.on_change();
}
public clear(keep_separator?: boolean) {
this.highlight.clear();
this.data.cursor_manager.hide();
for (let index in this.state_sprites) {
this.state_sprites[index].destroy();
}
this.state_sprites = [];
if (this.window.page_indicator.is_set) this.window.page_indicator.terminante();
if (!keep_separator) this.window.clear_separators();
}
protected get_djinn_counts(element: elements) {
const djinn = this.selected_char.djinn_by_element[element].map(
(djinn_key: string) => this.data.info.djinni_list[djinn_key]
);
return {
total: djinn.length,
set: djinn.filter((djinni: Djinn) => djinni.status === djinn_status.SET).length,
};
}
protected get_elemental_stats(element: elements) {
const elemental_level = this.selected_char.elemental_current[elemental_stats.LEVEL][element];
const elemental_power = this.selected_char.elemental_current[elemental_stats.POWER][element];
const elemental_resistance = this.selected_char.elemental_current[elemental_stats.RESIST][element];
return {level: elemental_level, power: elemental_power, resistance: elemental_resistance};
}
protected get_djinni_sprite(elem: elements, group: Phaser.Group, pos: {x: number; y: number}) {
const djinn_sprite_base = this.data.info.npcs_sprite_base_list[Djinn.sprite_base_key(elem)];
const action_key = djinn_sprite_base.getSpriteKey(djinn_status.SET);
const sprite = group.create(pos.x, pos.y, action_key);
sprite.anchor.setTo(0.5, 1.0);
sprite.scale.x = -1;
const direction = reverse_directions[directions.down];
const action = djinn_status.SET;
djinn_sprite_base.setAnimation(sprite, action);
sprite.animations.play(djinn_sprite_base.getAnimationKey(action, direction));
return sprite;
}
}