forked from smogon/pokemon-showdown-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient-ladder.js
173 lines (163 loc) · 6.38 KB
/
client-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
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
(function ($) {
var HTMLRoom = this.HTMLRoom = this.Room.extend({
type: 'html',
title: 'Page',
initialize: function () {
this.$el.addClass('ps-room-light').addClass('scrollable');
this.$el.html('<div class="pad"><p>Page unavailable</p></div>');
},
send: function (data) {
// HTML rooms don't actually exist server side, so send globally
app.send(data);
},
receive: function (data) {
this.add(data);
},
add: function (log) {
if (typeof log === 'string') log = log.split('\n');
for (var i = 0; i < log.length; i++) {
this.addRow(log[i]);
}
},
join: function () {
app.send('/join ' + this.id);
},
leave: function () {
app.send('/leave ' + this.id);
},
addRow: function (line) {
var name, name2, room, action, silent, oldid;
if (!line || typeof line !== 'string') return;
if (line.charAt(0) !== '|') line = '||' + line;
var pipeIndex = line.indexOf('|', 1);
var row;
if (pipeIndex >= 0) {
row = [line.slice(1, pipeIndex), line.slice(pipeIndex + 1)];
} else {
row = [line.slice(1), ''];
}
switch (row[0]) {
case 'init':
// ignore (handled elsewhere)
break;
case 'title':
this.title = row[1];
app.roomTitleChanged(this);
app.topbar.updateTabbar();
break;
case 'pagehtml':
this.$el.html(Tools.sanitizeHTML(row[1]));
this.subtleNotifyOnce();
break;
case 'selectorhtml':
var pipeIndex2 = row[1].indexOf('|');
if (pipeIndex2 < 0) return;
this.$(row[1].slice(0, pipeIndex2)).html(Tools.sanitizeHTML(row[1].slice(pipeIndex2 + 1)));
this.subtleNotifyOnce();
break;
case 'notify':
if (!Tools.prefs('mute') && Tools.prefs('notifvolume')) {
soundManager.getSoundById('notif').setVolume(Tools.prefs('notifvolume')).play();
}
this.notifyOnce(row[1], row.slice(2).join('|'), 'highlight');
break;
case 'tempnotify':
var notifyOnce = row[4] !== '!';
if (!this.notifications && !Tools.prefs('mute') && Tools.prefs('notifvolume')) {
soundManager.getSoundById('notif').setVolume(Tools.prefs('notifvolume')).play();
}
this.notify(row[2], row[3], row[1], notifyOnce);
break;
case 'tempnotifyoff':
this.closeNotification(row[1]);
break;
}
}
});
var LadderRoom = this.LadderRoom = HTMLRoom.extend({
type: 'ladder',
title: 'Ladder',
initialize: function () {
this.$el.addClass('ps-room-light').addClass('scrollable');
app.on('init:formats', this.update, this);
this.update();
app.on('response:laddertop', function (data) {
var buf = '<div class="ladder pad"><p><button name="selectFormat"><i class="fa fa-chevron-left"></i> Format List</button></p>';
if (!data) {
this.$el.html(buf + '<p>error</p></div>');
return;
}
if (this.curFormat !== data[0]) return;
buf += Tools.sanitizeHTML(data[1]) + '</div>';
this.$el.html(buf);
}, this);
},
curFormat: '',
join: function () {},
leave: function () {},
update: function () {
if (!this.curFormat) {
var buf = '<div class="ladder pad"><p>See a user\'s ranking with <a class="button" href="//pokemonshowdown.com/users/" target="_blank">User lookup</a></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>' +
'<p><button name="selectFormat" value="help" class="button"><i class="fa fa-info-circle"></i> How the ladder works</button></p><ul>';
if (!window.BattleFormats) {
this.$el.html('<div class="pad"><em>Loading...</em></div>');
return;
}
var curSection = '';
for (var i in BattleFormats) {
var format = BattleFormats[i];
if (format.section && format.section !== curSection) {
curSection = format.section;
buf += '</ul><h3>' + Tools.escapeHTML(curSection) + '</h3><ul style="list-style:none;margin:0;padding:0">';
}
if (!format.searchShow || !format.rated) continue;
buf += '<li style="margin:5px"><button name="selectFormat" value="' + i + '" class="button" style="width:320px;height:30px;text-align:left;font:12pt Verdana">' + Tools.escapeFormat(format.id) + '</button></li>';
}
buf += '</ul></div>';
this.$el.html(buf);
} else if (this.curFormat === 'help') {
this.showHelp();
} else {
var format = this.curFormat;
var self = this;
this.$el.html('<div class="ladder pad"><p><button name="selectFormat"><i class="fa fa-chevron-left"></i> Format List</button></p><p><em>Loading...</em></p></div>');
if (app.localLadder) {
app.send('/cmd laddertop ' + format);
} else {
$.get('/ladder.php', {
format: format,
server: Config.server.id.split(':')[0],
output: 'html'
}, function (data) {
if (self.curFormat !== format) return;
var buf = '<div class="ladder pad"><p><button name="selectFormat"><i class="fa fa-chevron-left"></i> Format List</button></p><p><button class="button" name="refresh"><i class="fa fa-refresh"></i> Refresh</button></p>';
buf += '<h3>' + Tools.escapeFormat(format) + ' Top 500</h3>';
buf += data + '</div>';
self.$el.html(buf);
}, 'html');
}
}
},
showHelp: function () {
var buf = '<div class="ladder pad"><p><button name="selectFormat"><i class="fa fa-chevron-left"></i> Format List</button></p>';
buf += '<h3>How the ladder works</h3>';
buf += '<p>Our ladder displays three ratings: Elo, GXE, and Glicko-1.</p>';
buf += '<p><strong>Elo</strong> is the main ladder rating. It\'s a pretty normal ladder rating: goes up when you win and down when you lose.</p>';
buf += '<p><strong>GXE</strong> (Glicko X-Act Estimate) is an estimate of your win chance against an average ladder player.</p>';
buf += '<p><strong>Glicko-1</strong> is a different rating system. It has rating and deviation values.</p>';
buf += '<p>Note that win/loss should not be used to estimate skill, since who you play against is much more important than how many times you win or lose. Our other stats like Elo and GXE are much better for estimating skill.</p>';
buf += '</div>';
this.$el.html(buf);
},
selectFormat: function (format) {
this.curFormat = format;
this.update();
},
refresh: function () {
this.$('button[name=refresh]').addClass('disabled').prop('disabled', true);
this.update();
}
});
}).call(this, jQuery);