-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrop.js
106 lines (103 loc) · 1.8 KB
/
crop.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
import { readdirSync } from 'fs';
import sharp from 'sharp';
const lineNames = {
default: [
'neutral',
'happy',
'ecstatic',
'afraid',
'sad',
'depressed',
'angry',
'enraged',
'defeated',
'injured',
'victory',
],
sunny: [
'neutral',
'calm',
null,
'afraid',
'sad',
null,
'angry',
null,
null, // Repeat of calm
'injured',
null, // Repeat of neutral
null,
null,
null,
'stressed-out',
],
omori: [
'neutral',
'happy',
'ecstatic',
'did-not-succumb',
'sad',
'depressed',
'angry',
'enraged',
'defeated',
'injured',
'victory',
'manic',
'miserable',
'furious',
null,
'afraid',
],
basil: [
'neutral',
'happy',
'ecstatic',
'afraid',
'sad',
'depressed',
'angry',
'enraged',
'defeated',
'injured',
'victory',
'manic',
'miserable',
'furious',
]
};
readdirSync('./public/spritesheets/characters').forEach(async (file) => {
const image = sharp(`./public/spritesheets/characters/${file}`);
const metadata = await image.metadata();
const lines =
file === 'sunny.png'
? {
count: lineNames.sunny.length,
names: lineNames.sunny,
}
: file === 'omori.png'
? {
count: lineNames.omori.length,
names: lineNames.omori,
}
: file == 'basil.png'
? {
count: lineNames.basil.length,
names: lineNames.basil,
}
: {
count: lineNames.default.length,
names: lineNames.default,
};
// Extract thumbnails for emotions
for (let i = 0; i < lines.count; i++) {
const frame = image.extract({
left: 0,
top: Math.floor((metadata.height / lines.count) * i),
width: Math.floor(metadata.width / 3),
height: Math.floor(metadata.height / lines.count),
});
if (lines.names[i])
frame.toFile(`./public/characters/${file.split('.')[0]}-${lines.names[i]}.png`);
}
});