-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.ts
197 lines (182 loc) · 5.46 KB
/
Util.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
import { Gamemode } from './Gamemode';
import { SweetAlertType } from 'sweetalert2';
import Swal from 'sweetalert2';
import Statistics = require('./Statistics');
/**
* @author Kolly Florian
* @version 1.0 - initial
* @classdesc Classe gérant des fonctionnalités pratiques
*/
class Util {
/** l'instance de la classe */
private static instance: Util;
/** le div du tutoriel */
private div: HTMLElement;
/** le mode de jeu actuel */
private gamemode: string;
/** callback lorsque le mode de jeu est changé */
private gamemodeChangedCallback: any;
/**
* @method constructor
*/
private constructor() {
this.div = <HTMLElement>document.getElementById('tutorial');
this.gamemode = Gamemode.Explore;
$('#onclick_gamemode_explore').on('click', () => {
if(this.gamemode !== Gamemode.Explore) {
this.gamemode = Gamemode.Explore;
this.onGameDataChanged();
}
});
$('#onclick_gamemode_train').on('click', () => {
if(this.gamemode !== Gamemode.Train) {
this.gamemode = Gamemode.Train;
this.onGameDataChanged();
}
});
$('#onclick_gamemode_evaluate').on('click', () => {
if(this.gamemode !== Gamemode.Evaluate) {
this.gamemode = Gamemode.Evaluate;
this.onGameDataChanged();
}
});
$('#onclick_gamemode_create').on('click', () => {
if(this.gamemode !== Gamemode.Create) {
this.gamemode = Gamemode.Create;
this.onGameDataChanged();
}
});
}
/**
* Crée une instance de la classe s'il n'y en a pas et la retourne
* @method getInstance
* @return l'instance de la classe
*/
public static getInstance(): Util {
if(!this.instance) {
this.instance = new Util();
}
return this.instance;
}
/**
* Modifie les paramètres graphiques du tutoriel
* @method setTutorialParams
* @param options les options à modifier
*/
public setTutorialParams(options: any): void {
if(options) {
if(options.fontSize) this.div.style.fontSize = options.fontSize;
if(options.fontStyle) this.div.style.fontStyle = options.fontStyle;
if(options.fontFamily) this.div.style.fontFamily = options.fontFamily;
if(options.fontWeight) this.div.style.fontWeight = options.fontWeight;
if(options.color) this.div.style.color = options.color;
if(options.textDecoration) this.div.style.textDecoration = options.textDecoration;
}
}
/**
* Modifie le texte du tutoriel
* @method setTutorialText
* @param text le texte à mettre
*/
public setTutorialText(text: string): void {
this.div.innerHTML = text;
}
/**
* Affiche les inputs dont l'ID est indiqué
* @method showTutorialInputs
* @param ...ids liste des IDs des inputs à afficher
*/
public showTutorialInputs(...ids: Array<string>) {
for(let id of ids) {
$(`#${id}`).show();
}
}
/**
* Cache les inputs dont l'ID est indiqué
* @method hideTutorialInputs
* @param ...ids liste des IDs des inputs à cacher
*/
public hideTutorialInputs(...ids: Array<string>) {
for(let id of ids) {
$(`#${id}`).hide();
}
}
/**
* Affiche une alerte SweetAlert
* @method showAlert
* @param type le type de l'alerte
* @param text le texte de l'alerte
* @param title (opt) le titre de l'alerte
* @param footer (opt) le footer de l'alerte
* @param callback (opt) un callback à effectuer lors de la fermeture de l'alerte
*/
public showAlert(type: SweetAlertType, text: string, title?: string, footer?: string, callback?: any): void {
Swal.fire({
type: type,
title: title || '',
text: text,
footer: footer || '',
onClose: () => {
if(callback) callback();
}
});
}
/**
* Affiche une alerte SweetAlert personnalisée
* @method showAlertPersonnalized
* @param options les options de SweetAlert
*/
public showAlertPersonnalized(options: any): void {
Swal.fire(options);
}
/**
* Bloque l'event par défaut sur l'élément indiqué
* @method preventDefault
* @param e l'event devant être bloqué
*/
public preventDefault(e: Event): void {
e.preventDefault();
}
/**
* Globalise un event interplateforme
* @method globalizeEvent
* @param e l'event à globaliser
* @returns l'event modifié
*/
public globalizeEvent(e: any): Event {
if(e.touches && e.touches[0]) {
e.clientX = e.touches[0].clientX;
e.clientY = e.touches[0].clientY;
}
if(!e.clientX || !e.clientY) {
if(e.originalEvent) {
e.clientX = e.originalEvent.clientX;
e.clientY = e.originalEvent.clientY;
}
}
if(e.type === 'touchmove' || e.type === 'touchstart' || e.buttons === 1) {
e.isPushed = true;
} else {
e.isPushed = false;
}
return e;
}
/**
* Ajoute la méthode a appeler lorsque le mode de jeu ou le degré est modifié
* @method callOnGamemodeChange
* @param callback la méthode à appelé
*/
public callOnGamemodeChange(callback: any): void {
this.gamemodeChangedCallback = callback;
}
public onGameDataChanged(): void {
if(this.gamemode === Gamemode.Train) {
Statistics.addStats(1);
} else if(this.gamemode === Gamemode.Evaluate) {
Statistics.addStats(2);
}
if(this.gamemodeChangedCallback) this.gamemodeChangedCallback();
}
public getGamemode(): string { return this.gamemode; }
}
export = Util;