-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
43 lines (36 loc) · 1017 Bytes
/
index.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
import { accessSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
import { ExtractData, extractSprites } from './extractSprites';
import { Canvas } from 'canvas';
import * as fs from 'fs';
const extractData: ExtractData = JSON.parse(
readFileSync('./extract-data.json').toString()
);
['TER257.PIC', 'SP257.PIC'].forEach((file: string) => {
const content = fs.readFileSync(file, {
encoding: 'binary',
});
extractSprites(
content,
extractData.files[file],
extractData.defaults,
(width, height) => new Canvas(width, height)
).forEach(({ name, uri }) => {
const dirname = name.replace(/\/[^\/]+$/, '/');
try {
accessSync('./assets/');
} catch (e) {
mkdirSync('./assets/');
}
try {
accessSync(dirname);
} catch (e) {
mkdirSync(dirname);
}
const buffer = Buffer.from(
uri.replace(/^data:image\/png;base64,/, ''),
'base64'
);
console.log(`Writing ${name}...`);
writeFileSync(name, buffer);
});
});