1 | var geneWindow = |
---|
2 | { |
---|
3 | context: undefined, |
---|
4 | urlToXML: "f0def.xml", |
---|
5 | debugCreatureName: "test", |
---|
6 | xml: undefined, |
---|
7 | model: new Model(), |
---|
8 | part: new Part(), |
---|
9 | joint: new Joint(), |
---|
10 | neuro: new Neuro(), |
---|
11 | neuroConn: new NeuroConn(), |
---|
12 | parts: [], |
---|
13 | joints: [], |
---|
14 | neurons: [], |
---|
15 | neuroConns: [], |
---|
16 | modelOne: undefined, |
---|
17 | _graphicsEngine: new GraphicsEngine(), |
---|
18 | downloadXML: function () { |
---|
19 | var local = this; |
---|
20 | $.ajax({ |
---|
21 | url: "http://localhost:63342/FramestickFavi/f0def.xml", |
---|
22 | dataType: "xml", |
---|
23 | async: false, |
---|
24 | success: function (xml) { |
---|
25 | var xmlDoc = $.parseXML(xml); |
---|
26 | $xml = $(xmlDoc); |
---|
27 | local.xml = $(xml); |
---|
28 | }, |
---|
29 | error: function () { |
---|
30 | alert("Can't download file f0def.xml"); |
---|
31 | } |
---|
32 | }) |
---|
33 | |
---|
34 | }, |
---|
35 | parseGeneXml: function () { |
---|
36 | var nodes = $(this.xml.find("CLASS")); |
---|
37 | var local = this; |
---|
38 | |
---|
39 | nodes.each(function (entry) { |
---|
40 | var node = $(nodes[entry]); |
---|
41 | |
---|
42 | if (node.attr("NAME") == "Model") { |
---|
43 | local.model.setModel(node); |
---|
44 | } |
---|
45 | else if (node.attr("NAME") == "Part") |
---|
46 | local.part.setModel(node); |
---|
47 | else if (node.attr("NAME") == "Joint") |
---|
48 | local.joint.setModel(node); |
---|
49 | else if (node.attr("NAME") == "Neuro") |
---|
50 | local.neuro.setModel(node); |
---|
51 | else if (node.attr("NAME") == "NeuroConn") |
---|
52 | local.neuroConn.setModel(node); |
---|
53 | else { |
---|
54 | console.log("Don't recognized NAME:", node.attr("NAME")); |
---|
55 | } |
---|
56 | |
---|
57 | }); |
---|
58 | }, |
---|
59 | analyseLine: function (line) { |
---|
60 | //ignore comment |
---|
61 | if (line[0] == '#' || line == "") |
---|
62 | return; |
---|
63 | |
---|
64 | var object; |
---|
65 | var type = line[0]; |
---|
66 | if (type == "p") { |
---|
67 | object = $.extend(true, {}, this.part); |
---|
68 | this.parts.push(object); |
---|
69 | } |
---|
70 | else if (type == "j") { |
---|
71 | object = $.extend(true, {}, this.joint); |
---|
72 | this.joints.push(object); |
---|
73 | } |
---|
74 | else if (type == "n") { |
---|
75 | object = $.extend(true, {}, this.neuro); |
---|
76 | this.neurons.push(object); |
---|
77 | } |
---|
78 | else if (type == "c") { |
---|
79 | object = $.extend(true, {}, this.neuroConn); |
---|
80 | this.neuroConns.push(object); |
---|
81 | } |
---|
82 | else if (type == "m") { |
---|
83 | object = $.extend(true, {}, this.model); |
---|
84 | this.modelOne = object; |
---|
85 | } |
---|
86 | else |
---|
87 | throw new Error("Undefined element: \"" + type + "\""); |
---|
88 | |
---|
89 | //remove char and ":" |
---|
90 | line = line.substring(2); |
---|
91 | var lines = line.match(/([^,"]+|"[^"]+")+/g); |
---|
92 | |
---|
93 | if (lines != null) |
---|
94 | lines.forEach(function (value) { |
---|
95 | value = value.trim(); |
---|
96 | if (value == "") |
---|
97 | object.setValue(); |
---|
98 | else if (value.indexOf("=") == -1) { |
---|
99 | object.setValue(value); |
---|
100 | } |
---|
101 | else { |
---|
102 | var name = value.substring(0, value.indexOf("=")); |
---|
103 | var val = value.substring(value.indexOf("=") + 1); |
---|
104 | object.setValue(name, val); |
---|
105 | } |
---|
106 | }) |
---|
107 | }, |
---|
108 | downloadCreature: function () { |
---|
109 | var lines; |
---|
110 | /*$.ajax({ |
---|
111 | url: "http://localhost:63342/FramestickFavi/creatures/" + this.debugCreatureName + ".txt", |
---|
112 | async: false, |
---|
113 | dataType: "text", |
---|
114 | success: function (data) { |
---|
115 | lines = data.split("\n"); |
---|
116 | |
---|
117 | }, |
---|
118 | error: function () { |
---|
119 | alert("Can't download creature"); |
---|
120 | } |
---|
121 | |
---|
122 | });*/ |
---|
123 | |
---|
124 | lines = $("#geno").val(); |
---|
125 | lines = lines.split("\n"); |
---|
126 | |
---|
127 | return lines; |
---|
128 | }, |
---|
129 | parseCreature: function () { |
---|
130 | var lines = this.downloadCreature(); |
---|
131 | lines.splice(0, 1); |
---|
132 | var local = this; |
---|
133 | lines.forEach(function (value) { |
---|
134 | local.analyseLine(value); |
---|
135 | }); |
---|
136 | }, |
---|
137 | renderCreature: function () { |
---|
138 | |
---|
139 | if($("#axisBox").is(":checked")) |
---|
140 | this._graphicsEngine.showPartAxis(); |
---|
141 | |
---|
142 | for (var i = 0; i < this.parts.length; i++) |
---|
143 | this._graphicsEngine.addPart(this.parts[i]) |
---|
144 | |
---|
145 | for (var i = 0; i < this.joints.length; i++) { |
---|
146 | this._graphicsEngine.addJoint(this.joints[i]); |
---|
147 | } |
---|
148 | |
---|
149 | }, |
---|
150 | mainLoop: function () { |
---|
151 | this._graphicsEngine.initializeScene(); |
---|
152 | this.renderCreature(); |
---|
153 | //this._graphicsEngine.debugTest(); |
---|
154 | this._graphicsEngine.renderScene(); |
---|
155 | } |
---|
156 | |
---|
157 | } |
---|
158 | |
---|
159 | function openWindow() { |
---|
160 | geneWindow.downloadXML(); |
---|
161 | geneWindow.parseGeneXml(); |
---|
162 | geneWindow.parseCreature(); |
---|
163 | geneWindow.mainLoop(); |
---|
164 | //geneWindow.context = window.open("window.html", "Window", "width=200,height=100"); |
---|
165 | |
---|
166 | } |
---|