|
49 | 49 | * worked out from the same rows; miles.js draws it as an earned award, and Slipstream's time boards say who holds it. |
50 | 50 | * And Top Cracker (cracker(), after ace()), the second earned award: whoever has the most all-time Shell Crackers kills, |
51 | 51 | * 25 or more, from the Kills board's own rows; Shell Crackers' Kills board says who holds it. |
| 52 | + * And the mini badges (topBoards() and gameTops(), after cracker()): whoever is first on each game's main board, with a |
| 53 | + * floor; miles.js draws a small shield per game, and that board says who holds it. |
52 | 54 | * |
53 | 55 | * Miles board (the first board, 'all'): This week or All time (a toggle, This week unless this browser picked All time: |
54 | 56 | * localStorage 'lb:span'; it also switches each game's play-time board, shown in miles). All time ranks by BackRoomMiles.of(node).miles, the |
|
128 | 130 | 'Most waves held': 'Más oleadas aguantadas', 'Daily puzzles finished': 'Puzles diarios terminados', 'Best daily streak (any puzzle)': 'Mejor racha diaria (cualquier puzle)', |
129 | 131 | 'Perfect days': 'Días perfectos', 'Perfect days (no mistakes)': 'Días perfectos (sin errores)', 'Clean daily solves': 'Resueltos limpios diarios', 'Daily clues solved': 'Pistas diarias resueltas', |
130 | 132 | 'No hints': 'Sin pistas', 'Solved with no hints': 'Resuelto sin pistas', 'Daily puzzles solved': 'Puzles diarios resueltos', 'Guesses to spare': 'Intentos de sobra', 'Mistakes to spare': 'Errores de sobra', |
| 133 | + // A game's main board: who holds its mini badge (miles.js). Names and values are filled in as they are. |
| 134 | + '{who}, with {v}.': '{who}, con {v}.', '{who}, with {v} each.': '{who}, con {v} cada uno.', |
| 135 | + '{who}, with {v} on {b}.': '{who}, con {v} en {b}.', '{who}, with {v} each on {b}.': '{who}, con {v} cada uno en {b}.', |
| 136 | + 'unclaimed.': 'sin dueño.', '{n} players share the top, so {b} decides: {v}.': '{n} jugadores comparten el primer puesto, así que decide {b}: {v}.', |
| 137 | + 'Whoever is first on this board holds its badge.': 'Quien esté primero en esta tabla tiene su insignia.', |
| 138 | + 'Whoever is first on this board holds its badge (at least {m}).': 'Quien esté primero en esta tabla tiene su insignia (al menos {m}).', |
| 139 | + 'Whoever is first on this board holds its badge (at most {m}).': 'Quien esté primero en esta tabla tiene su insignia (como máximo {m}).', |
| 140 | + 'Whoever is first on {b} holds its badge; while nobody is on it, the next of these with anyone on it counts: {l}.': 'Quien esté primero en {b} tiene su insignia; mientras nadie esté en esa tabla, cuenta la primera de estas que tenga a alguien: {l}.', |
| 141 | + 'Top player in {g}:': 'Mejor jugador en {g}:', |
131 | 142 | 'Par days': 'Días en par', 'Par days (no hints)': 'Días en par (sin pistas)', 'Perfect routes': 'Rutas perfectas', 'Most entries found': 'Más respuestas encontradas' |
132 | 143 | }); |
133 | 144 | })(0); |
|
932 | 943 | var who = names.length > 1 ? names.slice(0, -1).join(', ') + ' and ' + names[names.length - 1] : names[0]; |
933 | 944 | return who + ', with ' + fmtN(a.n) + ' kills' + (names.length > 1 ? ' each' : '') + '.' + rule; |
934 | 945 | } |
| 946 | + // ---- Top player in a game: a mini badge for whoever is first on each game's main board ---- |
| 947 | + // Every game in GAMES gets one (miles.js draws it as a small shield after every other badge), held by whoever rows() |
| 948 | + // ranks 1 on that game's main board: the same checked nodes, merged accounts as one player, removed ones never, and |
| 949 | + // everyone tied for first. The main board is the game's Elo board where it has one, else its first board that isn't |
| 950 | + // hidden, unless TOP_PICK names another; TOP_MODES gives a game more than one (Stackfall: Classic and Sand). Shell Crackers |
| 951 | + // and Slipstream have none: Top Cracker and the Slipstream ace are their badges (TOP_SKIP). A floor (TOP_MIN, or for |
| 952 | + // times and other lowest-first boards TOP_MAX) keeps it from being handed out for nothing: an Elo leader must be above |
| 953 | + // the starting rating, 1,000 (a rating is only published after a rated match, so that also means they have played); |
| 954 | + // anything else needs at least 1 unless listed. A new game in GAMES gets a badge by these defaults with no change here; |
| 955 | + // its name comes from GAMES's n, so a renamed game carries its badge's name with it. |
| 956 | + var TOP_SKIP = { 'shell-crackers': 1, slipstream: 1 }; |
| 957 | + var TOP_MODES = { stackfall: ['classic', 'sand'] }; |
| 958 | + // The daily puzzles rank by their best daily streak (winning every day in a row), not by wins (days played) or fewest |
| 959 | + // guesses (ties at the minimum); the rest pick the board that says "best", not a count that only grows with play. |
| 960 | + var TOP_PICK = { blockstorm: 'mkills', beatvault: 'keys', 'stat-duel': 'streak' }; |
| 961 | + ['daily', 'hunch', 'fourcast', 'quartets', 'crosslet', 'sleight', 'nearword', 'warmer', 'hotspot', 'outline', 'unfurl', 'overland', 'ninefold', 'poopdle', |
| 962 | + 'deadline-day', 'journeyman', 'scout-report', 'crossbar', 'teamsheet', 'back-four', 'top-bins'].forEach(function (d) { TOP_PICK[d] = 'streak'; }); |
| 963 | + var ELO_START = 1000; |
| 964 | + var TOP_MIN = { blockstorm: 5, coil: 300, trivium: 3000, showdown: 1000, escapade: 10, 'asteroid-run': 500, rollaway: 200, |
| 965 | + rampline: 5, flipline: 200, tidewick: 1000, beatvault: 3, gridpop: 1000, '2048': 2000, stackfall: 1000, 'stackfall:sand': 1000, |
| 966 | + 'melon-merge': 1000, 'patchwork-tower': 1000, flickerwood: 1000, lanternhold: 5, 'stat-duel': 3 }; |
| 967 | + // Lowest first: the fastest tower must be under 10 minutes (where its miles start); a Putterby card at most 36 strokes, |
| 968 | + // par (27) plus one a hole. |
| 969 | + var TOP_MAX = { spire: 600, putterby: 36 }; |
| 970 | + var TOP_STREAK = 3; // a daily streak: 3 days in a row or more |
| 971 | + var TOP_IDS = 12; // uids kept per game in the answer (ties and merged accounts), so it stays small |
| 972 | + // -> [{ id: 'coil' or 'stackfall:sand', d, st, name: 'Stackfall (Sand)', min, max }] in GAMES order. |
| 973 | + // Fallback boards: a game may list boards used, in order, only while the board before has no qualifying holder (Updraft: |
| 974 | + // the Lodestar time while nobody has one, then the Crown, then the old summit). Used nowhere else for now. |
| 975 | + var TOP_FALLBACK = { updraft: ['summit2', 'summit'] }; |
| 976 | + // A board with a cap ("of 144") where more than TIE_MANY players are tied at the cap: the game's uncapped best board named |
| 977 | + // here decides among them (Escapade: the fastest World 1 total). Without one here they all share it, as any tie does. |
| 978 | + var TOP_TIE = { escapade: 'total' }, TIE_MANY = 5; |
| 979 | + var topB0 = null; // GAMES never changes on a page, so the list is worked out once |
| 980 | + function topFloor(id, st) { |
| 981 | + var f = { st: st, min: 1, max: 0 }; |
| 982 | + if (st.f === 'elo') f.min = ELO_START + 1; |
| 983 | + else if (st.f === 'days') f.min = TOP_STREAK; |
| 984 | + var k = id + (TOP_MIN[id + '.' + st.k] != null ? '.' + st.k : ''); |
| 985 | + if (TOP_MIN[k] != null) f.min = TOP_MIN[k]; |
| 986 | + if (low(st)) { f.min = 0; f.max = TOP_MAX[k] || 0; } |
| 987 | + return f; |
| 988 | + } |
| 989 | + // -> [{ id: 'coil' or 'stackfall:sand', d, st, name: 'Stackfall (Sand)', min, max, boards: [{ st, min, max }: the main |
| 990 | + // board, then any fallbacks], tie: a tie-break stat or null }] in GAMES order. |
| 991 | + function topBoards() { |
| 992 | + if (topB0) return topB0; |
| 993 | + var out = topB0 = []; |
| 994 | + GAMES.forEach(function (g) { |
| 995 | + if (TOP_SKIP[g.d]) return; |
| 996 | + var vis = g.st.filter(function (s) { return !s.hide; }), keys = TOP_MODES[g.d]; |
| 997 | + function stat(k) { return vis.filter(function (s) { return s.k === k; })[0] || null; } |
| 998 | + if (!keys) { var k = TOP_PICK[g.d]; keys = [k && stat(k) ? k : stat('elo') ? 'elo' : vis[0] && vis[0].k]; } |
| 999 | + keys.forEach(function (k, i) { |
| 1000 | + var st = stat(k); if (!st) return; |
| 1001 | + var id = i ? g.d + ':' + k : g.d, f = topFloor(id, st); |
| 1002 | + var b = { id: id, d: g.d, st: st, name: g.n + (TOP_MODES[g.d] ? ' (' + (st.chip || st.l) + ')' : ''), min: f.min, max: f.max, boards: [f], tie: null }; |
| 1003 | + (i ? [] : TOP_FALLBACK[g.d] || []).forEach(function (fk) { var fs = stat(fk); if (fs) b.boards.push(topFloor(id, fs)); }); |
| 1004 | + if (!i && TOP_TIE[g.d] && stat(TOP_TIE[g.d])) b.tie = stat(TOP_TIE[g.d]); |
| 1005 | + out.push(b); |
| 1006 | + }); |
| 1007 | + }); |
| 1008 | + return out; |
| 1009 | + } |
| 1010 | + function topName(id) { var b = topBoards().filter(function (x) { return x.id === id; })[0]; return b ? b.name : ''; } |
| 1011 | + // Who leads each board. people: a collapsed list; all: the list before collapse (merged accounts, as ace() and cracker()). |
| 1012 | + // -> [{ b: the board, st: the board it went by (b.st, or a fallback), n: the leader's value there (0 when unclaimed), |
| 1013 | + // who: the holders, ids: their uids and merged accounts, tie: { st, v, n } when a tie-break decided }] |
| 1014 | + function gameTops(people, all, only) { |
| 1015 | + var list = (people || []).filter(function (p) { return p && !p.hidden && !p.into; }); |
| 1016 | + return (only ? [only] : topBoards()).map(function (b) { |
| 1017 | + var out = { b: b, st: b.st, n: 0, who: [], ids: [], tie: null }; |
| 1018 | + for (var i = 0; i < b.boards.length; i++) { |
| 1019 | + var f = b.boards[i], r = rows({ g: b.d, st: f.st }, list); |
| 1020 | + if (!r.length) continue; |
| 1021 | + var v = r[0].v; |
| 1022 | + if ((f.min && !(v >= f.min)) || (f.max && !(v <= f.max))) continue; |
| 1023 | + var who = r.filter(function (x) { return x.rank === 1; }).map(function (x) { return x.p; }); |
| 1024 | + // Too many tied at the board's cap: the tie-break board decides among them (only those with a value there). |
| 1025 | + if (b.tie && i === 0 && who.length > TIE_MANY && f.st.hi && v >= f.st.hi) { |
| 1026 | + var tr = rows({ g: b.d, st: b.tie }, who); |
| 1027 | + if (tr.length) { out.tie = { st: b.tie, v: tr[0].v, n: who.length }; who = tr.filter(function (x) { return x.rank === 1; }).map(function (x) { return x.p; }); } |
| 1028 | + } |
| 1029 | + out.st = f.st; out.n = v; |
| 1030 | + out.who = who.sort(function (a, c) { return a.n < c.n ? -1 : a.n > c.n ? 1 : a.uid < c.uid ? -1 : 1; }); |
| 1031 | + out.ids = out.who.map(function (p) { return p.uid; }); |
| 1032 | + (all || []).forEach(function (p) { if (p && p.into && !p.hidden && out.ids.indexOf(p.into) >= 0 && out.ids.indexOf(p.uid) < 0) out.ids.push(p.uid); }); |
| 1033 | + out.ids = out.ids.slice(0, TOP_IDS); |
| 1034 | + return out; |
| 1035 | + } |
| 1036 | + return out; |
| 1037 | + }); |
| 1038 | + } |
| 1039 | + // The line a game's main board (and its fallbacks) carries about its badge. me(uid): whether that is the viewer. |
| 1040 | + // st: the board being shown, for its floor. |
| 1041 | + function fmtTop(st, v) { return st.f === 'elo' ? fmtN(v) + ' Elo' : fmt(st, v); } |
| 1042 | + // -> sentences, each its own text node so the Spanish (lang.js) can translate each one. |
| 1043 | + function gameTopLine(t, me, st) { |
| 1044 | + var b = t.b, f = b.boards.filter(function (x) { return x.st === (st || b.st); })[0] || b.boards[0], out = []; |
| 1045 | + var lim = f.max ? ' (at most ' + fmtTop(f.st, f.max) + ')' : f.min ? ' (at least ' + fmtTop(f.st, f.min) + ')' : ''; |
| 1046 | + // A board's name inside a sentence: in Spanish already (lang.js translates whole text nodes, not words inside them). |
| 1047 | + function chipOf(x) { var c = x.chip || x.l; try { return window.BackRoomLang && BackRoomLang.t ? BackRoomLang.t(c) : c; } catch (e) { return c; } } |
| 1048 | + if (!t.n) out.push('unclaimed.'); |
| 1049 | + else { |
| 1050 | + var names = t.who.map(function (p) { return p.n + (me && me(p.uid) ? ' (you)' : ''); }); |
| 1051 | + var who = names.length > 1 ? names.slice(0, -1).join(', ') + ' and ' + names[names.length - 1] : names[0]; |
| 1052 | + out.push(who + ', with ' + fmtTop(t.st, t.n) + (names.length > 1 ? ' each' : '') + (t.st !== b.st ? ' on ' + chipOf(t.st) : '') + '.'); |
| 1053 | + if (t.tie) out.push(t.tie.n + ' players share the top, so ' + t.tie.st.l + ' decides: ' + fmtTop(t.tie.st, t.tie.v) + '.'); |
| 1054 | + } |
| 1055 | + if (b.boards.length > 1) out.push('Whoever is first on ' + chipOf(b.st) + ' holds its badge; while nobody is on it, the next of these with anyone on it counts: ' + b.boards.slice(1).map(function (x) { return chipOf(x.st); }).join(', ') + '.'); |
| 1056 | + else out.push('Whoever is first on this board holds its badge' + lim + '.'); |
| 1057 | + return out; |
| 1058 | + } |
935 | 1059 | // Who is first, second and third on the Miles board, for the "#1 all time" / "#2 this week" … tags miles.js puts by |
936 | 1060 | // tier badges: the uids rows() ranks 1, 2 and 3 for each span, so the same checked nodes, the same week and the same tie rule as the board (a tie for |
937 | 1061 | // first: every tied player, and allTie / weekTie say so). people: a collapsed list. all: the list before collapse, to |
|
955 | 1079 | }); |
956 | 1080 | var a = ace(list, all); out.ace = a.ids; out.aceN = a.n; |
957 | 1081 | var c = cracker(list, all); out.crack = c.ids; out.crackN = c.n; |
| 1082 | + // mini: [[board id, [uid…]], …] in GAMES order, only the boards someone holds (see gameTops). |
| 1083 | + out.mini = gameTops(list, all).filter(function (t) { return t.n && t.ids.length; }).map(function (t) { return [t.b.id, t.ids]; }); |
958 | 1084 | return out; |
959 | 1085 | } |
960 | 1086 | // The same from raw nodes, for the admin page (which also lists removed and merged accounts): read here as the boards |
|
969 | 1095 | } |
970 | 1096 |
|
971 | 1097 | // For the admin page: the same checks and names, so what it shows is what the boards would show. With data-lib, that's all. |
972 | | - window.BackRoomBoards = { rows: rows, tops: tops, topsOf: topsOf, ace: ace, ACE_MIN: ACE_MIN, cracker: cracker, CRACK_MIN: CRACK_MIN,RS_PATH: RS_PATH, readResets: readResets, get resets() { return RESETS; }, showHidden: function (v) { SHOW_HIDDEN = !!v; }, parse: parse, collapse: collapse, GAMES: GAMES, BY: BY, TRACKS: TRACKS, SLIP_SEASON: SLIP_SEASON, SLIP_RESET: SLIP_RESET, trackRows: trackRows, EPOCH: EPOCH, PATH: PATH, MAX_NODES: MAX_NODES, NODE_MAX: NODE_MAX, fmt: fmt, fmtHours: fmtHours, cleanName: cleanName, mask: mask, seatOf: seatOf }; |
| 1098 | + window.BackRoomBoards = { rows: rows, tops: tops, topsOf: topsOf, ace: ace, ACE_MIN: ACE_MIN, cracker: cracker, CRACK_MIN: CRACK_MIN, topBoards: topBoards, topName: topName, gameTops: gameTops,RS_PATH: RS_PATH, readResets: readResets, get resets() { return RESETS; }, showHidden: function (v) { SHOW_HIDDEN = !!v; }, parse: parse, collapse: collapse, GAMES: GAMES, BY: BY, TRACKS: TRACKS, SLIP_SEASON: SLIP_SEASON, SLIP_RESET: SLIP_RESET, trackRows: trackRows, EPOCH: EPOCH, PATH: PATH, MAX_NODES: MAX_NODES, NODE_MAX: NODE_MAX, fmt: fmt, fmtHours: fmtHours, cleanName: cleanName, mask: mask, seatOf: seatOf }; |
973 | 1099 | if (me && me.hasAttribute('data-lib')) return; |
974 | 1100 |
|
975 | 1101 | // ---------------- Styles ---------------- |
|
1317 | 1443 | $season.hidden = !(slip && view.st && (view.st.all || view.st.track)); // the lap and record boards, not Hours or Elo |
1318 | 1444 | // Shell Crackers' Kills (all time) board: the same line for Top Cracker (cracker), which that board decides. |
1319 | 1445 | var crackB = view.g === 'shell-crackers' && view.st && view.st.k === 'kills'; |
1320 | | - $ace.hidden = ($season.hidden && !crackB) || !people; |
| 1446 | + // A game's main board (topBoards): who holds that game's mini badge, the same kind of line. |
| 1447 | + var topB = !crackB && $season.hidden && view.st ? topBoards().filter(function (b) { return b.d === view.g && b.boards.some(function (f) { return f.st.k === view.st.k; }); })[0] : null; |
| 1448 | + $ace.hidden = ($season.hidden && !crackB && !topB) || !people; |
1321 | 1449 | if (!$ace.hidden) { |
1322 | 1450 | $ace.textContent = ''; |
1323 | 1451 | if (crackB) $ace.append(el('b', '', 'Top Cracker: '), crackerLine(cracker(people, everyone), isMe)); |
| 1452 | + else if (topB) { $ace.append(el('b', '', 'Top player in ' + topB.name + ':')); gameTopLine(gameTops(people, everyone, topB)[0], isMe, view.st).forEach(function (x) { $ace.append(' ', el('span', '', x)); }); } |
1324 | 1453 | else $ace.append(el('b', '', 'Slipstream ace: '), aceLine(ace(people, everyone), isMe)); |
1325 | 1454 | } |
1326 | 1455 | var miles = view.g === 'all', spans = miles || !view.st, wk = spans && view.span === 'week'; |
|
1395 | 1524 | $refresh.addEventListener('click', function () { lastLoad = 0; load(); }); |
1396 | 1525 | // avatar.js and miles.js may load after the boards were drawn (the home page loads them alongside this file). |
1397 | 1526 | document.addEventListener('backroom:avatar', function () { if (people) draw(); }); |
| 1527 | + // A change of language: the mini-badge line names boards inside a sentence, so it is drawn again in the new language. |
| 1528 | + document.addEventListener('backroom:lang', function () { if (people && !$ace.hidden) draw(); }); |
1398 | 1529 | // The same event with detail.tops says who is first changed (the "#1" tags): redraw, unless it is our own answer. |
1399 | 1530 | document.addEventListener('backroom:miles', function (e) { |
1400 | 1531 | if (!people || !e.detail || e.detail.uid || pushing) return; |
|
1426 | 1557 |
|
1427 | 1558 | // Test hook for the automated checks; harmless in normal play. |
1428 | 1559 | if (navigator.webdriver) window.__lb = { get people() { return people; }, get view() { return view; }, get myUid() { return myUid; }, parse: parse, collapse: collapse, rows: rows, milesOf: milesOf, $span: $span, trackRows: trackRows, boardsFor: boardsFor, fmt: fmt, BY: BY, load: function () { lastLoad = 0; return load(); }, draw: draw, set top(n) { TOP = n; }, setResets: function (r) { RESETS = r || {}; }, PATH: PATH, EPOCH: EPOCH, |
1429 | | - feed: function (val, now) { take(val || {}, now || Date.now()); say(''); draw(); }, tops: tops, ace: ace, aceLine: aceLine, cracker: cracker, crackerLine: crackerLine, $ace: $ace, get lastLoad() { return lastLoad; }, set lastLoad(t) { lastLoad = t; } }; |
| 1560 | + feed: function (val, now) { take(val || {}, now || Date.now()); say(''); draw(); }, tops: tops, ace: ace, aceLine: aceLine, cracker: cracker, crackerLine: crackerLine, gameTops: gameTops, gameTopLine: gameTopLine, topBoards: topBoards, $ace: $ace, get lastLoad() { return lastLoad; }, set lastLoad(t) { lastLoad = t; } }; |
1430 | 1561 | })(); |
0 commit comments