Skip to content
Permalink
Browse files

Store decks last use, use it to sort My Decks

  • Loading branch information...
Manuel-777 committed Mar 20, 2019
1 parent 825f9e6 commit d9d1f2172a10ad468ac2ea46837f4482dfb5d9aa
Showing with 35 additions and 5 deletions.
  1. +1 −0 shared/util.js
  2. +15 −0 window_background/background.js
  3. +19 −5 window_main/renderer.js
@@ -635,6 +635,7 @@ var playerDataDefault = {
arenaVersion: "",
patreon: false,
platreon_tier: 0,
decks_last_used: [],
rank: {
constructed: {
rank: "",
@@ -95,6 +95,7 @@ const defaultCfg = {
gold_history: [],
decks_index: [],
decks_tags: {},
decks_last_used: [],
tags_colors: {},
decks: {},
wildcards_history: []
@@ -859,6 +860,7 @@ function updateSettings(_settings, relay) {
if (_settings.overlay_ontop == undefined) _settings.overlay_ontop = true;
if (_settings.overlay_scale == undefined) _settings.overlay_scale = 100;
if (_settings.skip_firstpass == undefined) _settings.skip_firstpass = false;
if (_settings.decks_last_used == undefined) _settings.decks_last_used = [];
if (_settings.sound_priority_volume == undefined)
_settings.sound_priority_volume = 1;

@@ -2030,6 +2032,19 @@ function saveMatch(matchId) {
match.tags = cm.tags;
}

// Add deck to last used array
if (match.playerDeck && match.playerDeck.id) {
let decks_last_used = store.get("decks_last_used");
let deckId = match.playerDeck.id;
if (decks_last_used.includes(deckId)) {
let pos = decks_last_used.indexOf(deckId);
decks_last_used.splice(pos, 1);
}
decks_last_used.push(deckId);
store.set("decks_last_used", decks_last_used);
ipc_send("set_decks_last_used", decks_last_used);
}

// add locally
if (!history.matches.includes(currentMatch.matchId)) {
history.matches.push(currentMatch.matchId);
@@ -274,6 +274,11 @@ ipc.on("set_player_data", (event, _data) => {
}
});

//
ipc.on("set_decks_last_used", (event, arg) => {
playerData.decks_last_used = arg;
});

//
ipc.on("set_season", function(event, arg) {
season_starts = arg.starts;
@@ -2791,11 +2796,20 @@ function sort_decks() {

//
function compare_decks(a, b) {
a = Date.parse(a.lastUpdated);
b = Date.parse(b.lastUpdated);
if (a < b) return 1;
if (a > b) return -1;
return 0;
a = playerData.decks_last_used.indexOf(a.id);
b = playerData.decks_last_used.indexOf(b.id);

if (a == -1 && b == -1) {
a = Date.parse(a.lastUpdated);
b = Date.parse(b.lastUpdated);
if (a < b) return 1;
if (a > b) return -1;
return 0;
} else {
if (a < b) return 1;
if (a > b) return -1;
return 0;
}
}

//

0 comments on commit d9d1f21

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