-
Notifications
You must be signed in to change notification settings - Fork 5
/
pathery-client.js
98 lines (80 loc) · 2.71 KB
/
pathery-client.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
88
89
90
91
92
93
94
95
96
97
98
/*global $, mt_local_testing */
// NOTE: set mt_local_testing to use local version
var mt_url;
if (typeof mt_local_testing === 'undefined') {
mt_url = 'https://raw.githubusercontent.com/WuTheFWasThat/midnighttherapy/master/';
} else {
mt_url = mt_url || 'http://127.0.0.1:2222/';
}
// globals all mentioned here
var Analyst = {};
Analyst.server = mt_url;
Analyst.post = function(path, data, cb) {
$.ajax({
url: Analyst.server + path,
type: 'POST',
data: data,
dataType: 'json',
success: cb,
});
};
Analyst.compute_values = function(board, solution, cb) {
this.post('compute_values',
{'board': JSON.stringify(board), 'solution': JSON.stringify(solution)},
cb);
};
Analyst.compute_value = function(board, solution, cb) {
this.post('compute_value',
{'board': JSON.stringify(board), 'solution': JSON.stringify(solution)},
cb);
};
Analyst.place_greedy = function(board, solution, remaining, cb) {
this.post('place_greedy',
{'board': JSON.stringify(board), 'solution': JSON.stringify(solution), 'remaining': JSON.stringify(remaining)},
cb);
};
Analyst.play_map = function(board, solution, remaining, cb) {
this.post('play_map',
{'board': JSON.stringify(board), 'solution': JSON.stringify(solution), 'remaining': JSON.stringify(remaining)},
cb);
};
Analyst.improve_solution = function(board, solution, cb) {
this.post('improve_solution',
{'board': JSON.stringify(board), 'solution': JSON.stringify(solution)}, //, 'remaining': JSON.stringify(remaining)},
cb);
};
var Therapist = {};
(function() {
// SHARED WITH PATHERY-FULL
function get_therapist(cb) {
$.ajax({
url: mt_url + 'src/therapist.js',
type: 'GET',
dataType: 'text',
success: function(data) { eval(data); cb();},
});
}
function start_up() {
Therapist.toggle_values(); // note: must happen before scripts load for this to update button properly
Therapist.register_hotkey('F', function(/*e*/) { // override existing GO
var mapid = Therapist.get_mapid();
var walls_left = Therapist.walls_remaining(mapid);
if (!walls_left) {
Therapist.send_solution(mapid);
return;
}
Analyst.place_greedy(Therapist.get_board(mapid), Therapist.get_solution(mapid), walls_left, function(result) {
Therapist.load_solution(mapid, result);
Therapist.send_solution(mapid);
});
});
Therapist.register_hotkey('I', function(/*e*/) {
var mapid = Therapist.get_mapid();
Analyst.improve_solution(Therapist.get_board(mapid), Therapist.get_solution(mapid), function(result) {
Therapist.load_solution(mapid, result);
Therapist.send_solution(mapid);
});
});
}
get_therapist(start_up);
})();