-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconsole.js
87 lines (67 loc) · 1.73 KB
/
console.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
// https://github.com/op12no2
var CONSOLEBUILD = 'c1.13';
var args = lozGetURLArgs();
var engine = null;
lozData.page = 'console.htm';
lozData.idInfo = '#info';
lozData.idStats = '#stats';
//{{{ lozStandardRx
function lozStandardRx (e) {
lozData.message = e.data;
lozData.message = lozData.message.trim();
lozData.message = lozData.message.replace(/\n/g,'<br>');
lozData.message = lozData.message.replace(/\r/g,'');
lozData.message = lozData.message.replace(/\s+/g,' ');
lozData.tokens = lozData.message.split(' ');
if (lozData.tokens[0] == 'board') {
lozUpdateBoard();
}
$(lozData.idInfo).prepend(lozData.message + '<br>');
}
//}}}
//{{{ tx
function tx (m) {
if (m == 'start') {
if (engine)
engine.terminate();
engine = new Worker(lozData.source);
engine.onmessage = lozStandardRx;
//tx('uci');
tx('ucinewgame');
tx('position startpos');
tx('board');
return;
}
if (!engine) {
$('#info').prepend('engine not running<br>');
return;
}
$('#info').prepend('<b>> '+m+'</b><br>');
if (m == 'quit') {
engine.terminate();
engine = null;
$('#info').prepend('engine stopped<br>');
return;
}
if (m == 'clear') {
$(lozData.idInfo).html('');
return;
}
engine.postMessage(m);
}
//}}}
$(function() {
//{{{ handlers
$('#stdin').on("keypress", function(e) {
if (e.keyCode != 13)
return;
var m = $('#stdin').val().trim();
tx(m);
$('#stdin').val('').focus();
return false;
});
//}}}
//$(lozData.idInfo).prepend('Version ' + BUILD + ' ' + CONSOLEBUILD + '<br>');
tx('start');
$('#stdin').val('').focus();
});