-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
178 lines (152 loc) · 4.25 KB
/
index.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8 />
<title>TNT Basic Editor Prototype</title>
<link type="text/css" href="css/smoothness/jquery-ui-1.8.19.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.19.custom.min.js"></script>
<script src="lib/codemirror.js"></script>
<link rel="stylesheet" href="theme/neat.css">
<link rel="stylesheet" href="lib/codemirror.css">
<script src="mode/javascript/javascript.js"></script>
<style type="text/css">
.CodeMirror {border: 1px solid black;}
</style>
<script>
function get_appropriate_ws_url()
{
return "ws://localhost:7676";
var pcol;
var u = document.URL;
/*
* We open the websocket encrypted if this page came on an
* https:// url itself, otherwise unencrypted
*/
if (u.substring(0, 5) == "https") {
pcol = "wss://";
u = u.substr(8);
} else {
pcol = "ws://";
if (u.substring(0, 4) == "http")
u = u.substr(7);
}
u = u.split('/');
return pcol + u[0];
}
// http://jquery-howto.blogspot.co.uk/2009/09/get-url-parameters-values-with-jquery.html
// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
g_queryParams=getUrlVars();
socket_di = null;
g_projectId = parseInt(g_queryParams["projectid"]);
function openWebSocket()
{
socket_di=new WebSocket(get_appropriate_ws_url(),"tb-cmd-protocol");
try
{
socket_di.onopen = function()
{
document.getElementById("wsdi_statustd").style.backgroundColor = "#40ff40";
document.getElementById("wsdi_status").textContent = " websocket connection opened ";
loadCode();
}
socket_di.onmessage =function got_packet(msg)
{
var myObject=eval('('+msg.data+')');
console.log(msg);
}
socket_di.onclose = function()
{
document.getElementById("wsdi_statustd").style.backgroundColor = "#ff4040";
document.getElementById("wsdi_status").textContent = " websocket connection CLOSED ";
}
}
catch(exception)
{
alert('<p>Error' + exception);
}
}
var g_codeMirror=null;
function loadCode()
{
socket_di.send('{"command": "getresource", "projectid" : '+g_projectId+', "type" : "Basc", "id" : 128 }');
socket_di.onmessage=function gotcode(msg)
{
var myObject=eval('('+msg.data+')');
console.log(myObject);
var codePane=document.getElementById("codepane");
g_codeMirror=CodeMirror.fromTextArea(codePane,{ "theme": "neat" });
g_codeMirror.setValue(atob(myObject.response));
g_codeMirror.refresh();
}
}
function tabShow(event,ui)
{
if (ui.index==1) // code tab
{
if (g_codeMirror)
{
console.log("refreshing code mirror");
g_codeMirror.refresh();
}
else
{
console.log("not refreshing code mirror - not found");
}
}
}
$(function() {
$( "#tabs" ).tabs({ show: tabShow });
openWebSocket();
});
</script>
</head>
<body>
<h2>TNT Basic Editor Prototype</h2>
<table>
<tr>
<td id=wsdi_statustd align=center><div id=wsdi_status>Not initialized</div></td>
</tr>
</table>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Info</a></li>
<li><a href="#tabs-2">Code</a></li>
<li><a href="#tabs-3">Graphics</a></li>
<li><a href="#tabs-4">Sounds</a></li>
<li><a href="#tabs-5">Music</a></li>
<li><a href="#tabs-6">Maps</a></li>
</ul>
<div id="tabs-1">
<p>This is where project info would go</p>
</div>
<div id="tabs-2">
<textarea id="codepane"></textarea>
</div>
<div id="tabs-3">
<p>Edit your graphics</p>
</div>
<div id="tabs-4">
<p>Edit your sounds</p>
</div>
<div id="tabs-5">
<p>Edit your music</p>
</div>
<div id="tabs-6">
<p>Edit your maps</p>
</div>
</div>
</body>
</html>