forked from smogon/pokemon-showdown-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-minidex
executable file
·89 lines (73 loc) · 2.36 KB
/
build-minidex
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
#!/usr/bin/env node
'use strict';
const fs = require("fs");
process.chdir(__dirname);
const imageSize = require('image-size');
const Tools = require('./../data/Pokemon-Showdown/tools').includeData();
const toId = Tools.getId;
let buf = `/*
DO NOT EDIT
THIS FILE IS AUTOGENERATED BY ./githooks/build-minidex
*/
exports.BattlePokemonSprites = {
substitute:{exists:false, front:{w:34, h:39}, back:{w:37, h:38}},
`;
let g5buf = `/*
DO NOT EDIT
THIS FILE IS AUTOGENERATED BY ./githooks/build-minidex
*/
exports.BattlePokemonSpritesBW = {
`;
function sizeObj(path) {
try {
let size = imageSize(path);
return {
w: size.width,
h: size.height
};
} catch (e) {}
}
for (let baseid in Tools.data.Pokedex) {
let template = Tools.getTemplate(baseid);
for (let formid of [''].concat(template.otherForms || [])) {
let spriteid = template.spriteid;
if (formid) spriteid += '-' + formid.slice(template.id.length);
let id = toId(spriteid);
{
let row = {num: template.num};
const frontSize = sizeObj('../sprites/xyani/' + spriteid + '.gif');
if (frontSize) row.front = frontSize;
const frontSizeF = sizeObj('../sprites/xyani/' + spriteid + '-f.gif');
if (frontSizeF) row.frontf = frontSizeF;
const backSize = sizeObj('../sprites/xyani-back/' + spriteid + '.gif');
if (backSize) row.back = backSize;
const backSizeF = sizeObj('../sprites/xyani-back/' + spriteid + '-f.gif');
if (backSizeF) row.backf = backSizeF;
if (row.front || row.back || !row.forme) {
buf += `\t${id}:` + JSON.stringify(row).replace(/"/g, '') + `,\n`;
}
}
{
let g5row = {num: template.num};
const frontSize = sizeObj('../sprites/bwani/' + spriteid + '.gif');
if (frontSize) g5row.front = frontSize;
const frontSizeF = sizeObj('../sprites/bwani/' + spriteid + '-f.gif');
if (frontSizeF) g5row.frontf = frontSizeF;
const backSize = sizeObj('../sprites/bwani-back/' + spriteid + '.gif');
if (backSize) g5row.back = backSize;
const backSizeF = sizeObj('../sprites/bwani-back/' + spriteid + '-f.gif');
if (backSizeF) g5row.backf = backSizeF;
if (g5row.front || g5row.back || !g5row.forme) {
g5buf += `\t${id}:` + JSON.stringify(g5row).replace(/"/g, '') + `,\n`;
}
}
}
}
buf = buf.slice(0, -2) + `
};
`;
g5buf = g5buf.slice(0, -2) + `
};
`;
fs.writeFileSync('../data/pokedex-mini.js', buf);
fs.writeFileSync('../data/pokedex-mini-bw.js', g5buf);