-
Notifications
You must be signed in to change notification settings - Fork 810
/
Copy pathladder.js
79 lines (74 loc) · 2.67 KB
/
ladder.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
function Ladder(id, elem)
{
var selfR = this;
this.id = id;
this.elem = elem;
if (window.me) {
this.meIdent = {name: me.name, named: 'init'};
me.rooms[id] = {};
this.me = me.rooms[id];
}
this.activeFormat = false;
elem.html('<div class="mainsection formatlist"></div><div class="mainsection ladder" style="display:none"></div>');
this.formatListElem = elem.find('.formatlist');
this.ladderElem = elem.find('.ladder');
this.focus = function() {
selfR.updateMainElem();
};
this.init = function() {
selfR.update();
selfR.updateMe();
selfR.updateMainElem();
};
this.message = function(message) {
rooms.lobby.message(message);
};
this.send = function (message) {
emit(me.socket, 'chat', {room:'',message:message});
};
this.update = function(data) {
if (!data) {
selfR.updateMainElem();
return;
}
selfR.updateMainElem();
};
this.updateMainElem = function() {
var text = '';
selfR.ladderElem.show();
if (!selfR.activeFormat) {
var ladderButtons = '';
for (var i in exports.BattleFormats) {
var format = exports.BattleFormats[i];
if (!format.searchShow || !format.rated) continue;
ladderButtons += '<li style="margin:5px"><button onclick="rooms[\''+selfR.id+'\'].formSelectFormat(\''+i+'\')" style="width:400px;height:30px;text-align:left;font:12pt Verdana">'+format.name+'</button></li>';
}
selfR.ladderElem.html('<div><p>See a user\'s ranking with <code>/ranking <em>username</em></code></p>' +
//'<p><strong style="color:red">I\'m really really sorry, but as a warning: we\'re going to reset the ladder again soon to fix some more ladder bugs.</strong></p>' +
'<p>(btw if you couldn\'t tell the ladder screens aren\'t done yet; they\'ll look nicer than this once I\'m done.)</p><ul>' +
ladderButtons +
'</ul></div>');
} else {
this.ladderElem.html('<p><button onclick="rooms[\''+selfR.id+'\'].formSelectFormat(\'\')"><i class="icon-chevron-left"></i> Format List</button></p><p><em>Loading...</em></p>');
var format = selfR.activeFormat;
$.get('/ladder.php?format='+encodeURIComponent(format)+'&server='+encodeURIComponent(Config.server.id.split(':')[0])+'&output=html', function(data){
if (selfR.activeFormat !== format) return;
var text = '<p><button onclick="rooms[\''+selfR.id+'\'].formSelectFormat(\'\')"><i class="icon-chevron-left"></i> Format List</button></p>';
text += '<h3>'+format+' Top 100</h3>';
text += data;
selfR.ladderElem.html(text);
}, 'html');
}
};
this.formKeyDown = function(e) {
};
this.formKeyUp = function(e) {
};
this.formSelectFormat = function(format) {
selfR.activeFormat = format;
selfR.updateMainElem();
};
this.updateMe = function() {
};
selfR.init();
}