Permalink
Browse files

Add traditional ranked ladder, fix some date issues

  • Loading branch information...
Manuel-777 committed Feb 1, 2019
1 parent 81bd19a commit e9e3d73c225efd19ae6edeb1a45fe8ece9f657b7
Showing with 43 additions and 17 deletions.
  1. +20 −16 window_background/background.js
  2. +12 −0 window_background/http-api.js
  3. +1 −0 window_main/explore.js
  4. +10 −1 window_main/renderer.js
@@ -156,8 +156,6 @@ var playerId = null;
var playerSeat = null;
var playerWin = 0;
var draws = 0;
var season_starts = null;
var season_ends = null;

var oppName = null;
var oppRank = null;
@@ -405,8 +403,9 @@ const RANKED_DRAFT_EVENT_CODES = [
"QuickDraft_GRN_20181221"
];
// code and time when ranked draft _started_
const UNRANKED_RANKED_CHANGE_CODE = "QuickDraft_DOM_12072018";
const UNRANKED_RANKED_CHANGE_DATE = new Date("2018-12-14T16:00:00.000Z");
var UNRANKED_RANKED_CHANGE_CODE = "QuickDraft_DOM_12072018";
var season_starts = new Date("2019-01-31T17:05:00Z");
var season_ends = null;

// Calculates winrates for history tabs (set to last 10 dys as default)
function calculateRankWins() {
@@ -436,35 +435,37 @@ function calculateRankWins() {

};

let ss = new Date(season_starts);
let se = new Date(season_ends);

for (var i = 0; i < history.matches.length; i++) {
let match_id = history.matches[i];
let match = history[match_id];

if (match == undefined) continue;
if (match.type != "match") continue;
if (match.type !== "match") continue;
if (match.opponent == undefined) continue;

if (match.date < season_starts) continue;
if (match.date > season_ends) continue;
let md = new Date(match.date);

if (md < ss) continue;
if (md > se) continue;

let struct;
if (match.eventId == "Ladder") {
if (match.eventId == "Ladder" || match.eventId == "Traditional_Ladder") {
struct = rankwinrates.constructed;
} else if (RANKED_DRAFT_EVENT_CODES.includes(match.eventId)
|| (match.eventId === UNRANKED_RANKED_CHANGE_CODE && match.date >= UNRANKED_RANKED_CHANGE_DATE)) {
} else if (RANKED_DRAFT_EVENT_CODES.includes(match.eventId)) {
struct = rankwinrates.limited;
} else {
continue;
}

struct = struct[match.opponent.rank.toLowerCase()];
struct = struct[match.player.rank.toLowerCase()];

if (struct) {
struct.t += 1;
if (match.opponent.win > match.player.win)
struct.l += 1;
else
struct.w += 1;
struct.t += match.opponent.win + match.player.win;
struct.l += match.opponent.win;
struct.w += match.player.win;
}
}

@@ -483,6 +484,9 @@ ipc.on('request_explore', function (event, arg) {
else if (arg == "Ranked Ladder" ) {
httpApi.httpGetTopLadderDecks();
}
else if (arg == "Traditional Ranked Ladder" ) {
httpApi.httpGetTopLadderTraditionalDecks();
}
else {
httpApi.httpGetTopDecks(arg, cards);
}
@@ -50,6 +50,9 @@ function httpBasic() {
else if (_headers.method == 'get_ladder_decks') {
options = { protocol: 'https:', port: 443, hostname: serverAddress, path: '/top_ladder.json', method: 'GET'};
}
else if (_headers.method == 'get_ladder_traditional_decks') {
options = { protocol: 'https:', port: 443, hostname: serverAddress, path: '/top_ladder_traditional.json', method: 'GET'};
}
else if (_headers.method == 'get_status') {
http = require('https');
options = { protocol: 'https:', port: 443, hostname: 'magicthegatheringarena.statuspage.io', path: '/index.json', method: 'GET'};
@@ -93,6 +96,9 @@ function httpBasic() {
if (_headers.method == 'get_ladder_decks') {
ipc_send("set_ladder_decks", parsedResult);
}
if (_headers.method == 'get_ladder_traditional_decks') {
ipc_send("set_ladder_traditional_decks", parsedResult);
}
if (parsedResult.ok) {
if (_headers.method == 'auth') {
tokenAuth = parsedResult.token;
@@ -286,6 +292,11 @@ function httpGetTopLadderDecks() {
httpAsync.push({'reqId': _id, 'method': 'get_ladder_decks', 'method_path': '/top_ladder.json'});
}

function httpGetTopLadderTraditionalDecks() {
heartbeatClear();
var _id = makeId(6);
httpAsync.push({'reqId': _id, 'method': 'get_ladder_traditional_decks', 'method_path': '/top_ladder_traditional.json'});
}
function httpGetCourse(courseId) {
heartbeatClear();
var _id = makeId(6);
@@ -395,6 +406,7 @@ module.exports = {
httpSetPlayer,
httpGetTopDecks,
httpGetTopLadderDecks,
httpGetTopLadderTraditionalDecks,
httpGetCourse,
httpSetMatch,
httpSetDraft,
@@ -77,6 +77,7 @@ function open_explore_tab(arg, loadMore) {
eventFilters = [];
eventFilters.push('All');
eventFilters.push('Ranked Ladder');
eventFilters.push('Traditional Ranked Ladder');

dateNow = new Date();
dateNow = dateNow.getTime()/1000;
@@ -418,6 +418,15 @@ ipc.on('set_explore', function (event, arg) {

//
ipc.on('set_ladder_decks', function (event, arg) {
set_ladder_decks(arg);
});

//
ipc.on('set_ladder_traditional_decks', function (event, arg) {
set_ladder_decks(arg);
});

function set_ladder_decks(arg) {
if (sidebarActive == 3) {
set_explore_mode(1);

@@ -429,7 +438,7 @@ ipc.on('set_ladder_decks', function (event, arg) {

open_explore_tab(arg.decks, 0);
}
});
}

//
ipc.on('open_course_deck', function (event, arg) {

0 comments on commit e9e3d73

Please sign in to comment.