-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmapconverter.js
46 lines (35 loc) · 1.03 KB
/
mapconverter.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
const jimp = require('jimp');
const fs = require('fs');
let mapID = 10;
let file = `./mapspng/${mapID}.png`;
let data = "";
jimp.read(file, (e,i) => {
if (e) throw e;
for (let k = 0; k < i.bitmap.height; k++) {
for (let l = 0; l < i.bitmap.width; l++) {
let color = i.getPixelColor(l,k).toString(16).toUpperCase().substring(0, 6);
switch (color) {
default:
case '808080':
data += "0";
break;
case '858585':
data += "1";
break;
case '909000':
data += "2";
break;
case '909090':
data += "3";
break;
case 'AAAAAA':
data += "4";
break;
case '8080FF':
data += "5";
break;
}
}
}
fs.writeFileSync(`./maps/${mapID}.txt`, data);
});