Permalink
Browse files

Ranked in explore

  • Loading branch information...
Manuel-777 committed Jan 5, 2019
1 parent 36a1db4 commit cdec097d00a539f600c3bbdc0190e8fc7c701455
Showing with 247 additions and 21 deletions.
  1. +3 −0 window_background/background.js
  2. +12 −0 window_background/http-api.js
  3. +214 −21 window_main/explore.js
  4. +18 −0 window_main/renderer.js
@@ -476,6 +476,9 @@ ipc.on('request_explore', function (event, arg) {
if (arg == "all" || arg == "All" ) {
httpApi.httpGetTopDecks("", cards);
}
else if (arg == "Ranked Ladder" ) {
httpApi.httpGetTopLadderDecks();
}
else {
httpApi.httpGetTopDecks(arg, cards);
}
@@ -46,6 +46,9 @@ function httpBasic() {
if (_headers.method == 'get_database') {
options = { protocol: 'https:', port: 443, hostname: serverAddress, path: '/database/database.json', method: 'GET'};
}
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_status') {
http = require('https');
options = { protocol: 'https:', port: 443, hostname: 'magicthegatheringarena.statuspage.io', path: '/index.json', method: 'GET'};
@@ -86,6 +89,9 @@ function httpBasic() {
});
ipc_send("set_status", parsedResult);
}
if (_headers.method == 'get_ladder_decks') {
ipc_send("set_ladder_decks", parsedResult);
}
if (parsedResult.ok) {
if (_headers.method == 'auth') {
tokenAuth = parsedResult.token;
@@ -234,6 +240,11 @@ function httpGetTopDecks(query, collection) {
httpAsync.push({'reqId': _id, 'method': 'get_top_decks', 'method_path': '/get_courses_list.php', 'query': query, 'collection': collection});
}

function httpGetTopLadderDecks() {
var _id = makeId(6);
httpAsync.push({'reqId': _id, 'method': 'get_ladder_decks', 'method_path': '/top_ladder.json'});
}

function httpGetCourse(courseId) {
var _id = makeId(6);
httpAsync.push({'reqId': _id, 'method': 'get_course', 'method_path': '/get_course.php', 'courseid': courseId});
@@ -316,6 +327,7 @@ module.exports = {
httpSubmitCourse,
httpSetPlayer,
httpGetTopDecks,
httpGetTopLadderDecks,
httpGetCourse,
httpSetMatch,
httpSetDraft,
@@ -9,31 +9,47 @@ globals
ipc_send,
getEventId,
explore,
ladder,
add_checkbox,
economyHistory
economyHistory,
get_deck_missing,
getWinrateClass,
get_rank_index_16
*/

let loadExplore = 0;
let eventFilters = null;
let onlyOwned = false;
let exploreMode = 0;

const open_deck = require('./deck_details').open_deck;

let rarityBooster = {c: 3, u: 3, r: 6, m: 13};
let raritySort = {c: 'common', u: 'uncommon', r: 'rare', m: 'mythic'};
let raritySortReversed = {common: 'c', uncommon: 'u', rare: 'r', mythic: 'm'};

function updateExplore() {
filterEvent = getEventId(document.getElementById("query_select").value);
ipc_send('request_explore', filterEvent);
}

function set_explore_mode(mode) {
exploreMode = mode;
}

function open_explore_tab(arg, loadMore) {
document.body.style.cursor = "auto";
if (arg != null) {
explore = arg;
if (exploreMode == 1) {
ladder = arg;
}
else {
explore = arg;
}
}

var mainDiv = document.getElementById("ux_0");
var dateNow, d;
let rarityShort = {c: 'common', u: 'uncommon', r: 'rare', m: 'mythic'};
console.log(economyHistory);
let ownedWildcards = {c: economyHistory.wcCommon, u: economyHistory.wcUncommon, r: economyHistory.wcRare, m: economyHistory.wcMythic};

mainDiv.classList.remove("flex_item");
@@ -58,6 +74,7 @@ function open_explore_tab(arg, loadMore) {
if (eventFilters == null) {
eventFilters = [];
eventFilters.push('All');
eventFilters.push('Ranked Ladder');

dateNow = new Date();
dateNow = dateNow.getTime()/1000;
@@ -108,6 +125,192 @@ function open_explore_tab(arg, loadMore) {
}

//explore.forEach(function(_deck, index) {
if (exploreMode == 1) {
ladderLoadMore(loadMore, ownedWildcards);
}
else {
exploreLoadMore(loadMore, ownedWildcards);
}

if (loadMore == 0 && loadExplore-actuallyLoaded < 20) {
open_explore_tab(null, 20);
}

$(this).off();
$("#ux_0").on('scroll', function() {
if($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
open_explore_tab(null, 20);
}
})
}

function ladderLoadMore(loadMore, ownedWildcards) {
let mainDiv = document.getElementById("ux_0");
var actuallyLoaded = loadExplore;
console.log(ladder);
for (var loadEnd = loadExplore + loadMore; actuallyLoaded < loadEnd && loadExplore < ladder.length; loadExplore++) {
let _deck = ladder[loadExplore];
if (_deck == undefined) {
continue;
}
_deck.wildcards = get_deck_missing(_deck);
console.log(_deck);

let index = 'ladder_'+loadExplore;

var flcf = document.createElement("div");
flcf.classList.add("flex_item");
flcf.style.width = '20%';
flcf.style.justifyContent = 'center';

let wc;
let n = 0;
let boosterCost = 0;
for (var key in raritySortReversed) {
if (_deck.wildcards.hasOwnProperty(key)) {
if (_deck.wildcards[key] > 0) {
let bc = rarityBooster[raritySortReversed[key]] * (_deck.wildcards[key] - ownedWildcards[raritySortReversed[key]]);

n++;
if (bc > boosterCost) {
boosterCost = bc;
}
wc = document.createElement("div");
wc.classList.add("wc_explore_cost");
wc.classList.add("wc_"+key);
wc.title = key.capitalize()+" wldcards needed.";
wc.innerHTML = ownedWildcards[raritySortReversed[key]] + '/' + _deck.wildcards[key];
flcf.appendChild(wc);
}
}
}
if (n == 0) {
wc = document.createElement("div");
wc.classList.add("wc_complete");
flcf.appendChild(wc);
}
else if (onlyOwned) {
continue;
}
else {
let bo = document.createElement("div");
bo.classList.add("bo_explore_cost");
bo.innerHTML = boosterCost;
bo.title = "Aproximate boosters needed";
flcf.appendChild(bo);
}

actuallyLoaded++;

if (_deck.colors == undefined) {
_deck.colors = [];
}
if (_deck.wins == undefined) {
_deck.wins = 0;
_deck.losses = 0;
}

var tileGrpid = _deck.tile;
try {
let a = cardsDb.get(tileGrpid).images["art_crop"];
}
catch (e) {
tileGrpid = 67003;
}

var tile = document.createElement("div");
tile.classList.add(index+"t");
tile.classList.add("deck_tile");
tile.style.backgroundImage = "url(https://img.scryfall.com/cards"+cardsDb.get(tileGrpid).images["art_crop"]+")";

var div = document.createElement("div");
div.classList.add(index);
div.classList.add("list_deck");

var fll = document.createElement("div");
fll.classList.add("flex_item");

var flc = document.createElement("div");
flc.classList.add("flex_item");
flc.style.flexDirection = "column";
flc.style.width = '40%';

var flr = document.createElement("div");
flr.classList.add("flex_item");
flr.style.flexDirection = "column";
flr.style.width = '40%';

var flt = document.createElement("div");
flt.classList.add("flex_top");

var flb = document.createElement("div");
flb.classList.add("flex_bottom");

let d;
d = document.createElement("div");
d.classList.add("list_deck_name");
d.innerHTML = _deck.name;
flt.appendChild(d);

d = document.createElement("div");
d.classList.add("list_deck_name_it");
d.innerHTML = "by "+_deck.player;
flt.appendChild(d);

_deck.colors.forEach(function(color) {
var d = document.createElement("div");
d.classList.add("mana_s20");
d.classList.add("mana_"+mana[color]);
flb.appendChild(d);
});

d = document.createElement("div");
d.classList.add("list_deck_record");
let colClass = getWinrateClass(1/_deck.t*_deck.w);
d.innerHTML = `'Wins: ${_deck.w} / Losses: ${_deck.l} <span class="${colClass}_bright">(${Math.round(100/_deck.t*_deck.w)}%)</span>`;
flr.appendChild(d);

let rcont = document.createElement("div");
rcont.style.marginLeft = 'auto';
var pr = document.createElement("div");
pr.classList.add("ranks_16");
pr.style.backgroundPosition = (get_rank_index_16(_deck.rank)*-16)+"px 0px";
pr.title = _deck.rank;

rcont.appendChild(pr);
flr.appendChild(rcont);

div.appendChild(fll);
fll.appendChild(tile);
div.appendChild(flc);
div.appendChild(flcf);
flc.appendChild(flt);
flc.appendChild(flb);
div.appendChild(flr);

mainDiv.appendChild(div);

$('.'+index).on('mouseenter', function() {
$('.'+index+'t').css('opacity', 1);
$('.'+index+'t').css('width', '200px');
});

$('.'+index).on('mouseleave', function() {
$('.'+index+'t').css('opacity', 0.66);
$('.'+index+'t').css('width', '128px');
});

$('.'+index).on('click', function() {
open_deck(_deck, 1);
$('.moving_ux').animate({'left': '-100%'}, 250, 'easeInOutCubic');
});

}
}


function exploreLoadMore(loadMore, ownedWildcards) {
let mainDiv = document.getElementById("ux_0");
var actuallyLoaded = loadExplore;
for (var loadEnd = loadExplore + loadMore; actuallyLoaded < loadEnd && loadExplore < explore.length; loadExplore++) {
let _deck = explore[loadExplore];
@@ -117,7 +320,7 @@ function open_explore_tab(arg, loadMore) {

let index = loadExplore;

dateNow = new Date();
let dateNow = new Date();
dateNow = dateNow.getTime()/1000;
let _ss = Math.floor(dateNow - _deck.date);
if (Math.floor(_ss / 86400) > 10) {
@@ -132,7 +335,7 @@ function open_explore_tab(arg, loadMore) {
let wc;
let n = 0;
let boosterCost = 0;
for (var key in rarityShort) {
for (var key in raritySort) {
if (_deck.wildcards.hasOwnProperty(key)) {
n++;
let bc = rarityBooster[key] * (_deck.wildcards[key] - ownedWildcards[key]);
@@ -141,9 +344,9 @@ function open_explore_tab(arg, loadMore) {
}
wc = document.createElement("div");
wc.classList.add("wc_explore_cost");
wc.classList.add("wc_"+rarityShort[key]);
wc.title = rarityShort[key].capitalize()+" wldcards needed.";
wc.innerHTML = (ownedWildcards[key] > 0 ? ownedWildcards[key] + '/' : '') + _deck.wildcards[key];
wc.classList.add("wc_"+raritySort[key]);
wc.title = raritySort[key].capitalize()+" wldcards needed.";
wc.innerHTML = ownedWildcards[key] + '/' + _deck.wildcards[key];
flcf.appendChild(wc);
}
}
@@ -209,6 +412,7 @@ function open_explore_tab(arg, loadMore) {
var flb = document.createElement("div");
flb.classList.add("flex_bottom");

let d;
d = document.createElement("div");
d.classList.add("list_deck_name");
d.innerHTML = _deck.deckname;
@@ -262,17 +466,6 @@ function open_explore_tab(arg, loadMore) {
});

}

if (loadMore == 0 && loadExplore-actuallyLoaded < 20) {
open_explore_tab(null, 20);
}

$(this).off();
$("#ux_0").on('scroll', function() {
if($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
open_explore_tab(null, 20);
}
})
}

function update_explore_filters() {
@@ -286,5 +479,5 @@ function open_course_request(courseId) {
}

module.exports = {
open_explore_tab, update_explore_filters
open_explore_tab, update_explore_filters, set_explore_mode
}
Oops, something went wrong.

0 comments on commit cdec097

Please sign in to comment.