-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapParser.js
More file actions
42 lines (31 loc) · 750 Bytes
/
Copy pathmapParser.js
File metadata and controls
42 lines (31 loc) · 750 Bytes
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
const getter = require("pixel-getter")
const fs = require("fs")
/*
Tool for converting an image into a grid to be used
*/
getter.get("map1.png", (err, pixels) => {
if (err) {
console.log(err)
return
}
pixels = pixels[0]
console.log(pixels)
let map = [], r = 0
for (let i = 0; i < 900; i++) {
if (i % 30 === 0) {
map.push([])
if (i != 0) {
r++
}
}
let tile = pixels[i]
if (tile['r'] == 255) { // water
map[r].push({'type': 'water'})
} else if (tile['r'] == 0 && tile['a'] == 255) { // ground
map[r].push({'type': 'ground', 'plant': null})
} else {
map[r].push(null)
}
}
fs.writeFileSync('map.json', JSON.stringify({'map': map}));
});