blob: 37f419de8db6d4c721f103fae0e2b5d602917d8e (
plain)
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
|
const fs = require("fs")
let boxes = []
let mode, name, x, y, w, h
function flush() {
if (mode === 'rect') {
boxes[name] = [ x |0, y |0, w |0, h |0 ]
}
x = y = w = h = 0
name = null
}
for (let line of fs.readFileSync("tools/layout.svg", "utf-8").split("\n")) {
line = line.trim()
if (line.startsWith("<rect")) {
flush()
mode = "rect"
x = y = w = h = 0
} else if (line.startsWith('x="'))
x = Math.round(Number(line.split('"')[1]))
else if (line.startsWith('y="'))
y = Math.round(Number(line.split('"')[1]))
else if (line.startsWith('width="'))
w = Math.round(Number(line.split('"')[1]))
else if (line.startsWith('height="'))
h = Math.round(Number(line.split('"')[1]))
else if (line.startsWith('inkscape:label="'))
name = line.split('"')[1]
}
flush()
console.log("var LAYOUT = {")
for (let key of Object.keys(boxes).sort())
console.log("\t\"" + key + "\": " + JSON.stringify(boxes[key]) + ",")
console.log("}")
|