forked from jaredgrady/CleanRMT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rmt.js
304 lines (292 loc) · 12.3 KB
/
rmt.js
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
"use strict";
const dex = require('./data/dex.js');
const megas = require('./data/megas.js');
const baseImage = require('./data/base-image.js');
const formats = {
"icons": ["https://www.serebii.net/pokedex-sm/icon/", ".png", "iconserebii"],
"shuffle": ["http://www.pkparaiso.com/imagenes/shuffle/sprites/", ".png", "paraiso"],
"xyanimated": ["http://play.pokemonshowdown.com/sprites/xyani/", ".gif"],
"xy": ["http://play.pokemonshowdown.com/sprites/xy/", ".png"],
"smd": ["http://www.serebii.net/supermysterydungeon/pokemon/", ".png", "serebii"],
};
function hash(pokemon, format) {//gets dex number
pokemon = pokemon[0].toUpperCase() + pokemon.substr(1);
if (dex[pokemon]) return dex[pokemon][0];
if (format === "iconserebii") {
if (pokemon === "Charizard-megax") dex[pokemon][0] = "006-mx";
if (pokemon === "Charizard-megay") dex[pokemon][0] = "006-my";
if (pokemon === "Mewtwo-megax") dex[pokemon][0] = "150-mx";
if (pokemon === "Mewtwo-megay") dex[pokemon][0] = "150-my";
if (pokemon === "Deoxys-attack") dex[pokemon][0] = "386a";
if (pokemon === "Deoxys-defense") dex[pokemon][0] = "386d";
if (pokemon === "Deoxys-speed") dex[pokemon][0] = "386s";
if (pokemon === "Rotom-fan") dex[pokemon][0] = "479s";
if (pokemon === "Rotom-frost") dex[pokemon][0] = "479f";
if (pokemon === "Rotom-heat") dex[pokemon][0] = "479h";
if (pokemon === "Rotom-mow") dex[pokemon][0] = "479m";
if (pokemon === "Rotom-wash") dex[pokemon][0] = "479w";
if (pokemon === "Giratina-origin") dex[pokemon][0] = "487o";
if (pokemon === "Shaymin-sky") dex[pokemon][0] = "492s";
if (pokemon === "Basculin-bluestriped") dex[pokemon][0] = "550-b";
if (pokemon === "Darmanitan-zen") dex[pokemon][0] = "555d";
if (pokemon === "Oricorio-pomom") dex[pokemon][0] = "741-p";
if (pokemon === "Oricorio-pau") dex[pokemon][0] = "741-pau";
if (pokemon === "Typenull") dex[pokemon][0] = "772";
if (pokemon === "Jangmoo") dex[pokemon][0] = "782";
if (pokemon === "Hakamoo") dex[pokemon][0] = "783";
if (pokemon === "Kommoo") dex[pokemon][0] = "784";
if (pokemon === "Necrozma-duskmane") dex[pokemon][0] = "800-dm";
if (pokemon === "Necrozma-dawnwings") dex[pokemon][0] = "800-dw";
}
if (format === "paraiso" && ~pokemon.indexOf("mega")) dex[pokemon][0] += "ega";
return pokemon;
}
function removeParenthesizedInfo(line) {
if (!~line.indexOf('(')) return line.trim();
let start = line.indexOf('(') + 1;
let len = line.lastIndexOf(')') - start;
line = line.substr(start, len).trim();
return line;
}
function checkMega(line) {
let pokemon = line[0].toLowerCase();
if (!line[1]) return line[0]; //no item, its not mega
let item = line[1].toLowerCase().trim();
if (!megas[pokemon]) return line[0];
if (megas[pokemon]) {
if (typeof (megas[pokemon]) !== "object" && megas[pokemon] === item) {
return line[0] + '-Mega';
} else if (typeof (megas[pokemon]) === "object") {
if (megas[pokemon][0] === item) return line[0] + '-Mega-X';
else if (megas[pokemon][1] === item) return line[0] + '-Mega-Y';
} else {
return line[0];
}
}
}
function packTeam(importable) {
let team = {
"pokemon": [],
"pokenames": [],
"items": [],
"evs": [],
"abilities": [],
"natures": [],
"moves": [],
"ivs": [],
};
team.importable = importable;
let lines = importable.split('\n');
let data = [];
let dataIndex = 0;
data.push([lines[0]]);
for (let i = 1; i < lines.length; i++) {
if (lines[i].length < 2) continue;
if (lines[i - 1].length < 2) {
dataIndex++;
data.push([lines[i]]);
} else {
data[dataIndex].push(lines[i].trim());
}
}
for (let j = 0; j < data.length; j++) {
for (let k = 0; k < data[j].length; k++) {
let l = data[j][k];
if (k === 0) {
let pokeno = team.pokemon.length;
if (pokeno > team.evs.length) team.evs.push("No EVs");
if (pokeno > team.abilities.length) team.abilities.push("No Ability");
if (pokeno > team.natures.length) team.natures.push("No Nature");
if (pokeno > team.ivs.length) team.ivs.push(false);
let line = l.split(" @ ");
team.pokenames.push(line[0]);
line[0] = removeParenthesizedInfo(line[0]);
team.pokemon.push(checkMega(line));
/* eslint-disable */
line[1] ? team.items.push(line[1].trim()) : team.items.push(false);
/* eslint-enable */
} else if (~l.indexOf("EVs: ")) {
team.evs.push(l.substr(l.indexOf(' ')).trim());
} else if (~l.indexOf("Ability: ")) {
team.abilities.push(l.substr(l.indexOf(' ')).trim());
} else if (~l.indexOf("IVs: ")) {
team.ivs.push(l.substr(l.indexOf(' ')).trim());
} else if (~l.indexOf("Nature")) {
team.natures.push(l.substr(0, l.indexOf(' ')).trim());
} else if (~l.indexOf("- ")) {
let pokeno = team.pokemon.length - 1;
if (team.moves[pokeno]) {
team.moves[pokeno].push(l.substr(l.indexOf(" ")).trim());
} else {
team.moves.push([l.substr(l.indexOf(" ")).trim()]);
}
}
}
}
let pokeno = team.pokemon.length;
if (pokeno > team.evs.length) team.evs.push("No EVs");
if (pokeno > team.abilities.length) team.abilities.push("No Ability");
if (pokeno > team.natures.length) team.natures.push("No Nature");
if (pokeno > team.ivs.length) team.ivs.push(false);
return team;
}
function getImgs(format, team) {
let output = "";
if (typeof (team) !== "object") team = packTeam(team);
let pokemon = team.pokemon;
for (let j = 0; j < pokemon.length; j++) {
output += getImg(format, pokemon[j].toLowerCase());
}
return output;
}
function getImg(format, pokemon) {
if (!formats[format]) return;
if (pokemon === "mime jr.") pokemon = "mimejr";
if (pokemon === "charizard-mega-x") pokemon = "charizard-megax";
if (pokemon === "charizard-mega-y") pokemon = "charizard-megay";
if (pokemon === "raticate-alola-totem") pokemon = "raticate-alola";
if (["pikachu-pop-star", "pikachu-phd", "pikachu-rock-star", "pikachu-libre"].includes(pokemon)) pokemon = "pikachu-cosplay";
if (pokemon === "marowak-alola-totem") pokemon = "marowak-alola";
if (pokemon === "mewtwo-mega-x") pokemon = "mewtwo-megax";
if (pokemon === "mewtwo-mega-y") pokemon = "mewtwo-megay";
if (pokemon === "basculin-blue-striped") pokemon = "basculin-bluestriped";
if (pokemon === "zygarde-10%") pokemon = "zygarde-10";
if (pokemon === "gumshoos-totem") pokemon = "gumshoos";
if (pokemon === "vikavolt-totem") pokemon = "totem";
if (pokemon === "oricorio-pom-pom") pokemon = "oricorio-pompom";
if (pokemon === "oricorio-pa'u") pokemon = "oricorio-pau";
if (pokemon === "ribombee-totem") pokemon = "ribombee";
if (pokemon === "araquanid-totem") pokemon = "araquanid";
if (pokemon === "lurantis-totem") pokemon = "lurantis";
if (pokemon === "salazzle-totem") pokemon = "salazzle";
if (pokemon === "type: null") pokemon = "typenull";
if (pokemon === "togedemaru-totem") pokemon = "togedemaru";
if (pokemon === "mimikyu-totem") pokemon = "mimikyu";
if (pokemon === "mimikyu-busted-totem") pokemon = "mimikyu-busted";
if (pokemon === "jangmo-o") pokemon = "jangmoo";
if (pokemon === "salazzle-totem") pokemon = "hakamoo";
if (pokemon === "kommo-o") pokemon = "kommoo";
if (pokemon === "kommo-o-totem") pokemon = "kommoo";
if (pokemon === "necrozma-dusk-mane") pokemon = "necrozma-duskmane";
if (pokemon === "necrozma-dawn-wings") pokemon = "necrozma-dawnwings";
// if (baseImage[pokemon]) format = 'xyanimated';
// let fdata = formats[format];
return '[img]' + formats[format][0] + (formats[format][2] ? hash(pokemon, formats[format][2]) : pokemon) + formats[format][1] + '[/img]';
}
function toTitle(text, options) { //This function is a disaster lol
let output = "[" + options.align + "][FONT=" + options.tfont + "][SIZE=" + options.size + "]";
if (options.bold) output += "[B]";
if (options.underlined) output += "[U]";
if (options.bold === "first") text = text[0] + "[/B]" + text.substr(1);
output += text;
if (options.bold && options.bold !== "first") output += "[/B]";
if (options.underlined) output += "[/U]";
output += "[/SIZE][/FONT][/" + options.align + "]";
return output;
}
function buildingProcess(format, pokemon, f, fe) {
let output = ["", "", "", "", "", ""];
for (let i = 0; i < pokemon.length; i++) {
let img = getImg(format, pokemon[i].toLowerCase());
for (let j = i; j < pokemon.length; j++) {
output[j] += img;
}
}
for (let k = 0; k < output.length; k++) {
output[k] += "\n" + f + "**Why did you choose this pokemon?**" + fe + "\n";
}
return output.join("");
}
/* eslint-disable */
function buildSets(data, options, f, fe) {
let output = "";
switch (options.setFormat) {
case 'importable': //default
for (let i = 0; i < data.pokemon.length; i++) {
output += "[" + options. align + "]" + getImg(options.imgFormat, data.pokemon[i].toLowerCase()) + "\n" +
data.pokenames[i] + " @ " + data.items[i] + "\n" +
"Ability: " + data.abilities[i] + "\n" +
"EVs: " + data.evs[i] + "\n" +
data.natures[i] + " Nature \n" +
(data.ivs[i] ? "IVs: " + data.ivs[i] + "\n" : "");
for (let k = 0; k < data.moves[i].length; k++) {
output += "- " + data.moves[i][k] + "\n";
}
output += "[/" + options.align + "]\n" + f + "" + f + "**Why did you choose this pokemon? What does it do for your team?**" + fe + "" + fe + "\n\n";
}
break;
case 'bold-importable': //default with bold
for (let i = 0; i < data.pokemon.length; i++) {
output += "[LEFT]" + getImg(options.imgFormat, data.pokemon[i].toLowerCase()) + "\n" +
"[B]" + data.pokenames[i] + "[/B]" + (data.items[i] ? " @ " + data.items[i] : "") + "\n" +
"[B]Ability:[/B] " + data.abilities[i] + "\n" +
"[B]Nature:[/B] " + data.natures[i] + "\n" +
"[B]EVs:[/B] " + data.evs[i] + "\n" +
(data.ivs[i] ? "[B]IVs:[/B] " + data.ivs[i] + "\n" : "") +
"[B]Moves:[/B] ";
for (let k = 0; k < data.moves[i].length; k++) {
if (k !== 0) output += " | ";
output += data.moves[i][k];
}
output += "[/LEFT]\n\n" + f + "**Why did you choose this pokemon? What does it do for your team?**" + fe + "\n\n";
}
break;
case 'alternative': //trinitrotoluene
for (let i = 0; i < data.pokemon.length; i++) {
output += "[B][SIZE=2][LEFT][INDENT]" + getImg(options.imgFormat, data.pokemon[i].toLowerCase()) + "[/INDENT]\n" +
data.pokenames[i] + (data.items[i] ? " @ " + data.items[i] : "") + " | " +
data.abilities[i] + "\n" +
data.natures[i] + " | " +
data.evs[i] + "\n" +
(data.ivs[i] ? "IVs: " + data.ivs[i] + "\n" : "");
for (let k = 0; k < data.moves[i].length; k++) {
output += "• " + data.moves[i][k] + "\n";
}
output += "[/B][/SIZE][/LEFT]" + f + "**Why did you choose this pokemon? What does it do for your team?**" + fe + "\n\n";
}
break;
case 'pearl': //Pearl
for (let i = 0; i < data.pokemon.length; i++) {
output += "[SIZE=2][CENTER]" + getImg(options.imgFormat, data.pokemon[i].toLowerCase()) + "\n" +
(data.items[i] ?
"@ [IMG]http://www.serebii.net/itemdex/sprites/" + data.items[i].toLowerCase().split(" ").join("") + ".png[/IMG]\n" :
"") +
"[B]Ability-[/B] " + data.abilities[i] + "\n" +
"[B]EVs-[/B] " + data.evs[i].split(' / ').join(' | ') + "\n" +
(data.ivs[i] ? "[B]IVs-[/B] " + data.ivs[i] + "\n" : "") +
"[B]Nature- [/B]" + data.natures[i] + "\n\n";
for (let k = 0; k < data.moves[i].length; k++) {
if (k !== 0) output+= " | ";
output += data.moves[i][k];
}
output += "[/SIZE][/CENTER]\n" + f + "**Why did you choose this pokemon? What does it do for your team?**" + fe + "\n\n";
}
break;
}
return output;
}
/* eslint-enable */
function rmt(team, options) {
let data = packTeam(team);
options.align = options.align.toUpperCase(); //easier than doing this client-side
options.size = parseInt(options.size);
options.process = options.process === 'true';
options.bold = options.bold === 'true';
options.underlined = options.underlined === 'true';
let f = "[FONT=" + options.font + "]";
let fe = "[/FONT]";
let output = "";
output += "[center]" + getImgs(options.imgFormat, data) + "[/center]\n\n" +
toTitle("Introduction", options) + "\n\n" + f + "**Introduction goes here**" + fe + "\n\n";
if (options.process) {
output += toTitle("Teambuilding Process", options) + "\n\n" +
"[hide]" + buildingProcess(options.processFormat, data.pokemon, f, fe) + "[/hide]\n" +
"\n" + toTitle("The Team", options) + "\n\n";
}
output += buildSets(data, options, f, fe);
output += toTitle("Conclusion", options) + "\n\n" + f + "**Conclusion goes here**" + fe + "\n\n" +
"[hide=Importable]" + data.importable + "[/hide]";
return output;
}
module.exports.rmt = rmt;
module.exports.getImgs = getImgs;