-
Notifications
You must be signed in to change notification settings - Fork 1
/
saver.js
108 lines (96 loc) · 3.23 KB
/
saver.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
107
108
const fs = require("fs");
module.exports = {
prepare: function(targets, window_bounds)
{
var output = {};
output.id = -1;
output.name = "root";
output.children = [];
output.window = window_bounds;
var not_placed = [];
for (var i = 0; i < targets.length; i++)
{
if (typeof(targets[i].actor) == 'undefined' ||
typeof(targets[i].childof) == 'undefined')
{
continue;
}
var id = targets[i].id;
var name = targets[i].name.toLowerCase();
var description = targets[i].description.toLowerCase();
var type = "linear"; //menu.querySelector(".type").value.toLowerCase();
var actor = targets[i].actor.toLowerCase();
var parent = targets[i].childof.toLowerCase();
var shape = targets[i].shape;
if (parent == "parent")
{
parent = "root";
}
if (actor == "arcball-reset")
{
type = "helper";
}
var tempShape = {};
tempShape.type = shape.type;
let ratio = 1; //window.devicePixelRatio;
if (tempShape.type == "rect")
{
tempShape.x = shape.startX * ratio;
tempShape.y = shape.startY * ratio;
tempShape.width = shape.w * ratio;
tempShape.height = shape.h * ratio;
}
else if (tempShape.type == "circ")
{
tempShape.centerX = shape.midX * ratio;
tempShape.centerY = shape.midY * ratio;
tempShape.radius = shape.rad * ratio;
}
else if (tempShape.type == "poly")
{
tempShape.centerX = shape.centerX * ratio;
tempShape.centerY = shape.centerY * ratio;
tempShape.points = shape.points;
}
var obj = {
id: id,
name: name,
description: description,
type: type,
actor: actor,
parent: parent,
shape: tempShape
};
if (parent == "root")
{
output.children.push(obj);
}
else
{
not_placed.push(obj);
}
}
while (not_placed.length > 0) {
for (var i = 0; i < not_placed.length; i++) {
var found_parent = search(output, not_placed[i].parent);
if (found_parent != null) {
if (found_parent.children === undefined) {
found_parent.children = [];
}
// found_parent has children, set its type to parallel for now
found_parent.type = "parallel";
found_parent.children.push(not_placed[i]);
not_placed.splice(i, 1);
break;
}
}
}
return output;
},
save: function(data)
{
fs.writeFile("./viewer/config.json",
JSON.stringify(data),
() => {});
}
}