Skip to content
Permalink
Browse files

Set archetypes in history

  • Loading branch information...
Manuel-777 committed Feb 19, 2019
1 parent 7f87c17 commit 33338fb9923f0f902186fd3765b5c5c51f92cebc
@@ -559,6 +559,35 @@ ipc.on('add_tag', function (event, arg) {
store.set("decks_tags", decks_tags);
});

ipc.on('delete_history_tag', function (event, arg) {
let match = history[arg.match];

if (match.tags) {
match.tags.forEach((tag, index) => {
if (tag == arg.name) {
match.tags.splice(index, 1);
}
});
}

store.set(arg.match, match);
});

ipc.on('add_history_tag', function (event, arg) {
let match = history[arg.match];

if (match.tags) {
match.tags.push(arg.name);
}
else {
match.tags = [arg.name];
}

httpApi.httpSetDeckTag(arg.name, match.oppDeck.mainDeck, match.eventId);
store.set(arg.match, match);
});


ipc.on('set_deck_mode', function (event, state) {
overlayDeckMode = state;
update_deck(true);
@@ -405,11 +405,17 @@ function httpHeartbeat() {
}

function httpSetMythicRank(opp, rank) {
heartbeatClear();
var _id = makeId(6);
httpAsync.push({'reqId': _id, 'method': 'mythicrank', 'method_path': '/send_mythic_rank.php', 'opp': opp, 'rank': rank});
}

function httpSetDeckTag(tag, cards, format) {
var _id = makeId(6);
cards.forEach((card) => { card.quantity = 1; });
cards = JSON.stringify(cards);
httpAsync.push({'reqId': _id, 'method': 'set_deck_tag', 'method_path': '/send_deck_tag.php', 'tag': tag, 'cards': cards, 'format': format});
}

module.exports = {
httpAuth,
httpSubmitCourse,
@@ -431,5 +437,6 @@ module.exports = {
httpTournamentJoin,
httpTournamentDrop,
httpTournamentCheck,
httpSetMythicRank
httpSetMythicRank,
httpSetDeckTag
};
@@ -289,9 +289,7 @@ function filterDecks(filter) {

function createTag(tag, div, showClose = true) {
let tagCol = getTagColor(tag);
var t = document.createElement("div");
t.classList.add('deck_tag');
t.innerHTML = (tag == null ? 'Add': tag);
let t = createDivision(['deck_tag'], (tag == null ? 'Add': tag));
t.style.backgroundColor = tagCol;

if (tag) {
@@ -352,8 +350,7 @@ function createTag(tag, div, showClose = true) {
}

if (showClose) {
let tc = document.createElement("div");
tc.classList.add('deck_tag_close');
let tc = createDivision(['deck_tag_close']);
t.appendChild(tc);

$(tc).on('click', function(e) {
@@ -236,6 +236,24 @@ function open_history_tab(loadMore) {
fcb.appendChild(m);
});

let tags_div = createDivision(["history_tags"]);
fcb.appendChild(tags_div);

if (match.tags) {
match.tags.forEach((tag) => {
let t = createTag(tag, tags_div);
jQuery.data(t, "match", match_id);
});
if (match.tags.length == 0) {
let t = createTag(null, tags_div, false);
jQuery.data(t, "match", match_id);
}
}
else {
let t = createTag(null, tags_div, false);
jQuery.data(t, "match", match_id);
}

d = createDivision([(match.player.win > match.opponent.win ? "list_match_result_win" : "list_match_result_loss")], `${match.player.win}:${match.opponent.win}`);
flr.appendChild(d);
}
@@ -413,8 +431,138 @@ function renderRanksStats(container) {
viewingLimitSeason = !viewingLimitSeason;
renderRanksStats(container);
});
}

function createTag(tag, div, showClose = true) {
let tagCol = getTagColor(tag);
let t = createDivision(['deck_tag'], (tag == null ? 'Set archetype': tag));
t.style.backgroundColor = tagCol;

if (tag) {
$(t).on('click', function(e) {
var colorPick = $(t);
colorPick.spectrum({
showInitial: true,
showAlpha: false,
showButtons: false
});
colorPick.spectrum("set", tagCol);
colorPick.spectrum("show");

colorPick.on('move.spectrum', function(e, color) {
let tag = $(this).text();
let col = color.toRgbString();
ipc_send("edit_tag", {tag: tag, color: col});
tags_colors[tag] = col;

$('.deck_tag').each((index, obj) => {
let tag = $(obj).text();
$(obj).css("background-color", tags_colors[tag])
});
});

colorPick.on('hide.spectrum', () => {
colorPick.spectrum("destroy");
});
e.stopPropagation();
});

}
else {
$(t).on('click', function(e) {
if ($(this).html() == "Set archetype") {
t.innerHTML = '';
let input = $('<input size="1" onFocus="this.select()" class="deck_tag_input"></input>');
$(t).prepend(input);

input[0].focus();
input[0].select();
input.keydown(function(e) {
setTimeout(() => {
input.css("width", $(this).val().length*8);
}, 10);
if (e.keyCode == 13) {
let val = $(this).val();
let matchid = jQuery.data($(this).parent()[0], "match");
let masterdiv = $(this).parent().parent()[0];
addTag(matchid, val, masterdiv);

$(this).parent().remove();
}
});
}
e.stopPropagation();
});
}

if (showClose) {
let tc = createDivision(['deck_tag_close']);
t.appendChild(tc);

$(tc).on('click', function(e) {
e.stopPropagation();
let matchid = jQuery.data($(this).parent()[0], "match");
let val = $(this).parent().text();

deleteTag(matchid, val);

$(this).css("width", "0px");
$(this).css("margin", "0px");
$(this).parent().css("opacity", 0);
$(this).parent().css("font-size", 0);
$(this).parent().css("margin-right", "0px");
$(this).parent().css("color", $(this).css("background-color"));

let t = createTag(null, $(this).parent().parent()[0], false);
jQuery.data(t, "match", matchid);
});
}
else {
t.style.paddingRight = "12px";
}
div.appendChild(t);
return t;
}

function addTag(matchid, tag, div) {
let match = matchesHistory[matchid];
if (match.tags) {
if (match.tags.indexOf(tag) == -1) {
match.tags.push(tag);
}
}
else {
match.tags = [tag];
}

let obj = {match: matchid, name: tag};
ipc_send("add_history_tag", obj);

let t = createTag(tag, div);
jQuery.data(t, "match", matchid);
}

function deleteTag(matchid, tag) {
let match = matchesHistory[matchid];

if (match.tags) {
let ind = match.tags.indexOf(tag);
if (ind !== -1) {
match.tags.splice(ind, 1);
}
}

let obj = {match: matchid, name: tag};
ipc_send("delete_history_tag", obj);
}

function getTagColor(tag) {
let tc = tags_colors[tag];
if (tc) return tc;

return "#FAE5D2";
}

function filterHistory(filter) {
filterEvent = filter;
open_history_tab(0);
@@ -753,6 +753,11 @@ a:hover {
justify-content: space-between;
}

.history_tags {
display: flex;
margin: 1px -10px 0px 8px;
}

.list_deck_name {
-webkit-user-select:none;
align-self: center;
@@ -95,6 +95,7 @@ let economyHistory = [];
let season_starts = new Date();
let season_ends = new Date();

let deck_tags = {};
let tags_colors = {};
let authToken = null;
let discordTag = null;
@@ -405,6 +406,7 @@ ipc.on('set_status', function (event, arg) {
//
ipc.on('set_home', function (event, arg) {
document.body.style.cursor = "auto";
deck_tags = arg.tags;
if (sidebarActive == -1) {
console.log(arg);
open_home_tab(arg);

0 comments on commit 33338fb

Please sign in to comment.
You can’t perform that action at this time.