add retrieval of existing bots to debugger

This commit is contained in:
Alyssa Milburn 2014-07-30 00:03:33 +02:00
parent 223a068d34
commit 11448eccb8
1 changed files with 58 additions and 6 deletions

View File

@ -54,14 +54,62 @@
}); });
request.done(function(msg) { request.done(function(msg) {
// TODO: red on error?
$('#submit-feedback').html(msg); $('#submit-feedback').html(msg);
}); });
request.fail(function(jqXHR, status) { request.fail(function(jqXHR, status) {
// TODO: red on error? // TODO: red on error?
$('#submit-feedback').html(jqXHR.responseText); $('#submit-feedback').html(jqXHR.responseText);
}); });
};
function onRetrieve() {
$('#submit-feedback').html("Retrieving...");
var tokenprefix = "state/" + $('[name="token"]').val() + "/";
var makerequest = function(name) {
return $.ajax({
accept: "text/plain",
url: tokenprefix + name,
dataType: "text",
cache: false
});
};
var setval = function(name, val) {
$('[name="' + name + '"]').val(val);
};
var request = makerequest("name");
request.done(function(msg) {
$('#submit-feedback').html("");
setval("name", msg);
request = makerequest("author");
request.done(function(msg) { setval("author", msg); } );
request = makerequest("color");
request.done(function(msg) { setval("color", msg.replace(/[\r\n]/g, '')); update(); } );
request = makerequest("program");
request.done(function(msg) { setval("program", msg); } );
var sensorfunc = function(id) {
return function(msg) {
var vals = msg.replace(/[\r\n]/g, '').split(" ");
setval("s"+id+"r", vals[0]);
setval("s"+id+"a", vals[1]);
setval("s"+id+"w", vals[2]);
$('[name="' + "s"+id+"t" + '"]').attr('checked', vals[3] != 0);
update();
};
};
for (var i = 0; i < 10; i++) {
request = makerequest("sensor" + i);
request.done(sensorfunc(i));
} }
});
request.fail(function(jqXHR, status) {
// TODO: red on error?
$('#submit-feedback').html("error (bad token?)");
});
};
</script> </script>
</head> </head>
<body style="background: #222; color: #bbb;"> <body style="background: #222; color: #bbb;">
@ -80,17 +128,21 @@
1 sensor? { -50 50 set-speed! } if ( Turn if collision sensor triggered ) 1 sensor? { -50 50 set-speed! } if ( Turn if collision sensor triggered )
</textarea><br> </textarea><br>
<fieldset id="submit"> <fieldset id="submit">
<p><input type="button" value="Submit" onclick="onSubmit();"> <span id="submit-feedback"> </span></p> <p>
<input type="button" value="Submit" onclick="onSubmit();">
<input type="button" value="Retrieve" onclick="onRetrieve();">
<span id="submit-feedback"> </span>
</p>
<p> <p>
Before you can get going with a tank, you need a password. If you Before you can get going with a tank, you need a token. If you
need a password, just ask one of the dirtbags. need a token, just ask one of the dirtbags.
</p> </p>
<legend>Information</legend> <legend>Information</legend>
<table> <table>
<tr> <tr>
<td>Password:</td> <td>Token:</td>
<td><input name="token" type="password"></td> <td><input name="token" type="password"></td>
</tr> </tr>
<tr> <tr>