-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathParser.js
69 lines (55 loc) · 1.84 KB
/
Parser.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
import * as mushroominator from './mushroominator.js';
function loadXMLDoc(fileName) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", fileName, false);
xmlhttp.send(null);
return xmlhttp.responseText;
}
function parse(fileName) {
const parser = new DOMParser();
const text = loadXMLDoc(fileName);
const xmlDoc = parser.parseFromString(text, "text/xml");
const ps_elements = xmlDoc.getElementsByTagName("ps_element");
const parseTag = function(element, tagName) {
return element.getElementsByTagName(tagName)[0].innerHTML;
}
var threePSElements = [];
for (let ps_element of ps_elements) {
var element_id = parseTag(ps_element, "element_id");
var element_type = parseTag(ps_element, "element_type");
var x = parseTag(ps_element, "x");
var y = parseTag(ps_element, "y");
var z = parseTag(ps_element, "z");
var rot_x = parseTag(ps_element, "rot_x");
var rot_y = parseTag(ps_element, "rot_y");
var rot_z = parseTag(ps_element, "rot_z");
var type, element;
switch (element_type) {
case "rectangle_540_540":
type = mushroominator.PSElementType.Rectangle;
element = mushroominator.PSElement.rectangle_540_540;
break;
case "beam_7_495":
type = mushroominator.PSElementType.Beam;
element = mushroominator.PSElement.beam_7_495;
break;
case "beam_1_90":
type = mushroominator.PSElementType.Beam;
element = mushroominator.PSElement.beam_1_90;
break;
case "beam_7_3_495_247":
type = mushroominator.PSElementType.LBeam;
element = mushroominator.PSElement.beam_7_3_495_247;
break;
}
var threePSElement = {
type : type,
element : element,
pos : [x, y, z],
rotation : [rot_x, rot_y, rot_z]
};
threePSElements.push(threePSElement);
}
return threePSElements;
}
export { parse };