From 5b93b169e52375d68651a230069991e6b9db23ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manw=C3=AB?= Date: Sat, 6 Jan 2024 02:15:43 -0300 Subject: [PATCH] new log components --- public/tooldb-worker/index.js | 2028 ++++++++--------- src/background/greToClientInterpreter.ts | 153 +- src/background/saveMatch.ts | 2 +- src/background/store/types.ts | 4 +- src/components/action-log-v2/LineAbility.tsx | 19 + src/components/action-log-v2/LineAttack.tsx | 32 + src/components/action-log-v2/LineCast.tsx | 20 + src/components/action-log-v2/LineConceded.tsx | 16 + .../action-log-v2/LineCountered.tsx | 27 + .../action-log-v2/LineDamageDealt.tsx | 23 + .../action-log-v2/LineDestroyed.tsx | 27 + src/components/action-log-v2/LineDiscard.tsx | 20 + src/components/action-log-v2/LineDraw.tsx | 20 + src/components/action-log-v2/LineExile.tsx | 27 + src/components/action-log-v2/LinePlay.tsx | 20 + src/components/action-log-v2/LineTimedOut.tsx | 16 + src/components/action-log-v2/LineTurnInfo.tsx | 34 + src/components/action-log-v2/LineWon.tsx | 16 + src/components/action-log-v2/LineZonePut.tsx | 28 + .../action-log-v2/LineZoneReturn.tsx | 28 + src/components/action-log-v2/LogAbility.tsx | 16 + src/components/action-log-v2/LogCard.tsx | 21 + .../action-log-v2/getPlayerBySeat.ts | 11 + src/components/action-log-v2/index.tsx | 158 +- src/components/action-log-v2/types.ts | 16 +- src/info.json | 2 +- src/scss/actionLog.scss | 51 + 27 files changed, 1717 insertions(+), 1118 deletions(-) create mode 100644 src/components/action-log-v2/LineAbility.tsx create mode 100644 src/components/action-log-v2/LineAttack.tsx create mode 100644 src/components/action-log-v2/LineCast.tsx create mode 100644 src/components/action-log-v2/LineConceded.tsx create mode 100644 src/components/action-log-v2/LineCountered.tsx create mode 100644 src/components/action-log-v2/LineDamageDealt.tsx create mode 100644 src/components/action-log-v2/LineDestroyed.tsx create mode 100644 src/components/action-log-v2/LineDiscard.tsx create mode 100644 src/components/action-log-v2/LineDraw.tsx create mode 100644 src/components/action-log-v2/LineExile.tsx create mode 100644 src/components/action-log-v2/LinePlay.tsx create mode 100644 src/components/action-log-v2/LineTimedOut.tsx create mode 100644 src/components/action-log-v2/LineTurnInfo.tsx create mode 100644 src/components/action-log-v2/LineWon.tsx create mode 100644 src/components/action-log-v2/LineZonePut.tsx create mode 100644 src/components/action-log-v2/LineZoneReturn.tsx create mode 100644 src/components/action-log-v2/LogAbility.tsx create mode 100644 src/components/action-log-v2/LogCard.tsx create mode 100644 src/components/action-log-v2/getPlayerBySeat.ts diff --git a/public/tooldb-worker/index.js b/public/tooldb-worker/index.js index 2069d3a6..0646c4b4 100644 --- a/public/tooldb-worker/index.js +++ b/public/tooldb-worker/index.js @@ -1,1066 +1,1066 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.tooldbworker = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i { - let savedPeers = constants_1.DEFAULT_PEERS; - if (err) { - console.error("Error getting saved peers from cache:", err); - } - else if (data) { - try { - const newPeers = JSON.parse(data); - savedPeers = newPeers; - } - catch (_e) { - console.error("Error parsing saved peers from cache:", _e); - } - } - if (!savedPeers.includes(host)) { - savedPeers.push(host); - } - self.toolDb.store.put(constants_1.SAVED_PEERS_KEY, JSON.stringify(savedPeers), () => { - console.log("Saved peers to cache", savedPeers); - }); - }); -} -exports.default = addHost; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const constants_1 = require("./constants"); +/* eslint-disable no-restricted-globals */ +function addHost(host) { + // Try to conenct to servers from cache + self.toolDb.store.get(constants_1.SAVED_PEERS_KEY, (err, data) => { + let savedPeers = constants_1.DEFAULT_PEERS; + if (err) { + console.error("Error getting saved peers from cache:", err); + } + else if (data) { + try { + const newPeers = JSON.parse(data); + savedPeers = newPeers; + } + catch (_e) { + console.error("Error parsing saved peers from cache:", _e); + } + } + if (!savedPeers.includes(host)) { + savedPeers.push(host); + } + self.toolDb.store.put(constants_1.SAVED_PEERS_KEY, JSON.stringify(savedPeers), () => { + console.log("Saved peers to cache", savedPeers); + }); + }); +} +exports.default = addHost; },{"./constants":4}],2:[function(require,module,exports){ -"use strict"; -/* eslint-disable no-restricted-globals */ -Object.defineProperty(exports, "__esModule", { value: true }); -function addKeyListener(msgId, key) { - const id = self.toolDb.addKeyListener(key, (value) => { - self.postMessage({ type: `LISTENER_${key}`, value }); - }); - self.postMessage({ type: `${msgId}_ID`, id }); -} -exports.default = addKeyListener; +"use strict"; +/* eslint-disable no-restricted-globals */ +Object.defineProperty(exports, "__esModule", { value: true }); +function addKeyListener(msgId, key) { + const id = self.toolDb.addKeyListener(key, (value) => { + self.postMessage({ type: `LISTENER_${key}`, value }); + }); + self.postMessage({ type: `${msgId}_ID`, id }); +} +exports.default = addKeyListener; },{}],3:[function(require,module,exports){ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const handleDraftsIndex_1 = __importDefault(require("./handleDraftsIndex")); -const handleLiveFeed_1 = __importDefault(require("./handleLiveFeed")); -const handleMatchesIndex_1 = __importDefault(require("./handleMatchesIndex")); -const reduxAction_1 = __importDefault(require("./reduxAction")); -function afterLogin() { - const currentDay = Math.floor(new Date().getTime() / (86400 * 1000)); - if (self.toolDb.user) { - (0, reduxAction_1.default)("SET_PUBKEY", self.toolDb.user.pubKey); - self.toolDb.store - .query(`:${self.toolDb.user.pubKey}.matches-`) - .then((matches) => { - (0, reduxAction_1.default)("SET_LOCAL_MATCHES_INDEX", matches); - }); - self.toolDb - .queryKeys(`:${self.toolDb.user.pubKey}.matches-`, false, 5000, true) - .then(handleMatchesIndex_1.default); - self.toolDb - .queryKeys(`:${self.toolDb.user.pubKey}.draft-`) - .then(handleDraftsIndex_1.default); - self.toolDb.getData(`privateMode`, true).then((settingPrivate) => { - (0, reduxAction_1.default)("SET_SETTINGS", { privateMode: settingPrivate === true }); - }); - } - self.toolDb.addKeyListener(`matches-livefeed-${currentDay}`, handleLiveFeed_1.default); - self.toolDb.getData(`matches-livefeed-${currentDay}`); - self.toolDb.subscribeData("userids", true); - self.toolDb.subscribeData(`matches-livefeed-${currentDay}`); - self.toolDb.getData("hiddenDecks", true, 5000).then((hidden) => { - if (hidden) { - self.globalData.hiddenDecks = hidden; - (0, reduxAction_1.default)("SET_HIDDEN_DECKS", hidden); - } - }); - self.toolDb - .getData("userids", true, 5000) - .then((data) => { - let newest = ""; - let newestDate = 0; - Object.keys(data) - .filter((k) => k && k !== "undefined") - .forEach((uuid) => { - if (data[uuid] > newestDate) { - newestDate = data[uuid]; - newest = uuid; - } - self.toolDb.addKeyListener(self.toolDb.getUserNamespacedKey(`${uuid}-displayname`), (msg) => { - if (msg.type === "put") { - (0, reduxAction_1.default)("SET_UUID_DISPLAYNAME", { - displayName: msg.v.displayName, - uuid, - }); - } - }); - self.toolDb.subscribeData(`${uuid}-displayname`, true); - self.toolDb.addKeyListener(self.toolDb.getUserNamespacedKey(`${uuid}-cards`), (msg) => { - if (msg.type === "put") { - (0, reduxAction_1.default)("SET_UUID_CARDS_DATA", { cards: msg.v, uuid }); - } - }); - self.toolDb.subscribeData(`${uuid}-cards`, true); - self.toolDb.addKeyListener(self.toolDb.getUserNamespacedKey(`${uuid}-inventory`), (msg) => { - if (msg.type === "put") { - (0, reduxAction_1.default)("SET_UUID_INVENTORY_DATA", { - inventory: msg.v, - uuid, - }); - } - }); - self.toolDb.subscribeData(`${uuid}-inventory`, true); - self.toolDb.addKeyListener(self.toolDb.getUserNamespacedKey(`${uuid}-rank`), (msg) => { - if (msg.type === "put") { - (0, reduxAction_1.default)("SET_UUID_RANK_DATA", { rank: msg.v, uuid }); - } - }); - self.toolDb.subscribeData(`${uuid}-rank`, true); - self.globalData.currentUUID = newest; - (0, reduxAction_1.default)("SET_UUID", newest); - }); - }) - .catch(console.warn); -} -exports.default = afterLogin; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const handleDraftsIndex_1 = __importDefault(require("./handleDraftsIndex")); +const handleLiveFeed_1 = __importDefault(require("./handleLiveFeed")); +const handleMatchesIndex_1 = __importDefault(require("./handleMatchesIndex")); +const reduxAction_1 = __importDefault(require("./reduxAction")); +function afterLogin() { + const currentDay = Math.floor(new Date().getTime() / (86400 * 1000)); + if (self.toolDb.user) { + (0, reduxAction_1.default)("SET_PUBKEY", self.toolDb.user.pubKey); + self.toolDb.store + .query(`:${self.toolDb.user.pubKey}.matches-`) + .then((matches) => { + (0, reduxAction_1.default)("SET_LOCAL_MATCHES_INDEX", matches); + }); + self.toolDb + .queryKeys(`:${self.toolDb.user.pubKey}.matches-`, false, 5000, true) + .then(handleMatchesIndex_1.default); + self.toolDb + .queryKeys(`:${self.toolDb.user.pubKey}.draft-`) + .then(handleDraftsIndex_1.default); + self.toolDb.getData(`privateMode`, true).then((settingPrivate) => { + (0, reduxAction_1.default)("SET_SETTINGS", { privateMode: settingPrivate === true }); + }); + } + self.toolDb.addKeyListener(`matches-livefeed-${currentDay}`, handleLiveFeed_1.default); + self.toolDb.getData(`matches-livefeed-${currentDay}`); + self.toolDb.subscribeData("userids", true); + self.toolDb.subscribeData(`matches-livefeed-${currentDay}`); + self.toolDb.getData("hiddenDecks", true, 5000).then((hidden) => { + if (hidden) { + self.globalData.hiddenDecks = hidden; + (0, reduxAction_1.default)("SET_HIDDEN_DECKS", hidden); + } + }); + self.toolDb + .getData("userids", true, 5000) + .then((data) => { + let newest = ""; + let newestDate = 0; + Object.keys(data) + .filter((k) => k && k !== "undefined") + .forEach((uuid) => { + if (data[uuid] > newestDate) { + newestDate = data[uuid]; + newest = uuid; + } + self.toolDb.addKeyListener(self.toolDb.getUserNamespacedKey(`${uuid}-displayname`), (msg) => { + if (msg.type === "put") { + (0, reduxAction_1.default)("SET_UUID_DISPLAYNAME", { + displayName: msg.v.displayName, + uuid, + }); + } + }); + self.toolDb.subscribeData(`${uuid}-displayname`, true); + self.toolDb.addKeyListener(self.toolDb.getUserNamespacedKey(`${uuid}-cards`), (msg) => { + if (msg.type === "put") { + (0, reduxAction_1.default)("SET_UUID_CARDS_DATA", { cards: msg.v, uuid }); + } + }); + self.toolDb.subscribeData(`${uuid}-cards`, true); + self.toolDb.addKeyListener(self.toolDb.getUserNamespacedKey(`${uuid}-inventory`), (msg) => { + if (msg.type === "put") { + (0, reduxAction_1.default)("SET_UUID_INVENTORY_DATA", { + inventory: msg.v, + uuid, + }); + } + }); + self.toolDb.subscribeData(`${uuid}-inventory`, true); + self.toolDb.addKeyListener(self.toolDb.getUserNamespacedKey(`${uuid}-rank`), (msg) => { + if (msg.type === "put") { + (0, reduxAction_1.default)("SET_UUID_RANK_DATA", { rank: msg.v, uuid }); + } + }); + self.toolDb.subscribeData(`${uuid}-rank`, true); + self.globalData.currentUUID = newest; + (0, reduxAction_1.default)("SET_UUID", newest); + }); + }) + .catch(console.warn); +} +exports.default = afterLogin; },{"./handleDraftsIndex":14,"./handleLiveFeed":15,"./handleMatchesIndex":16,"./reduxAction":22}],4:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SERVERS_KEY = exports.SAVED_PEERS_KEY = exports.DEFAULT_PEERS = void 0; -const mtgatool_db_1 = require("mtgatool-db"); -/* eslint-disable import/prefer-default-export */ -exports.DEFAULT_PEERS = [ - "ccdde0f639db3ccb18ed2d48ed405323eac3ce86762923c1010796433e9a392dec3771400f524d4f0a466c0701cad99bbd8b509df3a467c8ca76fab7dc5504bb", -]; -exports.SAVED_PEERS_KEY = (0, mtgatool_db_1.sha1)("-.saved-peers.-"); -exports.SERVERS_KEY = (0, mtgatool_db_1.sha1)("-.servers.-"); +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SERVERS_KEY = exports.SAVED_PEERS_KEY = exports.DEFAULT_PEERS = void 0; +const mtgatool_db_1 = require("mtgatool-db"); +/* eslint-disable import/prefer-default-export */ +exports.DEFAULT_PEERS = [ + "ccdde0f639db3ccb18ed2d48ed405323eac3ce86762923c1010796433e9a392dec3771400f524d4f0a466c0701cad99bbd8b509df3a467c8ca76fab7dc5504bb", +]; +exports.SAVED_PEERS_KEY = (0, mtgatool_db_1.sha1)("-.saved-peers.-"); +exports.SERVERS_KEY = (0, mtgatool_db_1.sha1)("-.servers.-"); },{"mtgatool-db":292}],5:[function(require,module,exports){ -"use strict"; -/* eslint-disable no-restricted-globals */ -Object.defineProperty(exports, "__esModule", { value: true }); -function doFunction(msgId, fname, args, timeoutMs) { - return self.toolDb - .doFunction(fname, args, timeoutMs) - .then((value) => { - self.postMessage({ type: `${msgId}_OK`, value }); - }) - .catch((err) => { - self.postMessage({ type: "LOGIN_ERR", err }); - }); -} -exports.default = doFunction; +"use strict"; +/* eslint-disable no-restricted-globals */ +Object.defineProperty(exports, "__esModule", { value: true }); +function doFunction(msgId, fname, args, timeoutMs) { + return self.toolDb + .doFunction(fname, args, timeoutMs) + .then((value) => { + self.postMessage({ type: `${msgId}_OK`, value }); + }) + .catch((err) => { + self.postMessage({ type: "LOGIN_ERR", err }); + }); +} +exports.default = doFunction; },{}],6:[function(require,module,exports){ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.beginDataQuery = exports.limitRecord = void 0; -/* eslint-disable no-restricted-globals */ -/* eslint-disable no-bitwise */ -/* eslint-disable radix */ -const automerge_1 = __importDefault(require("automerge")); -const mtgatool_db_1 = require("mtgatool-db"); -function limitRecord(record, limit) { - const newRecord = {}; - Object.keys(record) - .map((k) => { - const v = record[k]; - return { - k, - v, - }; - }) - .sort((a, b) => { - if (a.v > b.v) - return -1; - if (b.v > a.v) - return 1; - return 0; - }) - .splice(0, limit) - .forEach((d) => { - newRecord[d.k] = d.v; - }); - return newRecord; -} -exports.limitRecord = limitRecord; -function beginDataQuery(_day, _eventId) { - let crdt = automerge_1.default.init({}); - const data = {}; - let queriedIds = []; - function continnuousCheck() { - self.postMessage({ - type: `EXPLORE_DATA_QUERY_STATE`, - value: { - foundKeys: Object.keys(crdt).length, - queriedKeys: queriedIds.length, - savedKeys: Object.keys(data).length, - loadingPercent: Math.floor((queriedIds.length / Object.keys(crdt).length) * 100), - }, - }); - if (Object.keys(crdt).length === queriedIds.length) { - self.postMessage({ - type: `EXPLORE_DATA_QUERY`, - value: data, - }); - } - if (Object.keys(crdt).length === 0) { - setTimeout(() => { - continnuousCheck(); - }, 500); - } - Object.keys(crdt) - .filter((k) => !queriedIds.includes(k)) - .splice(0, 1) - .forEach((id) => { - queriedIds = [...queriedIds, id]; - self.toolDb.getData(id).then((d) => { - data[id] = d; - continnuousCheck(); - }); - }); - } - const handleExploreData = (msg) => { - if (msg && msg.type === "crdt") { - const doc = automerge_1.default.load((0, mtgatool_db_1.base64ToBinaryDocument)(msg.doc)); - try { - crdt = automerge_1.default.merge(crdt, doc); - } - catch (e) { - console.warn(e); - } - } - }; - function queryForEvent(ev) { - for (let i = 0; i < _day; i += 1) { - const currentDay = Math.floor(new Date().getTime() / (86400 * 1000)); - const queryKey = `explore-${currentDay - i}-${ev}`; - self.toolDb.addKeyListener(queryKey, handleExploreData); - self.toolDb.subscribeData(queryKey); - } - } - if (_eventId === "aggregated-standard") { - queryForEvent("Ladder"); - queryForEvent("Play"); - queryForEvent("Constructed_BestOf3"); - queryForEvent("Constructed_Event_2020"); - queryForEvent("Constructed_Event_2021"); - queryForEvent("Constructed_Event_v2"); - queryForEvent("Traditional_Cons_Event_2020"); - queryForEvent("Traditional_Cons_Event_2021"); - queryForEvent("Traditional_Cons_Event_2022"); - queryForEvent("Traditional_Cons_Event_2023"); - queryForEvent("Traditional_Ladder"); - queryForEvent("Standard_Challenge_20230421"); - } - else if (_eventId === "aggregated-historic") { - queryForEvent("Historic_Ladder"); - queryForEvent("Historic_Play"); - queryForEvent("Historic_Event_v2"); - queryForEvent("Historic_Event"); - queryForEvent("Traditional_Historic_Event"); - queryForEvent("Traditional_Historic_Play"); - queryForEvent("Traditional_Historic_Ladder"); - } - else if (_eventId === "aggregated-timeless") { - queryForEvent("Timeless_Ladder"); - queryForEvent("Timeless_Play"); - queryForEvent("Timeless_Event_v2"); - queryForEvent("Timeless_Event"); - queryForEvent("Traditional_Timeless_Event"); - queryForEvent("Traditional_Timeless_Play"); - queryForEvent("Traditional_Timeless_Ladder"); - } - else if (_eventId === "aggregated-alchemy") { - queryForEvent("Alchemy_Ladder"); - queryForEvent("Alchemy_Play"); - queryForEvent("Alchemy_Event"); - queryForEvent("Traditional_Alchemy_Event_2022"); - queryForEvent("Traditional_Alchemy_Event_2023"); - queryForEvent("Traditional_Alchemy_Event"); - queryForEvent("Traditional_Alchemy_Play"); - queryForEvent("Traditional_Alchemy_Ladder"); - } - else if (_eventId === "aggregated-explorer") { - queryForEvent("Explorer_Ladder"); - queryForEvent("Explorer_Play"); - queryForEvent("Explorer_Event"); - queryForEvent("Explorer_Event_v2"); - queryForEvent("Traditional_Explorer_Event"); - queryForEvent("Traditional_Explorer_Play"); - queryForEvent("Traditional_Explorer_Ladder"); - } - else { - queryForEvent(_eventId); - } - continnuousCheck(); -} -exports.beginDataQuery = beginDataQuery; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.beginDataQuery = exports.limitRecord = void 0; +/* eslint-disable no-restricted-globals */ +/* eslint-disable no-bitwise */ +/* eslint-disable radix */ +const automerge_1 = __importDefault(require("automerge")); +const mtgatool_db_1 = require("mtgatool-db"); +function limitRecord(record, limit) { + const newRecord = {}; + Object.keys(record) + .map((k) => { + const v = record[k]; + return { + k, + v, + }; + }) + .sort((a, b) => { + if (a.v > b.v) + return -1; + if (b.v > a.v) + return 1; + return 0; + }) + .splice(0, limit) + .forEach((d) => { + newRecord[d.k] = d.v; + }); + return newRecord; +} +exports.limitRecord = limitRecord; +function beginDataQuery(_day, _eventId) { + let crdt = automerge_1.default.init({}); + const data = {}; + let queriedIds = []; + function continnuousCheck() { + self.postMessage({ + type: `EXPLORE_DATA_QUERY_STATE`, + value: { + foundKeys: Object.keys(crdt).length, + queriedKeys: queriedIds.length, + savedKeys: Object.keys(data).length, + loadingPercent: Math.floor((queriedIds.length / Object.keys(crdt).length) * 100), + }, + }); + if (Object.keys(crdt).length === queriedIds.length) { + self.postMessage({ + type: `EXPLORE_DATA_QUERY`, + value: data, + }); + } + if (Object.keys(crdt).length === 0) { + setTimeout(() => { + continnuousCheck(); + }, 500); + } + Object.keys(crdt) + .filter((k) => !queriedIds.includes(k)) + .splice(0, 1) + .forEach((id) => { + queriedIds = [...queriedIds, id]; + self.toolDb.getData(id).then((d) => { + data[id] = d; + continnuousCheck(); + }); + }); + } + const handleExploreData = (msg) => { + if (msg && msg.type === "crdt") { + const doc = automerge_1.default.load((0, mtgatool_db_1.base64ToBinaryDocument)(msg.doc)); + try { + crdt = automerge_1.default.merge(crdt, doc); + } + catch (e) { + console.warn(e); + } + } + }; + function queryForEvent(ev) { + for (let i = 0; i < _day; i += 1) { + const currentDay = Math.floor(new Date().getTime() / (86400 * 1000)); + const queryKey = `explore-${currentDay - i}-${ev}`; + self.toolDb.addKeyListener(queryKey, handleExploreData); + self.toolDb.subscribeData(queryKey); + } + } + if (_eventId === "aggregated-standard") { + queryForEvent("Ladder"); + queryForEvent("Play"); + queryForEvent("Constructed_BestOf3"); + queryForEvent("Constructed_Event_2020"); + queryForEvent("Constructed_Event_2021"); + queryForEvent("Constructed_Event_v2"); + queryForEvent("Traditional_Cons_Event_2020"); + queryForEvent("Traditional_Cons_Event_2021"); + queryForEvent("Traditional_Cons_Event_2022"); + queryForEvent("Traditional_Cons_Event_2023"); + queryForEvent("Traditional_Ladder"); + queryForEvent("Standard_Challenge_20230421"); + } + else if (_eventId === "aggregated-historic") { + queryForEvent("Historic_Ladder"); + queryForEvent("Historic_Play"); + queryForEvent("Historic_Event_v2"); + queryForEvent("Historic_Event"); + queryForEvent("Traditional_Historic_Event"); + queryForEvent("Traditional_Historic_Play"); + queryForEvent("Traditional_Historic_Ladder"); + } + else if (_eventId === "aggregated-timeless") { + queryForEvent("Timeless_Ladder"); + queryForEvent("Timeless_Play"); + queryForEvent("Timeless_Event_v2"); + queryForEvent("Timeless_Event"); + queryForEvent("Traditional_Timeless_Event"); + queryForEvent("Traditional_Timeless_Play"); + queryForEvent("Traditional_Timeless_Ladder"); + } + else if (_eventId === "aggregated-alchemy") { + queryForEvent("Alchemy_Ladder"); + queryForEvent("Alchemy_Play"); + queryForEvent("Alchemy_Event"); + queryForEvent("Traditional_Alchemy_Event_2022"); + queryForEvent("Traditional_Alchemy_Event_2023"); + queryForEvent("Traditional_Alchemy_Event"); + queryForEvent("Traditional_Alchemy_Play"); + queryForEvent("Traditional_Alchemy_Ladder"); + } + else if (_eventId === "aggregated-explorer") { + queryForEvent("Explorer_Ladder"); + queryForEvent("Explorer_Play"); + queryForEvent("Explorer_Event"); + queryForEvent("Explorer_Event_v2"); + queryForEvent("Traditional_Explorer_Event"); + queryForEvent("Traditional_Explorer_Play"); + queryForEvent("Traditional_Explorer_Ladder"); + } + else { + queryForEvent(_eventId); + } + continnuousCheck(); +} +exports.beginDataQuery = beginDataQuery; },{"automerge":85,"mtgatool-db":292}],7:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -/* eslint-disable no-restricted-globals */ -function getConnectionData() { - const networkModule = self.toolDb.network; - const connectionData = Object.keys(networkModule.clientToSend).map((peerId) => { - const serverPeerData = networkModule.serverPeerData[peerId]; - const peerData = self.toolDb.peers[peerId]; - const host = peerData === null || peerData === void 0 ? void 0 : peerData.host; - const peerHost = !host || host === "127.0.0.1" ? peerId.slice(-20) : host; - const socket = networkModule.clientSocket[peerId]; - return { - peerId, - peerData, - serverPeerData: serverPeerData, - host: (serverPeerData === null || serverPeerData === void 0 ? void 0 : serverPeerData.name) || peerHost, - readyState: socket === null || socket === void 0 ? void 0 : socket.readyState, - isConnected: (socket === null || socket === void 0 ? void 0 : socket.readyState) === socket.OPEN, - }; - }); - self.postMessage({ type: `CONNECTION_DATA`, value: connectionData }); -} -exports.default = getConnectionData; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-restricted-globals */ +function getConnectionData() { + const networkModule = self.toolDb.network; + const connectionData = Object.keys(networkModule.clientToSend).map((peerId) => { + const serverPeerData = networkModule.serverPeerData[peerId]; + const peerData = self.toolDb.peers[peerId]; + const host = peerData === null || peerData === void 0 ? void 0 : peerData.host; + const peerHost = !host || host === "127.0.0.1" ? peerId.slice(-20) : host; + const socket = networkModule.clientSocket[peerId]; + return { + peerId, + peerData, + serverPeerData: serverPeerData, + host: (serverPeerData === null || serverPeerData === void 0 ? void 0 : serverPeerData.name) || peerHost, + readyState: socket === null || socket === void 0 ? void 0 : socket.readyState, + isConnected: (socket === null || socket === void 0 ? void 0 : socket.readyState) === socket.OPEN, + }; + }); + self.postMessage({ type: `CONNECTION_DATA`, value: connectionData }); +} +exports.default = getConnectionData; },{}],8:[function(require,module,exports){ -"use strict"; -/* eslint-disable no-restricted-globals */ -Object.defineProperty(exports, "__esModule", { value: true }); -function getCrdt(msgId, key, userNamespaced, timeoutMs = 5000) { - return self.toolDb - .getCrdt(key, userNamespaced, timeoutMs) - .then((value) => { - self.postMessage({ type: `${msgId}_OK`, value }); - }) - .catch((err) => { - self.postMessage({ type: `${msgId}_ERR`, err }); - }); -} -exports.default = getCrdt; +"use strict"; +/* eslint-disable no-restricted-globals */ +Object.defineProperty(exports, "__esModule", { value: true }); +function getCrdt(msgId, key, userNamespaced, timeoutMs = 5000) { + return self.toolDb + .getCrdt(key, userNamespaced, timeoutMs) + .then((value) => { + self.postMessage({ type: `${msgId}_OK`, value }); + }) + .catch((err) => { + self.postMessage({ type: `${msgId}_ERR`, err }); + }); +} +exports.default = getCrdt; },{}],9:[function(require,module,exports){ -"use strict"; -/* eslint-disable no-restricted-globals */ -Object.defineProperty(exports, "__esModule", { value: true }); -function getData(msgId, key, userNamespaced, timeoutMs = 5000) { - return self.toolDb - .getData(key, userNamespaced, timeoutMs) - .then((value) => { - self.postMessage({ type: `${msgId}_OK`, value }); - }) - .catch((err) => { - self.postMessage({ type: `${msgId}_ERR`, err }); - }); -} -exports.default = getData; +"use strict"; +/* eslint-disable no-restricted-globals */ +Object.defineProperty(exports, "__esModule", { value: true }); +function getData(msgId, key, userNamespaced, timeoutMs = 5000) { + return self.toolDb + .getData(key, userNamespaced, timeoutMs) + .then((value) => { + self.postMessage({ type: `${msgId}_OK`, value }); + }) + .catch((err) => { + self.postMessage({ type: `${msgId}_ERR`, err }); + }); +} +exports.default = getData; },{}],10:[function(require,module,exports){ -"use strict"; -/* eslint-disable no-restricted-globals */ -Object.defineProperty(exports, "__esModule", { value: true }); -function getDataLocal(msgId, key) { - return new Promise((resolve) => { - self.toolDb.store.get(key, (err, data) => { - if (err) { - self.postMessage({ type: `${msgId}_ERR`, err }); - } - else if (data) { - try { - const json = JSON.parse(data); - self.postMessage({ type: `${msgId}_OK`, value: json.v }); - resolve(json.v); - } - catch (_e) { - self.postMessage({ type: `${msgId}_ERR`, err: _e }); - } - } - else { - self.postMessage({ type: `${msgId}_ERR`, err: "No data" }); - } - }); - }); -} -exports.default = getDataLocal; +"use strict"; +/* eslint-disable no-restricted-globals */ +Object.defineProperty(exports, "__esModule", { value: true }); +function getDataLocal(msgId, key) { + return new Promise((resolve) => { + self.toolDb.store.get(key, (err, data) => { + if (err) { + self.postMessage({ type: `${msgId}_ERR`, err }); + } + else if (data) { + try { + const json = JSON.parse(data); + self.postMessage({ type: `${msgId}_OK`, value: json.v }); + resolve(json.v); + } + catch (_e) { + self.postMessage({ type: `${msgId}_ERR`, err: _e }); + } + } + else { + self.postMessage({ type: `${msgId}_ERR`, err: "No data" }); + } + }); + }); +} +exports.default = getDataLocal; },{}],11:[function(require,module,exports){ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getMatchesData = exports.getMatchesDataLocal = exports.convertDbMatchToData = void 0; -const getRankFilterVal_1 = __importDefault(require("./getRankFilterVal")); -function convertDbMatchToData(match) { - const { internalMatch } = match; - return { - uuid: match.playerId, - matchId: match.matchId, - internalMatch: match.internalMatch, - playerDeckName: internalMatch.player.name, - timestamp: match.timestamp, - duration: match.duration, - win: match.playerWins > match.playerLosses, - eventId: match.eventId, - playerDeckColors: match.playerDeckColors, - oppDeckColors: match.oppDeckColors, - playerWins: match.playerWins, - playerLosses: match.playerLosses, - rank: (0, getRankFilterVal_1.default)(internalMatch.player.rank), - }; -} -exports.convertDbMatchToData = convertDbMatchToData; -function getLocalData(key) { - return new Promise((resolve) => { - self.toolDb.store.get(key, (err, data) => { - if (err) { - resolve(undefined); - } - else if (data) { - try { - const json = JSON.parse(data); - resolve(json.v); - } - catch (_e) { - resolve(undefined); - } - } - else { - resolve(undefined); - } - }); - }); -} -function getMatchesDataLocal(msgId, matchesIds, uuid) { - const promises = matchesIds.map((id) => { - return getLocalData(id); - }); - Promise.all(promises) - .then((matches) => matches.filter((m) => m).map((m) => convertDbMatchToData(m))) - .then((data) => { - self.postMessage({ - type: `${msgId}_OK`, - value: data.filter((m) => (uuid ? m.uuid === uuid : true)), - }); - }); -} -exports.getMatchesDataLocal = getMatchesDataLocal; -function getMatchesData(msgId, matchesIds, uuid, updateCallback) { - const matchesIndex = [...new Set([...(matchesIds || [])])]; - let saved = 0; - let timeout = null; - let lastUpdate = new Date().getTime(); - function updateState() { - timeout = null; - if (updateCallback) { - updateCallback(matchesIndex.length, saved); - } - if (saved === matchesIndex.length && matchesIndex.length > 0) { - getMatchesDataLocal(msgId, matchesIndex, uuid); - } - } - function debounceUpdateState() { - if (timeout) - clearTimeout(timeout); - if (new Date().getTime() - lastUpdate > 1000) { - lastUpdate = new Date().getTime(); - updateState(); - } - timeout = setTimeout(updateState, 100); - } - // Fetch any match we dont have locally - matchesIndex.forEach((id) => { - self.toolDb.store.get(id, (err) => { - if (!err) { - saved += 1; - debounceUpdateState(); - } - else { - self.toolDb.getData(id, false, 2000).finally(() => { - saved += 1; - debounceUpdateState(); - }); - } - }); - }); - updateState(); -} -exports.getMatchesData = getMatchesData; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getMatchesData = exports.getMatchesDataLocal = exports.convertDbMatchToData = void 0; +const getRankFilterVal_1 = __importDefault(require("./getRankFilterVal")); +function convertDbMatchToData(match) { + const { internalMatch } = match; + return { + uuid: match.playerId, + matchId: match.matchId, + internalMatch: match.internalMatch, + playerDeckName: internalMatch.player.name, + timestamp: match.timestamp, + duration: match.duration, + win: match.playerWins > match.playerLosses, + eventId: match.eventId, + playerDeckColors: match.playerDeckColors, + oppDeckColors: match.oppDeckColors, + playerWins: match.playerWins, + playerLosses: match.playerLosses, + rank: (0, getRankFilterVal_1.default)(internalMatch.player.rank), + }; +} +exports.convertDbMatchToData = convertDbMatchToData; +function getLocalData(key) { + return new Promise((resolve) => { + self.toolDb.store.get(key, (err, data) => { + if (err) { + resolve(undefined); + } + else if (data) { + try { + const json = JSON.parse(data); + resolve(json.v); + } + catch (_e) { + resolve(undefined); + } + } + else { + resolve(undefined); + } + }); + }); +} +function getMatchesDataLocal(msgId, matchesIds, uuid) { + const promises = matchesIds.map((id) => { + return getLocalData(id); + }); + Promise.all(promises) + .then((matches) => matches.filter((m) => m).map((m) => convertDbMatchToData(m))) + .then((data) => { + self.postMessage({ + type: `${msgId}_OK`, + value: data.filter((m) => (uuid ? m.uuid === uuid : true)), + }); + }); +} +exports.getMatchesDataLocal = getMatchesDataLocal; +function getMatchesData(msgId, matchesIds, uuid, updateCallback) { + const matchesIndex = [...new Set([...(matchesIds || [])])]; + let saved = 0; + let timeout = null; + let lastUpdate = new Date().getTime(); + function updateState() { + timeout = null; + if (updateCallback) { + updateCallback(matchesIndex.length, saved); + } + if (saved === matchesIndex.length && matchesIndex.length > 0) { + getMatchesDataLocal(msgId, matchesIndex, uuid); + } + } + function debounceUpdateState() { + if (timeout) + clearTimeout(timeout); + if (new Date().getTime() - lastUpdate > 1000) { + lastUpdate = new Date().getTime(); + updateState(); + } + timeout = setTimeout(updateState, 100); + } + // Fetch any match we dont have locally + matchesIndex.forEach((id) => { + self.toolDb.store.get(id, (err) => { + if (!err) { + saved += 1; + debounceUpdateState(); + } + else { + self.toolDb.getData(id, false, 2000).finally(() => { + saved += 1; + debounceUpdateState(); + }); + } + }); + }); + updateState(); +} +exports.getMatchesData = getMatchesData; },{"./getRankFilterVal":12}],12:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.RANK_MYTHIC = exports.RANK_DIAMOND = exports.RANK_PLATINUM = exports.RANK_GOLD = exports.RANK_SILVER = exports.RANK_BRONZE = void 0; -exports.RANK_BRONZE = 1; -exports.RANK_SILVER = 2; -exports.RANK_GOLD = 4; -exports.RANK_PLATINUM = 8; -exports.RANK_DIAMOND = 16; -exports.RANK_MYTHIC = 32; -function getRankFilterVal(rank) { - let ret = 0; - switch (rank) { - case "Unranked": - ret = 0; - break; - case "Bronze": - ret = exports.RANK_BRONZE; - break; - case "Silver": - ret = exports.RANK_SILVER; - break; - case "Gold": - ret = exports.RANK_GOLD; - break; - case "Platinum": - ret = exports.RANK_PLATINUM; - break; - case "Diamond": - ret = exports.RANK_DIAMOND; - break; - case "Mythic": - ret = exports.RANK_MYTHIC; - break; - default: - break; - } - return ret; -} -exports.default = getRankFilterVal; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.RANK_MYTHIC = exports.RANK_DIAMOND = exports.RANK_PLATINUM = exports.RANK_GOLD = exports.RANK_SILVER = exports.RANK_BRONZE = void 0; +exports.RANK_BRONZE = 1; +exports.RANK_SILVER = 2; +exports.RANK_GOLD = 4; +exports.RANK_PLATINUM = 8; +exports.RANK_DIAMOND = 16; +exports.RANK_MYTHIC = 32; +function getRankFilterVal(rank) { + let ret = 0; + switch (rank) { + case "Unranked": + ret = 0; + break; + case "Bronze": + ret = exports.RANK_BRONZE; + break; + case "Silver": + ret = exports.RANK_SILVER; + break; + case "Gold": + ret = exports.RANK_GOLD; + break; + case "Platinum": + ret = exports.RANK_PLATINUM; + break; + case "Diamond": + ret = exports.RANK_DIAMOND; + break; + case "Mythic": + ret = exports.RANK_MYTHIC; + break; + default: + break; + } + return ret; +} +exports.default = getRankFilterVal; },{}],13:[function(require,module,exports){ -"use strict"; -/* eslint-disable no-restricted-globals */ -Object.defineProperty(exports, "__esModule", { value: true }); -const mtgatool_db_1 = require("mtgatool-db"); -function getSaveKeysJson() { - return new Promise((resolve) => { - if (self.toolDb.user) { - (0, mtgatool_db_1.saveKeysComb)(self.toolDb.user.keys.signKeys, self.toolDb.user.keys.encryptionKeys).then((keys) => { - var _a; - const saveKeys = { keys: keys, userName: ((_a = self.toolDb.user) === null || _a === void 0 ? void 0 : _a.name) || "" }; - self.postMessage({ type: `SAVE_KEYS_JSON`, value: saveKeys }); - resolve(saveKeys); - }); - } - else { - resolve(null); - } - }); -} -exports.default = getSaveKeysJson; +"use strict"; +/* eslint-disable no-restricted-globals */ +Object.defineProperty(exports, "__esModule", { value: true }); +const mtgatool_db_1 = require("mtgatool-db"); +function getSaveKeysJson() { + return new Promise((resolve) => { + if (self.toolDb.user) { + (0, mtgatool_db_1.saveKeysComb)(self.toolDb.user.keys.signKeys, self.toolDb.user.keys.encryptionKeys).then((keys) => { + var _a; + const saveKeys = { keys: keys, userName: ((_a = self.toolDb.user) === null || _a === void 0 ? void 0 : _a.name) || "" }; + self.postMessage({ type: `SAVE_KEYS_JSON`, value: saveKeys }); + resolve(saveKeys); + }); + } + else { + resolve(null); + } + }); +} +exports.default = getSaveKeysJson; },{"mtgatool-db":292}],14:[function(require,module,exports){ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -/* eslint-disable no-restricted-globals */ -const reduxAction_1 = __importDefault(require("./reduxAction")); -function handleDraftsIndex(draftsIndex) { - self.globalData.draftsIndex = [ - ...new Set([...self.globalData.draftsIndex, ...(draftsIndex || [])]), - ]; - console.log("handleDraftsIndex", self.globalData.draftsIndex); - // Fetch any match we dont have locally - self.globalData.draftsIndex.forEach((id) => { - self.toolDb.store.get(id, (err, data) => { - if (!data) { - self.toolDb.getData(id, false, 2000); - } - }); - }); - (0, reduxAction_1.default)("SET_DRAFTS_INDEX", self.globalData.draftsIndex); -} -exports.default = handleDraftsIndex; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-restricted-globals */ +const reduxAction_1 = __importDefault(require("./reduxAction")); +function handleDraftsIndex(draftsIndex) { + self.globalData.draftsIndex = [ + ...new Set([...self.globalData.draftsIndex, ...(draftsIndex || [])]), + ]; + console.log("handleDraftsIndex", self.globalData.draftsIndex); + // Fetch any match we dont have locally + self.globalData.draftsIndex.forEach((id) => { + self.toolDb.store.get(id, (err, data) => { + if (!data) { + self.toolDb.getData(id, false, 2000); + } + }); + }); + (0, reduxAction_1.default)("SET_DRAFTS_INDEX", self.globalData.draftsIndex); +} +exports.default = handleDraftsIndex; },{"./reduxAction":22}],15:[function(require,module,exports){ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -/* eslint-disable no-restricted-globals */ -const automerge_1 = __importDefault(require("automerge")); -const mtgatool_db_1 = require("mtgatool-db"); -const reduxAction_1 = __importDefault(require("./reduxAction")); -function handleLiveFeed(msg) { - console.log("Key Listener live feed ", msg); - if (msg && msg.type === "crdt") { - if (self.globalData.liveFeed) { - const doc = automerge_1.default.load((0, mtgatool_db_1.base64ToBinaryDocument)(msg.doc)); - try { - self.globalData.liveFeed = automerge_1.default.merge(automerge_1.default.init(), doc); - } - catch (e) { - console.warn(e); - } - const filteredLiveFeed = Object.keys(self.globalData.liveFeed) - .sort((a, b) => { - if (self.globalData.liveFeed[a] > self.globalData.liveFeed[b]) - return -1; - if (self.globalData.liveFeed[a] < self.globalData.liveFeed[b]) - return 1; - return 0; - }) - .slice(0, 10); - (0, reduxAction_1.default)("SET_LIVE_FEED", filteredLiveFeed); - // Fetch any match we dont have locally - filteredLiveFeed.forEach((id) => { - self.toolDb.store.get(id, (err, data) => { - if (!data) { - self.toolDb.getData(id, false).then((match) => { - (0, reduxAction_1.default)("SET_LIVE_FEED_MATCH", { key: id, match: match }); - }); - } - else { - (0, reduxAction_1.default)("SET_LIVE_FEED_MATCH", { - key: id, - match: JSON.parse(data).v, - }); - } - }); - }); - } - } -} -exports.default = handleLiveFeed; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-restricted-globals */ +const automerge_1 = __importDefault(require("automerge")); +const mtgatool_db_1 = require("mtgatool-db"); +const reduxAction_1 = __importDefault(require("./reduxAction")); +function handleLiveFeed(msg) { + console.log("Key Listener live feed ", msg); + if (msg && msg.type === "crdt") { + if (self.globalData.liveFeed) { + const doc = automerge_1.default.load((0, mtgatool_db_1.base64ToBinaryDocument)(msg.doc)); + try { + self.globalData.liveFeed = automerge_1.default.merge(automerge_1.default.init(), doc); + } + catch (e) { + console.warn(e); + } + const filteredLiveFeed = Object.keys(self.globalData.liveFeed) + .sort((a, b) => { + if (self.globalData.liveFeed[a] > self.globalData.liveFeed[b]) + return -1; + if (self.globalData.liveFeed[a] < self.globalData.liveFeed[b]) + return 1; + return 0; + }) + .slice(0, 10); + (0, reduxAction_1.default)("SET_LIVE_FEED", filteredLiveFeed); + // Fetch any match we dont have locally + filteredLiveFeed.forEach((id) => { + self.toolDb.store.get(id, (err, data) => { + if (!data) { + self.toolDb.getData(id, false).then((match) => { + (0, reduxAction_1.default)("SET_LIVE_FEED_MATCH", { key: id, match: match }); + }); + } + else { + (0, reduxAction_1.default)("SET_LIVE_FEED_MATCH", { + key: id, + match: JSON.parse(data).v, + }); + } + }); + }); + } + } +} +exports.default = handleLiveFeed; },{"./reduxAction":22,"automerge":85,"mtgatool-db":292}],16:[function(require,module,exports){ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -/* eslint-disable no-restricted-globals */ -const getMatchesData_1 = require("./getMatchesData"); -const reduxAction_1 = __importDefault(require("./reduxAction")); -function handleMatchesIndex(matchesIds) { - if (matchesIds) { - (0, reduxAction_1.default)("SET_REMOTE_MATCHES_INDEX", matchesIds); - (0, getMatchesData_1.getMatchesData)("MATCHES_DATA", matchesIds, self.globalData.currentUUID, (total, saved) => { - (0, reduxAction_1.default)("SET_MATCHES_FETCH_STATE", { - total, - saved, - }); - }); - } -} -exports.default = handleMatchesIndex; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-restricted-globals */ +const getMatchesData_1 = require("./getMatchesData"); +const reduxAction_1 = __importDefault(require("./reduxAction")); +function handleMatchesIndex(matchesIds) { + if (matchesIds) { + (0, reduxAction_1.default)("SET_REMOTE_MATCHES_INDEX", matchesIds); + (0, getMatchesData_1.getMatchesData)("MATCHES_DATA", matchesIds, self.globalData.currentUUID, (total, saved) => { + (0, reduxAction_1.default)("SET_MATCHES_FETCH_STATE", { + total, + saved, + }); + }); + } +} +exports.default = handleMatchesIndex; },{"./getMatchesData":11,"./reduxAction":22}],17:[function(require,module,exports){ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -/* eslint-disable no-restricted-globals */ -const mtgatool_db_1 = require("mtgatool-db"); -const afterLogin_1 = __importDefault(require("./afterLogin")); -const reduxAction_1 = __importDefault(require("./reduxAction")); -function keysLogin(keys) { - return new Promise((resolve, reject) => { - (0, mtgatool_db_1.loadKeysComb)(keys).then((importedKeys) => { - if (importedKeys) { - (0, mtgatool_db_1.exportKey)("spki", importedKeys.signKeys.publicKey) - .then((skpub) => (0, mtgatool_db_1.encodeKeyString)(skpub)) - .then((pubKey) => { - console.log("keys", keys); - console.log("pubKey", pubKey); - self.toolDb - .getData(`:${pubKey}.username`, false, 5000) - .then((username) => { - console.log("username", username); - self.toolDb - .keysSignIn(importedKeys, username || "") - .then(() => { - self.postMessage({ type: "LOGIN_OK" }); - (0, reduxAction_1.default)("SET_PUBKEY", pubKey); - (0, reduxAction_1.default)("SET_MY_USERNAME", username); - (0, afterLogin_1.default)(); - resolve(); - }); - }); - }); - } - else { - reject(new Error("Something went wrong when importing the keys")); - } - }); - }); -} -exports.default = keysLogin; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-restricted-globals */ +const mtgatool_db_1 = require("mtgatool-db"); +const afterLogin_1 = __importDefault(require("./afterLogin")); +const reduxAction_1 = __importDefault(require("./reduxAction")); +function keysLogin(keys) { + return new Promise((resolve, reject) => { + (0, mtgatool_db_1.loadKeysComb)(keys).then((importedKeys) => { + if (importedKeys) { + (0, mtgatool_db_1.exportKey)("spki", importedKeys.signKeys.publicKey) + .then((skpub) => (0, mtgatool_db_1.encodeKeyString)(skpub)) + .then((pubKey) => { + console.log("keys", keys); + console.log("pubKey", pubKey); + self.toolDb + .getData(`:${pubKey}.username`, false, 5000) + .then((username) => { + console.log("username", username); + self.toolDb + .keysSignIn(importedKeys, username || "") + .then(() => { + self.postMessage({ type: "LOGIN_OK" }); + (0, reduxAction_1.default)("SET_PUBKEY", pubKey); + (0, reduxAction_1.default)("SET_MY_USERNAME", username); + (0, afterLogin_1.default)(); + resolve(); + }); + }); + }); + } + else { + reject(new Error("Something went wrong when importing the keys")); + } + }); + }); +} +exports.default = keysLogin; },{"./afterLogin":3,"./reduxAction":22,"mtgatool-db":292}],18:[function(require,module,exports){ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -/* eslint-disable no-restricted-globals */ -const afterLogin_1 = __importDefault(require("./afterLogin")); -const reduxAction_1 = __importDefault(require("./reduxAction")); -function login(username, password) { - return self.toolDb - .signIn(username, password) - .then((keys) => { - var _a; - self.toolDb.putData("username", username, true); - (0, afterLogin_1.default)(); - self.postMessage({ type: "LOGIN_OK" }); - (0, reduxAction_1.default)("SET_PUBKEY", (_a = self.toolDb.user) === null || _a === void 0 ? void 0 : _a.pubKey); - return keys; - }) - .catch((err) => { - self.postMessage({ type: "LOGIN_ERR", err }); - }); -} -exports.default = login; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-restricted-globals */ +const afterLogin_1 = __importDefault(require("./afterLogin")); +const reduxAction_1 = __importDefault(require("./reduxAction")); +function login(username, password) { + return self.toolDb + .signIn(username, password) + .then((keys) => { + var _a; + self.toolDb.putData("username", username, true); + (0, afterLogin_1.default)(); + self.postMessage({ type: "LOGIN_OK" }); + (0, reduxAction_1.default)("SET_PUBKEY", (_a = self.toolDb.user) === null || _a === void 0 ? void 0 : _a.pubKey); + return keys; + }) + .catch((err) => { + self.postMessage({ type: "LOGIN_ERR", err }); + }); +} +exports.default = login; },{"./afterLogin":3,"./reduxAction":22}],19:[function(require,module,exports){ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -/* eslint-disable no-restricted-globals */ -/* eslint-disable no-param-reassign */ -const automerge_1 = __importDefault(require("automerge")); -async function pushToExplore(key, match) { - // Create CRDT document with the new match added to it - try { - const docInit = automerge_1.default.init(); - const { eventId } = match; - if (!eventId.includes("NPE_") && !eventId.includes("ColorChallenge_")) { - const newDocument = automerge_1.default.change(docInit, (doc) => { - doc[key] = new Date(match.internalMatch.date).getTime(); - }); - const currentDay = Math.floor(new Date().getTime() / (86400 * 1000)); - self.toolDb - .putCrdt(`explore-${currentDay}-${eventId}`, automerge_1.default.getChanges(docInit, newDocument), false) - .catch(console.error); - } - } - catch (e) { - console.warn(e); - } -} -exports.default = pushToExplore; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-restricted-globals */ +/* eslint-disable no-param-reassign */ +const automerge_1 = __importDefault(require("automerge")); +async function pushToExplore(key, match) { + // Create CRDT document with the new match added to it + try { + const docInit = automerge_1.default.init(); + const { eventId } = match; + if (!eventId.includes("NPE_") && !eventId.includes("ColorChallenge_")) { + const newDocument = automerge_1.default.change(docInit, (doc) => { + doc[key] = new Date(match.internalMatch.date).getTime(); + }); + const currentDay = Math.floor(new Date().getTime() / (86400 * 1000)); + self.toolDb + .putCrdt(`explore-${currentDay}-${eventId}`, automerge_1.default.getChanges(docInit, newDocument), false) + .catch(console.error); + } + } + catch (e) { + console.warn(e); + } +} +exports.default = pushToExplore; },{"automerge":85}],20:[function(require,module,exports){ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -/* eslint-disable no-restricted-globals */ -/* eslint-disable no-param-reassign */ -const automerge_1 = __importDefault(require("automerge")); -async function pushToLiveFeed(key, match) { - if (!self.globalData.liveFeed[key]) { - // Create CRDT document with the new match added to it - try { - const origDoc = automerge_1.default.init(); - const newLiveFeed = automerge_1.default.change(origDoc, (doc) => { - doc[key] = new Date(match.internalMatch.date).getTime(); - }); - const currentDay = Math.floor(new Date().getTime() / (86400 * 1000)); - self.toolDb - .putCrdt(`matches-livefeed-${currentDay}`, automerge_1.default.getChanges(origDoc, newLiveFeed), false) - .catch(console.error); - // self.globalData.liveFeed = newLiveFeed; - } - catch (e) { - console.warn(e); - } - } -} -exports.default = pushToLiveFeed; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-restricted-globals */ +/* eslint-disable no-param-reassign */ +const automerge_1 = __importDefault(require("automerge")); +async function pushToLiveFeed(key, match) { + if (!self.globalData.liveFeed[key]) { + // Create CRDT document with the new match added to it + try { + const origDoc = automerge_1.default.init(); + const newLiveFeed = automerge_1.default.change(origDoc, (doc) => { + doc[key] = new Date(match.internalMatch.date).getTime(); + }); + const currentDay = Math.floor(new Date().getTime() / (86400 * 1000)); + self.toolDb + .putCrdt(`matches-livefeed-${currentDay}`, automerge_1.default.getChanges(origDoc, newLiveFeed), false) + .catch(console.error); + // self.globalData.liveFeed = newLiveFeed; + } + catch (e) { + console.warn(e); + } + } +} +exports.default = pushToLiveFeed; },{"automerge":85}],21:[function(require,module,exports){ -"use strict"; -/* eslint-disable no-restricted-globals */ -Object.defineProperty(exports, "__esModule", { value: true }); -function queryKeys(msgId, key, userNamespaced, timeoutMs = 5000) { - return self.toolDb - .queryKeys(key, userNamespaced, timeoutMs) - .then((value) => { - self.postMessage({ type: `${msgId}_OK`, value }); - }) - .catch((err) => { - self.postMessage({ type: `${msgId}_ERR`, err }); - }); -} -exports.default = queryKeys; +"use strict"; +/* eslint-disable no-restricted-globals */ +Object.defineProperty(exports, "__esModule", { value: true }); +function queryKeys(msgId, key, userNamespaced, timeoutMs = 5000) { + return self.toolDb + .queryKeys(key, userNamespaced, timeoutMs) + .then((value) => { + self.postMessage({ type: `${msgId}_OK`, value }); + }) + .catch((err) => { + self.postMessage({ type: `${msgId}_ERR`, err }); + }); +} +exports.default = queryKeys; },{}],22:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -/* eslint-disable no-restricted-globals */ -function reduxAction(type, arg) { - self.postMessage({ type: "REDUX_ACTION", arg: { type, arg } }); -} -exports.default = reduxAction; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-restricted-globals */ +function reduxAction(type, arg) { + self.postMessage({ type: "REDUX_ACTION", arg: { type, arg } }); +} +exports.default = reduxAction; },{}],23:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const constants_1 = require("./constants"); -/* eslint-disable no-restricted-globals */ -function removeHost(host) { - const networkModule = self.toolDb.network; - networkModule.disconnect(host); - // Try to conenct to servers from cache - self.toolDb.store.get(constants_1.SAVED_PEERS_KEY, (err, data) => { - let savedPeers = constants_1.DEFAULT_PEERS; - if (err) { - console.error("Error getting saved peers from cache:", err); - } - else if (data) { - try { - const newPeers = JSON.parse(data); - savedPeers = newPeers; - } - catch (_e) { - console.error("Error parsing saved peers from cache:", _e); - } - } - savedPeers = savedPeers.filter((peer) => peer !== host); - self.toolDb.store.put(constants_1.SAVED_PEERS_KEY, JSON.stringify(savedPeers), () => { - console.log("Saved peers to cache", savedPeers); - }); - }); -} -exports.default = removeHost; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const constants_1 = require("./constants"); +/* eslint-disable no-restricted-globals */ +function removeHost(host) { + const networkModule = self.toolDb.network; + networkModule.disconnect(host); + // Try to conenct to servers from cache + self.toolDb.store.get(constants_1.SAVED_PEERS_KEY, (err, data) => { + let savedPeers = constants_1.DEFAULT_PEERS; + if (err) { + console.error("Error getting saved peers from cache:", err); + } + else if (data) { + try { + const newPeers = JSON.parse(data); + savedPeers = newPeers; + } + catch (_e) { + console.error("Error parsing saved peers from cache:", _e); + } + } + savedPeers = savedPeers.filter((peer) => peer !== host); + self.toolDb.store.put(constants_1.SAVED_PEERS_KEY, JSON.stringify(savedPeers), () => { + console.log("Saved peers to cache", savedPeers); + }); + }); +} +exports.default = removeHost; },{"./constants":4}],24:[function(require,module,exports){ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const login_1 = __importDefault(require("./login")); -function waitMs(ms) { - return new Promise((resolve) => { - setTimeout(() => resolve(true), ms); - }); -} -/** - * Sign up process - * @param username plaintext username - * @param password sha1 of the plaintext password - * @returns Promise - */ -function signup(username, password) { - return self.toolDb - .signUp(username, password) - .then((msg) => { - // console.log("Sent signup! now wait"); - return waitMs(3000).then(() => { - // console.log("wait finished, now login"); - return (0, login_1.default)(username, password).then((_keys) => { - // console.log("login ok!?"); - return self.toolDb - .putData("userids", {}, true) - .then((_put) => { - return msg; - }); - }); - }); - }) - .catch((err) => { - self.postMessage({ type: "SIGNUP_ERR", err }); - }); -} -exports.default = signup; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const login_1 = __importDefault(require("./login")); +function waitMs(ms) { + return new Promise((resolve) => { + setTimeout(() => resolve(true), ms); + }); +} +/** + * Sign up process + * @param username plaintext username + * @param password sha1 of the plaintext password + * @returns Promise + */ +function signup(username, password) { + return self.toolDb + .signUp(username, password) + .then((msg) => { + // console.log("Sent signup! now wait"); + return waitMs(3000).then(() => { + // console.log("wait finished, now login"); + return (0, login_1.default)(username, password).then((_keys) => { + // console.log("login ok!?"); + return self.toolDb + .putData("userids", {}, true) + .then((_put) => { + return msg; + }); + }); + }); + }) + .catch((err) => { + self.postMessage({ type: "SIGNUP_ERR", err }); + }); +} +exports.default = signup; },{"./login":18}],25:[function(require,module,exports){ -"use strict"; -/* eslint-disable no-restricted-globals */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const mtgatool_db_1 = require("mtgatool-db"); -const addHost_1 = __importDefault(require("./addHost")); -const addKeyListener_1 = __importDefault(require("./addKeyListener")); -const constants_1 = require("./constants"); -const doFunction_1 = __importDefault(require("./doFunction")); -const exploreAggregation_1 = require("./exploreAggregation"); -const getConnectionData_1 = __importDefault(require("./getConnectionData")); -const getCrdt_1 = __importDefault(require("./getCrdt")); -const getData_1 = __importDefault(require("./getData")); -const getDataLocal_1 = __importDefault(require("./getDataLocal")); -const getMatchesData_1 = require("./getMatchesData"); -const getSaveKeysJson_1 = __importDefault(require("./getSaveKeysJson")); -const handleMatchesIndex_1 = __importDefault(require("./handleMatchesIndex")); -const keysLogin_1 = __importDefault(require("./keysLogin")); -const login_1 = __importDefault(require("./login")); -const pushToExplore_1 = __importDefault(require("./pushToExplore")); -const pushToLivefeed_1 = __importDefault(require("./pushToLivefeed")); -const queryKeys_1 = __importDefault(require("./queryKeys")); -const reduxAction_1 = __importDefault(require("./reduxAction")); -const removeHost_1 = __importDefault(require("./removeHost")); -const signup_1 = __importDefault(require("./signup")); -const toolDb = new mtgatool_db_1.ToolDb({ - topic: "mtgatool-db-swarm-v4", - // debug: true, - server: false, - maxRetries: 999, -}); -toolDb.on("init", (key) => console.warn("ToolDb initialized!", key)); -// Try to conenct to servers from cache -toolDb.store.get(constants_1.SAVED_PEERS_KEY, (err, savedData) => { - let savedPeers = constants_1.DEFAULT_PEERS; - if (err) { - toolDb.store.put(constants_1.SAVED_PEERS_KEY, JSON.stringify(constants_1.DEFAULT_PEERS), () => { - console.log("Saved default peers to cache"); - }); - } - else if (savedData) { - try { - const newPeers = JSON.parse(savedData); - savedPeers = newPeers; - } - catch (_e) { - console.error("Error parsing saved peers from cache:", _e); - } - } - toolDb.store.get(constants_1.SERVERS_KEY, (serr, data) => { - let serversData = {}; - if (serr) { - console.error("Error getting servers from cache:", serr); - } - else if (data) { - try { - serversData = JSON.parse(data); - } - catch (_e) { - console.error("Error parsing servers from cache:", _e); - } - } - console.log("Got servers from cache:", serversData); - savedPeers.forEach((peer) => { - const networkModule = toolDb.network; - if (serversData[peer]) { - networkModule.connectTo(serversData[peer]); - } - else { - networkModule.findServer(peer); - } - }); - }); -}); -toolDb.onConnect = () => { - const networkModule = toolDb.network; - (0, reduxAction_1.default)("SET_OFFLINE", false); - self.postMessage({ type: "CONNECTED" }); - toolDb.store.put(constants_1.SERVERS_KEY, JSON.stringify(networkModule.serverPeerData), () => console.log("Saved servers to cache", networkModule.serverPeerData)); -}; -toolDb.onDisconnect = () => { - (0, reduxAction_1.default)("SET_OFFLINE", true); -}; -self.toolDb = toolDb; -self.globalData = { - hiddenDecks: [], - liveFeed: {}, - fetchedAvatars: [], - matchesIndex: [], - draftsIndex: [], - currentUUID: "", -}; -self.onmessage = (e) => { - const { type } = e.data; - // console.log("Worker onmessage:", e.type, e.data); - switch (type) { - case "LOGIN": - (0, login_1.default)(e.data.username, e.data.password); - break; - case "KEYS_LOGIN": - (0, keysLogin_1.default)(e.data.keys); - break; - case "SIGNUP": - (0, signup_1.default)(e.data.username, e.data.password); - break; - case "PUT_DATA": - self.toolDb.putData(e.data.key, e.data.data, e.data.userNamespaced); - break; - case "GET_DATA": - (0, getData_1.default)(e.data.id, e.data.key, e.data.userNamespaced, e.data.timeoutMs); - break; - case "GET_CRDT": - (0, getCrdt_1.default)(e.data.id, e.data.key, e.data.userNamespaced, e.data.timeoutMs); - break; - case "GET_LOCAL_DATA": - (0, getDataLocal_1.default)(e.data.id, e.data.key); - break; - case "QUERY_KEYS": - (0, queryKeys_1.default)(e.data.id, e.data.key, e.data.userNamespaced, e.data.timeoutMs); - break; - case "ADD_KEY_LISTENER": - (0, addKeyListener_1.default)(e.data.id, e.data.key); - break; - case "SUBSCRIBE": - self.toolDb.subscribeData(e.data.key, e.data.userNamespaced); - break; - case "REMOVE_KEY_LISTENER": - self.toolDb.removeKeyListener(e.data.id); - break; - case "DO_FUNCTION": - (0, doFunction_1.default)(e.data.id, e.data.fname, e.data.args, e.data.timeoutMs); - break; - case "GET_CONNECTION_DATA": - (0, getConnectionData_1.default)(); - break; - case "CONNECT": - (0, addHost_1.default)(e.data.peer.pubKey); - self.toolDb.network.connectTo(e.data.peer); - break; - case "DISCONNECT": - self.toolDb.network.disconnect(e.data.host); - break; - case "REMOVE_HOST": - (0, removeHost_1.default)(e.data.host); - break; - case "FIND_SERVER": - (0, addHost_1.default)(e.data.host); - self.toolDb.network.findServer(e.data.host); - break; - case "GET_SAVE_KEYS_JSON": - (0, getSaveKeysJson_1.default)(); - break; - // application specific handlers - case "PUSH_DB_MATCH": - (0, pushToExplore_1.default)(e.data.key, e.data.match); - (0, pushToLivefeed_1.default)(e.data.key, e.data.match); - break; - case "EXPLORE_DATA_QUERY": - (0, exploreAggregation_1.beginDataQuery)(e.data.days, e.data.event); - break; - case "GET_MATCHES_DATA": - (0, getMatchesData_1.getMatchesData)(e.data.id, e.data.matchesIndex, e.data.uuid); - break; - case "REFRESH_MATCHES": - if (self.toolDb.user) { - self.toolDb - .queryKeys(`:${self.toolDb.user.pubKey}.matches-`, false, 5000, true) - .then(handleMatchesIndex_1.default); - } - break; - default: - break; - } -}; +"use strict"; +/* eslint-disable no-restricted-globals */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const mtgatool_db_1 = require("mtgatool-db"); +const addHost_1 = __importDefault(require("./addHost")); +const addKeyListener_1 = __importDefault(require("./addKeyListener")); +const constants_1 = require("./constants"); +const doFunction_1 = __importDefault(require("./doFunction")); +const exploreAggregation_1 = require("./exploreAggregation"); +const getConnectionData_1 = __importDefault(require("./getConnectionData")); +const getCrdt_1 = __importDefault(require("./getCrdt")); +const getData_1 = __importDefault(require("./getData")); +const getDataLocal_1 = __importDefault(require("./getDataLocal")); +const getMatchesData_1 = require("./getMatchesData"); +const getSaveKeysJson_1 = __importDefault(require("./getSaveKeysJson")); +const handleMatchesIndex_1 = __importDefault(require("./handleMatchesIndex")); +const keysLogin_1 = __importDefault(require("./keysLogin")); +const login_1 = __importDefault(require("./login")); +const pushToExplore_1 = __importDefault(require("./pushToExplore")); +const pushToLivefeed_1 = __importDefault(require("./pushToLivefeed")); +const queryKeys_1 = __importDefault(require("./queryKeys")); +const reduxAction_1 = __importDefault(require("./reduxAction")); +const removeHost_1 = __importDefault(require("./removeHost")); +const signup_1 = __importDefault(require("./signup")); +const toolDb = new mtgatool_db_1.ToolDb({ + topic: "mtgatool-db-swarm-v4", + // debug: true, + server: false, + maxRetries: 999, +}); +toolDb.on("init", (key) => console.warn("ToolDb initialized!", key)); +// Try to conenct to servers from cache +toolDb.store.get(constants_1.SAVED_PEERS_KEY, (err, savedData) => { + let savedPeers = constants_1.DEFAULT_PEERS; + if (err) { + toolDb.store.put(constants_1.SAVED_PEERS_KEY, JSON.stringify(constants_1.DEFAULT_PEERS), () => { + console.log("Saved default peers to cache"); + }); + } + else if (savedData) { + try { + const newPeers = JSON.parse(savedData); + savedPeers = newPeers; + } + catch (_e) { + console.error("Error parsing saved peers from cache:", _e); + } + } + toolDb.store.get(constants_1.SERVERS_KEY, (serr, data) => { + let serversData = {}; + if (serr) { + console.error("Error getting servers from cache:", serr); + } + else if (data) { + try { + serversData = JSON.parse(data); + } + catch (_e) { + console.error("Error parsing servers from cache:", _e); + } + } + console.log("Got servers from cache:", serversData); + savedPeers.forEach((peer) => { + const networkModule = toolDb.network; + if (serversData[peer]) { + networkModule.connectTo(serversData[peer]); + } + else { + networkModule.findServer(peer); + } + }); + }); +}); +toolDb.onConnect = () => { + const networkModule = toolDb.network; + (0, reduxAction_1.default)("SET_OFFLINE", false); + self.postMessage({ type: "CONNECTED" }); + toolDb.store.put(constants_1.SERVERS_KEY, JSON.stringify(networkModule.serverPeerData), () => console.log("Saved servers to cache", networkModule.serverPeerData)); +}; +toolDb.onDisconnect = () => { + (0, reduxAction_1.default)("SET_OFFLINE", true); +}; +self.toolDb = toolDb; +self.globalData = { + hiddenDecks: [], + liveFeed: {}, + fetchedAvatars: [], + matchesIndex: [], + draftsIndex: [], + currentUUID: "", +}; +self.onmessage = (e) => { + const { type } = e.data; + // console.log("Worker onmessage:", e.type, e.data); + switch (type) { + case "LOGIN": + (0, login_1.default)(e.data.username, e.data.password); + break; + case "KEYS_LOGIN": + (0, keysLogin_1.default)(e.data.keys); + break; + case "SIGNUP": + (0, signup_1.default)(e.data.username, e.data.password); + break; + case "PUT_DATA": + self.toolDb.putData(e.data.key, e.data.data, e.data.userNamespaced); + break; + case "GET_DATA": + (0, getData_1.default)(e.data.id, e.data.key, e.data.userNamespaced, e.data.timeoutMs); + break; + case "GET_CRDT": + (0, getCrdt_1.default)(e.data.id, e.data.key, e.data.userNamespaced, e.data.timeoutMs); + break; + case "GET_LOCAL_DATA": + (0, getDataLocal_1.default)(e.data.id, e.data.key); + break; + case "QUERY_KEYS": + (0, queryKeys_1.default)(e.data.id, e.data.key, e.data.userNamespaced, e.data.timeoutMs); + break; + case "ADD_KEY_LISTENER": + (0, addKeyListener_1.default)(e.data.id, e.data.key); + break; + case "SUBSCRIBE": + self.toolDb.subscribeData(e.data.key, e.data.userNamespaced); + break; + case "REMOVE_KEY_LISTENER": + self.toolDb.removeKeyListener(e.data.id); + break; + case "DO_FUNCTION": + (0, doFunction_1.default)(e.data.id, e.data.fname, e.data.args, e.data.timeoutMs); + break; + case "GET_CONNECTION_DATA": + (0, getConnectionData_1.default)(); + break; + case "CONNECT": + (0, addHost_1.default)(e.data.peer.pubKey); + self.toolDb.network.connectTo(e.data.peer); + break; + case "DISCONNECT": + self.toolDb.network.disconnect(e.data.host); + break; + case "REMOVE_HOST": + (0, removeHost_1.default)(e.data.host); + break; + case "FIND_SERVER": + (0, addHost_1.default)(e.data.host); + self.toolDb.network.findServer(e.data.host); + break; + case "GET_SAVE_KEYS_JSON": + (0, getSaveKeysJson_1.default)(); + break; + // application specific handlers + case "PUSH_DB_MATCH": + (0, pushToExplore_1.default)(e.data.key, e.data.match); + (0, pushToLivefeed_1.default)(e.data.key, e.data.match); + break; + case "EXPLORE_DATA_QUERY": + (0, exploreAggregation_1.beginDataQuery)(e.data.days, e.data.event); + break; + case "GET_MATCHES_DATA": + (0, getMatchesData_1.getMatchesData)(e.data.id, e.data.matchesIndex, e.data.uuid); + break; + case "REFRESH_MATCHES": + if (self.toolDb.user) { + self.toolDb + .queryKeys(`:${self.toolDb.user.pubKey}.matches-`, false, 5000, true) + .then(handleMatchesIndex_1.default); + } + break; + default: + break; + } +}; },{"./addHost":1,"./addKeyListener":2,"./constants":4,"./doFunction":5,"./exploreAggregation":6,"./getConnectionData":7,"./getCrdt":8,"./getData":9,"./getDataLocal":10,"./getMatchesData":11,"./getSaveKeysJson":13,"./handleMatchesIndex":16,"./keysLogin":17,"./login":18,"./pushToExplore":19,"./pushToLivefeed":20,"./queryKeys":21,"./reduxAction":22,"./removeHost":23,"./signup":24,"mtgatool-db":292}],26:[function(require,module,exports){ 'use strict' diff --git a/src/background/greToClientInterpreter.ts b/src/background/greToClientInterpreter.ts index d215df84..d4bd0a49 100644 --- a/src/background/greToClientInterpreter.ts +++ b/src/background/greToClientInterpreter.ts @@ -22,7 +22,6 @@ import { Annotations, DetailsKeyType, DetailsSrcDestCategoryType, - GameObject, } from "../types/greInterpreter"; import db from "../utils/database-wrapper"; import actionLog from "./actionLog"; @@ -90,7 +89,7 @@ function _setHeat(seat: number, value: number): void { } } -function getGameObject(id: number): GameObject { +function getGameObject(id: number): GameObjectInfo { return globalStore.currentMatch.gameObjects[id]; } @@ -134,7 +133,7 @@ function isAnnotationProcessed(id: number): boolean { const FACE_DOWN_CARD = 3; -function isObjectACard(card: GameObject): boolean { +function isObjectACard(card: GameObjectInfo): boolean { return ( card.type == "GameObjectType_Card" || card.type == "GameObjectType_SplitCard" @@ -156,7 +155,7 @@ class NoInstanceException { } } -function instanceIdToObject(iid: number): GameObject { +function instanceIdToObject(iid: number): GameObjectInfo { let instanceID = iid; const orig = instanceID; const { idChanges } = globalStore.currentMatch; @@ -185,7 +184,7 @@ const AnnotationType_ZoneTransfer = (ann: Annotations): void => { const fromZone = getZone(ann.details.zone_src); if (fromZone.type == "ZoneType_Sideboard") { const obj = instanceIdToObject(ann.affectedIds[0]); - if (obj.ownerSeatId == globalStore.currentMatch.playerSeat) { + if (obj.ownerSeatId == globalStore.currentMatch.playerSeat && obj.grpId) { addCardFromSideboard([obj.grpId]); } } @@ -196,7 +195,7 @@ const AnnotationType_ZoneTransfer = (ann: Annotations): void => { const grpId = affected.grpId || 0; actionLog({ - seat: affected.controllerSeatId, + seat: affected.controllerSeatId || 0, timestamp: globalStore.currentMatch.logTime.getTime(), type: "PLAY", grpId, @@ -269,18 +268,18 @@ const AnnotationType_ZoneTransfer = (ann: Annotations): void => { const affector = instanceIdToObject(ann.affectorId); const seat = obj.ownerSeatId || 0; - if (affector.type == "GameObjectType_Ability") { + if (affector.type == "GameObjectType_Ability" && grpId) { actionLog({ seat: seat, timestamp: globalStore.currentMatch.logTime.getTime(), type: "ZONE_PUT", - sourceGrpId: affector.objectSourceGrpId, + sourceGrpId: affector.objectSourceGrpId || 0, abilityId: affector.grpId, grpId, zone: getZoneName(zone || "ZoneType_None"), }); } - if (isObjectACard(affector)) { + if (isObjectACard(affector) && grpId && affector.grpId) { actionLog({ seat: seat, timestamp: globalStore.currentMatch.logTime.getTime(), @@ -298,9 +297,13 @@ const AnnotationType_ZoneTransfer = (ann: Annotations): void => { const zone = getZone(ann.details.zone_dest).type; const affected = instanceIdToObject(ann.affectedIds[0]); const affector = instanceIdToObject(ann.affectorId); - const seat = affected.ownerSeatId; + const seat = affected.ownerSeatId || 0; - if (affector.type == "GameObjectType_Ability") { + if ( + affector.type == "GameObjectType_Ability" && + affected.grpId && + affector.objectSourceGrpId + ) { actionLog({ seat: seat, timestamp: globalStore.currentMatch.logTime.getTime(), @@ -311,7 +314,7 @@ const AnnotationType_ZoneTransfer = (ann: Annotations): void => { zone: getZoneName(zone || "ZoneType_None"), }); } - if (isObjectACard(affector)) { + if (isObjectACard(affector) && affected.grpId && affector.grpId) { actionLog({ seat: seat, timestamp: globalStore.currentMatch.logTime.getTime(), @@ -329,8 +332,13 @@ const AnnotationType_ZoneTransfer = (ann: Annotations): void => { const affected = instanceIdToObject(ann.affectedIds[0]); const affector = instanceIdToObject(ann.affectorId); - const seat = affector.ownerSeatId; - if (affector.type == "GameObjectType_Ability") { + const seat = affector.ownerSeatId || 0; + + if ( + affector.type == "GameObjectType_Ability" && + affector.objectSourceGrpId && + affected.grpId + ) { actionLog({ seat: seat, timestamp: globalStore.currentMatch.logTime.getTime(), @@ -340,7 +348,7 @@ const AnnotationType_ZoneTransfer = (ann: Annotations): void => { grpId: affected.grpId, }); } - if (isObjectACard(affector)) { + if (isObjectACard(affector) && affected.grpId && affector.grpId) { actionLog({ seat: seat, timestamp: globalStore.currentMatch.logTime.getTime(), @@ -362,8 +370,12 @@ const AnnotationType_ZoneTransfer = (ann: Annotations): void => { const affector = instanceIdToObject(ann.affectorId); const affected = instanceIdToObject(ann.affectedIds[0]); - const seat = affector.ownerSeatId; - if (affector.type == "GameObjectType_Ability") { + const seat = affector.ownerSeatId || 0; + if ( + affector.type == "GameObjectType_Ability" && + affector.objectSourceGrpId && + affected.grpId + ) { actionLog({ seat: seat, timestamp: globalStore.currentMatch.logTime.getTime(), @@ -373,7 +385,7 @@ const AnnotationType_ZoneTransfer = (ann: Annotations): void => { grpId: affected.grpId, }); } - if (isObjectACard(affector)) { + if (isObjectACard(affector) && affected.grpId && affector.grpId) { actionLog({ seat: seat, timestamp: globalStore.currentMatch.logTime.getTime(), @@ -421,7 +433,11 @@ const AnnotationType_ResolutionStart = (ann: Annotations): void => { const affected = instanceIdToObject(ann.affectedIds[0]); const grpId = ann.details.grpid; - if (affected.type == "GameObjectType_Ability") { + if ( + affected.type == "GameObjectType_Ability" && + affected.controllerSeatId && + affected.objectSourceGrpId + ) { // affected.grpId = grpId; actionLog({ seat: affected.controllerSeatId, @@ -444,27 +460,31 @@ const AnnotationType_DamageDealt = (ann: Annotations): void => { targetType = "PLAYER"; } else { const affected = instanceIdToObject(ann.affectedIds[0]); - targetId = affected.grpId; + targetId = affected.grpId || 0; targetType = "PERMANENT"; } const affector = instanceIdToObject(ann.affectorId); const dmg = ann.details.damage; + const affectorGrpId = affector.grpId || 0; + if (affector.controllerSeatId == globalStore.currentMatch.playerSeat) { const pstats = globalStore.currentMatch.playerStats; - const prev = pstats.damage[affector.grpId]; - pstats.damage[affector.grpId] = (prev || 0) + dmg; + + const prev = pstats.damage[affectorGrpId]; + pstats.damage[affectorGrpId] = (prev || 0) + dmg; } else { const pstats = globalStore.currentMatch.oppStats; - const prev = pstats.damage[affector.grpId]; - pstats.damage[affector.grpId] = (prev || 0) + dmg; + + const prev = pstats.damage[affectorGrpId]; + pstats.damage[affectorGrpId] = (prev || 0) + dmg; } actionLog({ - seat: affector.controllerSeatId, + seat: affector.controllerSeatId || 0, timestamp: globalStore.currentMatch.logTime.getTime(), type: "DAMAGE_DEALT", - sourceGrpId: affector.grpId, + sourceGrpId: affectorGrpId, targetId, targetType, amount: dmg, @@ -510,14 +530,14 @@ const AnnotationType_TargetSpec = (ann: Annotations): void => { targetType = "PLAYER"; } else { const affected = instanceIdToObject(ann.affectedIds[0]); - targetId = affected.grpId; + targetId = affected.grpId || 0; targetType = "PERMANENT"; } const affector = instanceIdToObject(ann.affectorId); - const seat = affector.ownerSeatId; + const seat = affector.ownerSeatId || 0; - if (affector.type == "GameObjectType_Ability") { + if (affector.type == "GameObjectType_Ability" && affector.objectSourceGrpId) { actionLog({ seat, timestamp: globalStore.currentMatch.logTime.getTime(), @@ -528,7 +548,7 @@ const AnnotationType_TargetSpec = (ann: Annotations): void => { targetId, }); } - if (isObjectACard(affector)) { + if (isObjectACard(affector) && affector.grpId) { actionLog({ seat, timestamp: globalStore.currentMatch.logTime.getTime(), @@ -546,7 +566,7 @@ const AnnotationType_Scry = (ann: Annotations): void => { // REVIEW SCRY ANNOTATION let affector = ann.affectorId; if (affector > 3) { - affector = instanceIdToObject(affector).ownerSeatId; + affector = instanceIdToObject(affector).ownerSeatId || 0; } // const { playerSeat } = globalStore.currentMatch; @@ -625,7 +645,7 @@ const AnnotationType_ManaPaid = (ann: Annotations): void => { let affector = ann.affectorId; if (affector > 3) { - affector = instanceIdToObject(affector).ownerSeatId; + affector = instanceIdToObject(affector).ownerSeatId || 0; } if (affector == playerSeat) { @@ -827,7 +847,7 @@ function getOppUsedCards(): number[] { if (obj.ownerSeatId == oppSeat && isObjectACard(obj)) { grpId = obj.grpId; // debugLog(zone.type, db.card(grpId).name, obj); - if (grpId !== FACE_DOWN_CARD) cardsUsed.push(grpId); + if (grpId && grpId !== FACE_DOWN_CARD) cardsUsed.push(grpId); } } catch (e) { // @@ -1001,8 +1021,8 @@ function checkForStartingLibrary(gameState?: GameStateMessage): boolean { const mull = player.mulliganCount || 0; // If this is the first hand drawn or we made a mulligan if (mull > 0 || currentMatch.handsDrawn.length == 0) { - const drawn = hand.map((n) => getGameObject(n).grpId); - setHandDrawn(mull, drawn); + const drawn = hand.map((n) => getGameObject(n).grpId).filter((n) => n); + setHandDrawn(mull, drawn as number[]); console.log(`Mulligan: ${mull}, ${drawn}`); } } @@ -1027,6 +1047,7 @@ function checkForStartingLibrary(gameState?: GameStateMessage): boolean { } function checkTurnDiff(turnInfo: TurnInfo): void { + console.log("checkTurnDiff", turnInfo); const { currentMatch } = globalStore; const currentTurnInfo = currentMatch.turnInfo; const { currentPriority } = currentMatch; @@ -1037,7 +1058,59 @@ function checkTurnDiff(turnInfo: TurnInfo): void { ) { setOnThePlay(turnInfo.activePlayer); } - // console.log("checkTurnDiff", currentMatch.logTime); + + if ( + turnInfo.step === "Step_DeclareBlock" && + currentTurnInfo.step !== turnInfo.step + ) { + // Find all attacking creatures and add it to the action log + const attackersByTarget: Record = {}; + if (turnInfo.phase && turnInfo.step === "Step_DeclareBlock") { + Object.values(globalStore.currentMatch.zones) + .filter((z) => z.type === "ZoneType_Battlefield") + .forEach((zone) => { + if (zone.objectInstanceIds) { + zone.objectInstanceIds.forEach((id: number) => { + try { + const obj = getGameObject(id); + if ( + obj.attackState === "AttackState_Attacking" && + obj.grpId && + obj.grpId !== FACE_DOWN_CARD && + obj.attackInfo && + obj.attackInfo.targetId + ) { + const { targetId } = obj.attackInfo; + + if (attackersByTarget[targetId]) { + attackersByTarget[targetId].push(obj.grpId); + } else { + attackersByTarget[targetId] = [obj.grpId]; + } + } + } catch (e) { + // + } + }); + } + }); + } + + console.log("attackersByTarget", attackersByTarget); + Object.entries(attackersByTarget).forEach(([id, attackers]) => { + const targetId = parseInt(id); + const targetType = targetId < 5 ? "PLAYER" : "PERMANENT"; + actionLog({ + type: "ATTACK", + seat: turnInfo.activePlayer || -1, + timestamp: globalStore.currentMatch.logTime.getTime(), + grpIds: attackers, + targetType, + targetId, + }); + }); + } + if (turnInfo.priorityPlayer !== currentPriority) { changePriority( currentPriority, @@ -1055,21 +1128,21 @@ function checkTurnDiff(turnInfo: TurnInfo): void { ...turnInfo, }); } - if (currentTurnInfo.step !== turnInfo.step) { + if (currentTurnInfo.phase !== turnInfo.phase) { actionLog({ type: "TURN_INFO", seat: -1, timestamp: globalStore.currentMatch.logTime.getTime(), - subType: "STEP", + subType: "PHASE", ...turnInfo, }); } - if (currentTurnInfo.phase !== turnInfo.phase) { + if (currentTurnInfo.step !== turnInfo.step) { actionLog({ type: "TURN_INFO", seat: -1, timestamp: globalStore.currentMatch.logTime.getTime(), - subType: "PHASE", + subType: "STEP", ...turnInfo, }); } diff --git a/src/background/saveMatch.ts b/src/background/saveMatch.ts index a011506e..fe59b460 100644 --- a/src/background/saveMatch.ts +++ b/src/background/saveMatch.ts @@ -85,7 +85,7 @@ function generateInternalMatch(): InternalMatch { toolRunFromSource: !remote?.app.isPackaged, arenaId: currentMatch.player.name, playerDeckHash: globalStore.currentMatch.originalDeck.getHash(), - actionLog: globalStore.currentActionLog, + actionLog: globalStore.currentActionLog as any, type: "match", }; diff --git a/src/background/store/types.ts b/src/background/store/types.ts index 692684f9..df537dfd 100644 --- a/src/background/store/types.ts +++ b/src/background/store/types.ts @@ -2,7 +2,6 @@ import { CardCast, Chances, Deck, - GameObject, Heat, InternalDeck, InternalPlayer, @@ -12,6 +11,7 @@ import { import { AnnotationInfo, GameInfo, + GameObjectInfo, GREToClientMessage, PlayerInfo, TurnInfo, @@ -61,7 +61,7 @@ export interface MatchState { zones: Record; annotations: Record; processedAnnotations: number[]; - gameObjects: Record; + gameObjects: Record; initialLibraryInstanceIds: number[]; instanceToCardIdMap: Record; idChanges: Record; diff --git a/src/components/action-log-v2/LineAbility.tsx b/src/components/action-log-v2/LineAbility.tsx new file mode 100644 index 00000000..81151850 --- /dev/null +++ b/src/components/action-log-v2/LineAbility.tsx @@ -0,0 +1,19 @@ +import LogAbility from "./LogAbility"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LineAbility(props: ActionLogLineProps) { + const { line } = props; + + if (line.type !== "ZONE_PUT") return <>; + + return ( + <> +
+ + 's  + {line.abilityId ? : "ability"} +
+ + ); +} diff --git a/src/components/action-log-v2/LineAttack.tsx b/src/components/action-log-v2/LineAttack.tsx new file mode 100644 index 00000000..a9bf7cbd --- /dev/null +++ b/src/components/action-log-v2/LineAttack.tsx @@ -0,0 +1,32 @@ +import getPlayerBySeat from "./getPlayerBySeat"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LineAttack(props: ActionLogLineProps) { + const { line, players } = props; + + if (line.type !== "ATTACK") return <>; + + return ( +
+ {getPlayerBySeat(line.seat, players)} +  attacked with   + {line.grpIds.map((grpId, index) => { + const len = line.grpIds.length; + return ( + <> + + {index < len - 2 && len > 2 && <>, } + {index === len - 2 && <> and } + + ); + })} +  to  + {line.targetType === "PLAYER" ? ( + getPlayerBySeat(line.targetId, players) + ) : ( + + )} +
+ ); +} diff --git a/src/components/action-log-v2/LineCast.tsx b/src/components/action-log-v2/LineCast.tsx new file mode 100644 index 00000000..d045ac5e --- /dev/null +++ b/src/components/action-log-v2/LineCast.tsx @@ -0,0 +1,20 @@ +import getPlayerBySeat from "./getPlayerBySeat"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LineCast(props: ActionLogLineProps) { + const { line, players } = props; + + if (line.type !== "CAST") return <>; + + const playerName = getPlayerBySeat(line.seat || 0, players); + + return ( + <> +
+ {playerName} cast  + {line.grpId ? : "a spell"} +
+ + ); +} diff --git a/src/components/action-log-v2/LineConceded.tsx b/src/components/action-log-v2/LineConceded.tsx new file mode 100644 index 00000000..9e79905a --- /dev/null +++ b/src/components/action-log-v2/LineConceded.tsx @@ -0,0 +1,16 @@ +import getPlayerBySeat from "./getPlayerBySeat"; +import { ActionLogLineProps } from "./types"; + +export default function LineConceded(props: ActionLogLineProps) { + const { line, players } = props; + + if (line.type !== "CONCEDED") return <>; + + const playerName = getPlayerBySeat(line.seat || 0, players); + + return ( + <> +
{playerName} conceded.
+ + ); +} diff --git a/src/components/action-log-v2/LineCountered.tsx b/src/components/action-log-v2/LineCountered.tsx new file mode 100644 index 00000000..623e12d5 --- /dev/null +++ b/src/components/action-log-v2/LineCountered.tsx @@ -0,0 +1,27 @@ +import LogAbility from "./LogAbility"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LineCountered(props: ActionLogLineProps) { + const { line } = props; + + if (line.type !== "COUNTERED") return <>; + + return ( + <> +
+ {line.abilityId ? ( + <> + + 's  + + + ) : ( + + )} +  countered  + +
+ + ); +} diff --git a/src/components/action-log-v2/LineDamageDealt.tsx b/src/components/action-log-v2/LineDamageDealt.tsx new file mode 100644 index 00000000..86146b9a --- /dev/null +++ b/src/components/action-log-v2/LineDamageDealt.tsx @@ -0,0 +1,23 @@ +import getPlayerBySeat from "./getPlayerBySeat"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LineDamageDealt(props: ActionLogLineProps) { + const { line, players } = props; + + if (line.type !== "DAMAGE_DEALT") return <>; + + return ( + <> +
+ +  dealt {line.amount} damage to  + {line.targetType === "PLAYER" ? ( + getPlayerBySeat(line.targetId, players) + ) : ( + + )} +
+ + ); +} diff --git a/src/components/action-log-v2/LineDestroyed.tsx b/src/components/action-log-v2/LineDestroyed.tsx new file mode 100644 index 00000000..2f86d520 --- /dev/null +++ b/src/components/action-log-v2/LineDestroyed.tsx @@ -0,0 +1,27 @@ +import LogAbility from "./LogAbility"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LineDestroyed(props: ActionLogLineProps) { + const { line } = props; + + if (line.type !== "DESTROYED") return <>; + + return ( + <> +
+ {line.abilityId ? ( + <> + + 's  + + + ) : ( + + )} +  destroyed  + +
+ + ); +} diff --git a/src/components/action-log-v2/LineDiscard.tsx b/src/components/action-log-v2/LineDiscard.tsx new file mode 100644 index 00000000..3f538b2c --- /dev/null +++ b/src/components/action-log-v2/LineDiscard.tsx @@ -0,0 +1,20 @@ +import getPlayerBySeat from "./getPlayerBySeat"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LineDiscard(props: ActionLogLineProps) { + const { line, players } = props; + + if (line.type !== "DISCARD") return <>; + + const playerName = getPlayerBySeat(line.seat || 0, players); + + return ( + <> +
+ {playerName} discarded  + {line.grpId ? : "a card"} +
+ + ); +} diff --git a/src/components/action-log-v2/LineDraw.tsx b/src/components/action-log-v2/LineDraw.tsx new file mode 100644 index 00000000..93100760 --- /dev/null +++ b/src/components/action-log-v2/LineDraw.tsx @@ -0,0 +1,20 @@ +import getPlayerBySeat from "./getPlayerBySeat"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LineDraw(props: ActionLogLineProps) { + const { line, players } = props; + + if (line.type !== "DRAW") return <>; + + const playerName = getPlayerBySeat(line.seat || 0, players); + + return ( + <> +
+ {playerName} drew  + {line.grpId ? : "a card"} +
+ + ); +} diff --git a/src/components/action-log-v2/LineExile.tsx b/src/components/action-log-v2/LineExile.tsx new file mode 100644 index 00000000..cc6eaea1 --- /dev/null +++ b/src/components/action-log-v2/LineExile.tsx @@ -0,0 +1,27 @@ +import LogAbility from "./LogAbility"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LineExile(props: ActionLogLineProps) { + const { line } = props; + + if (line.type !== "EXILE") return <>; + + return ( + <> +
+ {line.abilityId ? ( + <> + + 's  + + + ) : ( + + )} +  exiled  + +
+ + ); +} diff --git a/src/components/action-log-v2/LinePlay.tsx b/src/components/action-log-v2/LinePlay.tsx new file mode 100644 index 00000000..e8ca4b31 --- /dev/null +++ b/src/components/action-log-v2/LinePlay.tsx @@ -0,0 +1,20 @@ +import getPlayerBySeat from "./getPlayerBySeat"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LinePlay(props: ActionLogLineProps) { + const { line, players } = props; + + if (line.type !== "PLAY") return <>; + + const playerName = getPlayerBySeat(line.seat || 0, players); + + return ( + <> +
+ {playerName} played  + {line.grpId ? : "a land"} +
+ + ); +} diff --git a/src/components/action-log-v2/LineTimedOut.tsx b/src/components/action-log-v2/LineTimedOut.tsx new file mode 100644 index 00000000..7d91f525 --- /dev/null +++ b/src/components/action-log-v2/LineTimedOut.tsx @@ -0,0 +1,16 @@ +import getPlayerBySeat from "./getPlayerBySeat"; +import { ActionLogLineProps } from "./types"; + +export default function LineTimedOut(props: ActionLogLineProps) { + const { line, players } = props; + + if (line.type !== "TIMED_OUT") return <>; + + const playerName = getPlayerBySeat(line.seat || 0, players); + + return ( + <> +
{playerName} timed out.
+ + ); +} diff --git a/src/components/action-log-v2/LineTurnInfo.tsx b/src/components/action-log-v2/LineTurnInfo.tsx new file mode 100644 index 00000000..69d52912 --- /dev/null +++ b/src/components/action-log-v2/LineTurnInfo.tsx @@ -0,0 +1,34 @@ +import getPlayerBySeat from "./getPlayerBySeat"; +import { ActionLogLineProps } from "./types"; + +const phasesMap: Record = { + Phase_None: "None", + Phase_Beginning: "Beginning Phase", + Phase_Main1: "First Main Phase", + Phase_Combat: "Combat", + Phase_Main2: "Second Main Phase", + Phase_Ending: "End Phase", +}; + +export default function LineTurnInfo(props: ActionLogLineProps) { + const { line, players } = props; + + if (line.type !== "TURN_INFO") return <>; + + return ( + <> + {line.subType === "BEGIN" && ( +
+
Turn {line.turnNumber}
+
+ {getPlayerBySeat(line.activePlayer || 0, players)} +
+
+ )} + + {line.subType === "PHASE" && line.phase && ( +
{phasesMap[line.phase]}
+ )} + + ); +} diff --git a/src/components/action-log-v2/LineWon.tsx b/src/components/action-log-v2/LineWon.tsx new file mode 100644 index 00000000..9503d34e --- /dev/null +++ b/src/components/action-log-v2/LineWon.tsx @@ -0,0 +1,16 @@ +import getPlayerBySeat from "./getPlayerBySeat"; +import { ActionLogLineProps } from "./types"; + +export default function LineWin(props: ActionLogLineProps) { + const { line, players } = props; + + if (line.type !== "WIN") return <>; + + const playerName = getPlayerBySeat(line.seat || 0, players); + + return ( + <> +
{playerName} won!
+ + ); +} diff --git a/src/components/action-log-v2/LineZonePut.tsx b/src/components/action-log-v2/LineZonePut.tsx new file mode 100644 index 00000000..f30976f3 --- /dev/null +++ b/src/components/action-log-v2/LineZonePut.tsx @@ -0,0 +1,28 @@ +import LogAbility from "./LogAbility"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LineZonePut(props: ActionLogLineProps) { + const { line } = props; + + if (line.type !== "ZONE_PUT") return <>; + + return ( + <> +
+ {line.abilityId ? ( + <> + + 's  + + + ) : ( + + )} +  put  + +  in {line.zone} +
+ + ); +} diff --git a/src/components/action-log-v2/LineZoneReturn.tsx b/src/components/action-log-v2/LineZoneReturn.tsx new file mode 100644 index 00000000..28ceee71 --- /dev/null +++ b/src/components/action-log-v2/LineZoneReturn.tsx @@ -0,0 +1,28 @@ +import LogAbility from "./LogAbility"; +import LogCard from "./LogCard"; +import { ActionLogLineProps } from "./types"; + +export default function LineZoneReturn(props: ActionLogLineProps) { + const { line } = props; + + if (line.type !== "ZONE_RETURN") return <>; + + return ( + <> +
+ {line.abilityId ? ( + <> + + 's  + + + ) : ( + + )} +  returned  + +  to {line.zone} +
+ + ); +} diff --git a/src/components/action-log-v2/LogAbility.tsx b/src/components/action-log-v2/LogAbility.tsx new file mode 100644 index 00000000..fda21f90 --- /dev/null +++ b/src/components/action-log-v2/LogAbility.tsx @@ -0,0 +1,16 @@ +import { database } from "mtgatool-shared"; + +interface LogAbilityProps { + abId: number; +} + +export default function LogAbility(props: LogAbilityProps): JSX.Element { + const { abId } = props; + const desc = database.ability(abId); + + return ( + + ability + + ); +} diff --git a/src/components/action-log-v2/LogCard.tsx b/src/components/action-log-v2/LogCard.tsx new file mode 100644 index 00000000..ad11a261 --- /dev/null +++ b/src/components/action-log-v2/LogCard.tsx @@ -0,0 +1,21 @@ +import { database } from "mtgatool-shared"; + +import useHoverCard from "../../hooks/useHoverCard"; + +interface LogCardProps { + grpId: number; +} + +export default function LogCard(props: LogCardProps): JSX.Element { + const { grpId } = props; + const cardObj = database.card(grpId); + const cardName = cardObj?.Name; + + const [hoverIn, hoverOut] = useHoverCard(grpId); + + return ( + + {cardName} + + ); +} diff --git a/src/components/action-log-v2/getPlayerBySeat.ts b/src/components/action-log-v2/getPlayerBySeat.ts new file mode 100644 index 00000000..1cfc7e32 --- /dev/null +++ b/src/components/action-log-v2/getPlayerBySeat.ts @@ -0,0 +1,11 @@ +import getPlayerNameWithoutSuffix from "../../utils/getPlayerNameWithoutSuffix"; +import { ActionLogPlayer } from "./types"; + +export default function getPlayerBySeat( + seat: number, + players: ActionLogPlayer[] +): string { + const playerName = + players.filter((player) => player.seat === seat)[0]?.name || ""; + return getPlayerNameWithoutSuffix(playerName); +} diff --git a/src/components/action-log-v2/index.tsx b/src/components/action-log-v2/index.tsx index 3b8c3c77..e0de8456 100644 --- a/src/components/action-log-v2/index.tsx +++ b/src/components/action-log-v2/index.tsx @@ -1,60 +1,82 @@ -/* eslint-disable react/no-array-index-key */ -/* eslint-disable radix */ +import LineAbility from "./LineAbility"; +import LineAttack from "./LineAttack"; +import LineCast from "./LineCast"; +import LineConceded from "./LineConceded"; +import LineCountered from "./LineCountered"; +import LineDamageDealt from "./LineDamageDealt"; +import LineDestroyed from "./LineDestroyed"; +import LineDiscard from "./LineDiscard"; +import LineDraw from "./LineDraw"; +import LineExile from "./LineExile"; +import LinePlay from "./LinePlay"; +import LineTimedOut from "./LineTimedOut"; +import LineTurnInfo from "./LineTurnInfo"; +import LineWin from "./LineWon"; +import LineZonePut from "./LineZonePut"; +import LineZoneReturn from "./LineZoneReturn"; +import { ActionLogLineProps, ActionLogLineType, ActionLogV2 } from "./types"; -import { database } from "mtgatool-shared"; -import { Fragment } from "react"; +const DefaultLineComponent = (_props: ActionLogLineProps): JSX.Element => { + return <>; +}; -import useHoverCard from "../../hooks/useHoverCard"; -import { ActionLogV2 } from "./types"; +function getLineComponent(type: ActionLogLineType) { + let lineComponent = DefaultLineComponent; -interface LogTextProps { - children: string; -} - -function LogText(props: LogTextProps): JSX.Element { - const { children } = props; - return
{children}
; -} - -interface LogCardProps { - children: string; - grpId: number; -} - -function _LogCard(props: LogCardProps): JSX.Element { - const { children, grpId } = props; - const cardObj = database.card(grpId); - const cardName = cardObj?.Name; - - const [hoverIn, hoverOut] = useHoverCard(grpId); - - return ( - <> - {children !== "" ? {children} : <>} -
- {cardName} -
- - ); -} - -interface LogAbilityProps { - children: string; - abId: number; -} + switch (type) { + case "WIN": + lineComponent = LineWin; + break; + case "CONCEDED": + lineComponent = LineConceded; + break; + case "TIMED_OUT": + lineComponent = LineTimedOut; + break; + case "DRAW": + lineComponent = LineDraw; + break; + case "CAST": + lineComponent = LineCast; + break; + case "PLAY": + lineComponent = LinePlay; + break; + case "DISCARD": + lineComponent = LineDiscard; + break; + case "ZONE_PUT": + lineComponent = LineZonePut; + break; + case "ZONE_RETURN": + lineComponent = LineZoneReturn; + break; + case "EXILE": + lineComponent = LineExile; + break; + case "COUNTERED": + lineComponent = LineCountered; + break; + case "DESTROYED": + lineComponent = LineDestroyed; + break; + case "TURN_INFO": + lineComponent = LineTurnInfo; + break; + case "ABILITY": + lineComponent = LineAbility; + break; + case "DAMAGE_DEALT": + lineComponent = LineDamageDealt; + break; + case "ATTACK": + lineComponent = LineAttack; + break; + default: + break; + } -function _LogAbility(props: LogAbilityProps): JSX.Element { - const { children, abId } = props; - const desc = database.ability(abId); - - return ( - <> - {children !== "" ? {children} : <>} -
- ability -
- - ); + return lineComponent; } interface ActionLogProps { @@ -64,15 +86,33 @@ interface ActionLogProps { export default function ActionLog(props: ActionLogProps): JSX.Element { const { actionLog } = props; + // const logLength = actionLog.lines.length; + return ( - <> - {actionLog.lines.map((line, i) => { +
+ {actionLog.lines.map((line) => { + const LineComponent = getLineComponent(line.type); + + // const nextLine = actionLog.lines[i + 1]; + + // if ( + // line.type === "TURN_INFO" && + // line.subType !== "BEGIN" && + // logLength - 1 !== i && + // nextLine.type === "TURN_INFO" && + // nextLine.subType === line.subType + // ) { + // return <>; + // } + return ( -
- {JSON.stringify(line)} -
+ ); })} - +
); } diff --git a/src/components/action-log-v2/types.ts b/src/components/action-log-v2/types.ts index 16879b21..56d286f2 100644 --- a/src/components/action-log-v2/types.ts +++ b/src/components/action-log-v2/types.ts @@ -17,6 +17,7 @@ export type ActionLogLineType = | "COUNTERED" | "DESTROYED" | "ABILITY" + | "ATTACK" | "DAMAGE_DEALT" | "MODIFIED_LIFE" | "TARGET" @@ -117,6 +118,13 @@ export interface ActionLogLineAbility extends ActionLogLineBase { abilityId: number; } +export interface ActionLogLineAttack extends ActionLogLineBase { + type: "ATTACK"; + grpIds: number[]; + targetType: string; + targetId: number; +} + export interface ActionLogLineDamageDealt extends ActionLogLineBase { type: "DAMAGE_DEALT"; sourceGrpId: number; @@ -169,13 +177,14 @@ export type ActionLogLine = | ActionLogLineCountered | ActionLogLineDestroyed | ActionLogLineAbility + | ActionLogLineAttack | ActionLogLineDamageDealt | ActionLogLineModifiedLife | ActionLogLineTarget | ActionLogLineScry | ActionLogLineReveal; -interface ActionLogPlayer { +export interface ActionLogPlayer { name: string; seat: number; userId: string; @@ -186,3 +195,8 @@ export type ActionLogV2 = { players: ActionLogPlayer[]; lines: ActionLogLine[]; }; + +export interface ActionLogLineProps { + line: ActionLogLine; + players: ActionLogPlayer[]; +} diff --git a/src/info.json b/src/info.json index 7a81747a..63edcd6f 100644 --- a/src/info.json +++ b/src/info.json @@ -1 +1 @@ -{"version":"6.5.3","branch":"dev","timestamp":1704463740093} \ No newline at end of file +{"version":"6.5.3","branch":"action-logs-v2","timestamp":1704517285209} \ No newline at end of file diff --git a/src/scss/actionLog.scss b/src/scss/actionLog.scss index b943554d..db4030fc 100644 --- a/src/scss/actionLog.scss +++ b/src/scss/actionLog.scss @@ -73,3 +73,54 @@ cursor: pointer; margin-right: 3px; } + +.action-log-v2 { + font-size: 14px; + color: var(--color-text); + font-style: italic; + + .log-line { + margin-top: 8px; + margin-left: 16px; + display: flex; + } + + .result { + font-weight: 600; + margin-left: 0px; + color: var(--color-text-dark); + } + + .winner { + font-weight: 600; + margin-left: 0px; + margin-top: 16px; + color: var(--color-text-dark); + } + + .card, .ability { + color: var(--color-link); + text-decoration: underline; + } + + .turn-info { + margin-top: 12px; + display: flex; + justify-content: space-between; + + .name { + color: var(--color-text-dark); + } + + &.begin { + margin-top: 16px; + padding-bottom: 4px; + border-bottom: var(--color-link) 1px solid; + } + + &.phase { + font-weight: 600; + color: var(--color-text-dark); + } + } +}