From 870df1f83f0b63e77c1f663b073714b115d8a375 Mon Sep 17 00:00:00 2001 From: Razviar Date: Sat, 2 Sep 2023 09:37:05 +0300 Subject: [PATCH] 1.2.17 --- package-lock.json | 4 +- package.json | 8 +- src/api/cards.ts | 10 + src/app/game_state.ts | 4 + src/lib/messages.ts | 4 +- src/models/cards.ts | 188 +++++++----------- src/models/match.ts | 8 +- src/models/overlay.ts | 4 +- src/windows/overlay/functions/drawdeck.ts | 2 + src/windows/overlay/functions/makecard.ts | 15 +- .../overlay/functions/messages_ipcmain.ts | 9 +- src/windows/overlay/functions/sortdeck.ts | 18 ++ src/windows/overlay/functions/updatedeck.ts | 23 ++- .../overlay/functions/updateoppdeck.ts | 28 +-- 14 files changed, 164 insertions(+), 161 deletions(-) create mode 100644 src/api/cards.ts create mode 100644 src/windows/overlay/functions/sortdeck.ts diff --git a/package-lock.json b/package-lock.json index 0b4ec69..8dcc4fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "marvelsnaptracker", - "version": "1.2.11", + "version": "1.2.17", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "marvelsnaptracker", - "version": "1.2.11", + "version": "1.2.17", "license": "MIT", "dependencies": { "@types/find": "0.2.1", diff --git a/package.json b/package.json index 6681c6b..2fd577b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "marvelsnaptracker", "productName": "Marvel Snap Tracker", - "version": "1.2.15", + "version": "1.2.17", "description": "Marvel Snap Tracker", "main": "./.webpack/main", "scripts": { @@ -26,7 +26,7 @@ "dependencies": { "@types/find": "0.2.1", "auto-launch": "5.0.6", - "axios": "1.4.0", + "axios": "1.5.0", "date-fns": "2.30.0", "electron-is-dev": "2.0.0", "error-stack-parser": "2.1.4", @@ -61,13 +61,13 @@ "file-loader": "6.2.0", "fork-ts-checker-webpack-plugin": "7.3.0", "node-loader": "2.0.0", - "prettier": "3.0.2", + "prettier": "3.0.3", "style-loader": "3.3.3", "ts-loader": "9.4.4", "tslint": "6.1.3", "tslint-loader": "3.5.4", "tslint-plugin-prettier": "2.3.0", - "typescript": "5.1.6", + "typescript": "5.2.2", "webpack-hook-plugin": "1.0.7" }, "optionalDependencies": { diff --git a/src/api/cards.ts b/src/api/cards.ts new file mode 100644 index 0000000..b3bba0c --- /dev/null +++ b/src/api/cards.ts @@ -0,0 +1,10 @@ +import {Cards} from 'root/models/cards'; +import {Request} from 'root/app/request'; + +export async function getCards(): Promise { + const res = await Request.get('/snap/do.php?cmd=getcards', { + url: 'https://static2.marvelsnap.pro/snap/do.php?cmd=getcards', + }); + + return res; +} diff --git a/src/app/game_state.ts b/src/app/game_state.ts index a05dae4..f7353d5 100644 --- a/src/app/game_state.ts +++ b/src/app/game_state.ts @@ -2,6 +2,7 @@ import {exec, execFile} from 'child_process'; import {BrowserWindow} from 'electron'; import electronIsDev from 'electron-is-dev'; import psList from 'ps-list'; +import {getCards} from 'root/api/cards'; import {registerHotkeys, unRegisterHotkeys} from 'root/app/hotkeys'; import {WindowLocator} from 'root/app/locatewindow'; import {withLogParser} from 'root/app/log_parser_manager'; @@ -181,6 +182,9 @@ class GameState { sendMessageToOverlayWindow('set-ovlsettings', ovlSettings); sendMessageToOverlayWindow('deck-message', this.selectedDeck); sendMessageToOverlayWindow('decks-message', this.decks); + getCards().then((cards) => { + sendMessageToOverlayWindow('cards-message', cards); + }); } public overlayPositionSetter(onlySetPosition?: boolean): void { diff --git a/src/lib/messages.ts b/src/lib/messages.ts index 1a34bd4..7822190 100644 --- a/src/lib/messages.ts +++ b/src/lib/messages.ts @@ -1,7 +1,7 @@ import {TokenCheckRes, TokenRequestRes} from 'root/api/userbytokenid'; import {Account, LatestSettings, OverlaySettings} from 'root/app/settings-store/settings_store'; import {HotkeysSettingsV1} from 'root/app/settings-store/v8'; -import {CardPlayed} from 'root/models/cards'; +import {Cards} from 'root/models/cards'; import {UserMetadata} from 'root/models/metadata'; import {UserDeck} from 'root/models/snap_deck'; import {UserResult} from 'root/models/userbytokenid'; @@ -81,6 +81,7 @@ export interface Messages { 'disable-clicks': undefined; 'deck-message': string; 'decks-message': Array; + 'cards-message': Cards; 'set-userdata': UserMetadata; mulligan: boolean; 'set-version': string; @@ -92,7 +93,6 @@ export interface Messages { 'set-setting-icon': string; 'set-setting-do-uploads': boolean; 'set-setting-disable-hotkeys': boolean; - 'card-played': CardPlayed; 'set-setting-o-hidezero': boolean; 'set-setting-o-hidemy': boolean; 'set-setting-o-hideopp': boolean; diff --git a/src/models/cards.ts b/src/models/cards.ts index 51f0cca..d4eec92 100644 --- a/src/models/cards.ts +++ b/src/models/cards.ts @@ -1,127 +1,87 @@ export interface Card { - id: number; - doublelink: number; - cardid: string; - multiverseid: number; + CardDefId: string; name: string; - slug: string; - kw: string; - flavor: string; - power: number; - market: number; - toughness: number; - expansion: number; - rarity: number; - mana: string; - convmana: number; - text: string; - loyalty: number; - type: number; - subtype: number; - txttype: string; - pict: string; - date_in: number; - colorindicator: string; - mtga_id: number; - is_collectible: number; - reprint: number; - draftrate: number; - drafteval: number; - is_land: number; - colorarr: string; - currentstandard: number; - currenthistoric: number; - art: string; - has_hiresimg: number; - willbeoutsoon: number; - drafteval2: number; - wleval: number; - battleusage: number; - wleval_draft: number; - battleusage_draft: number; - is_boostable: number; - is_craftable: number; - TraditionalStandardBan: number; - TraditionalHistoricBan: number; - StandardBan: number; - HistoricBan: number; - wleval_1sthand: number; + description: string; + abilities: string; + cost: string; + power: string; + category: string; + source: string; + variants: Variant[]; + use_count: string; + connected_cards: string; + is_Token: string; + share_cube_earned: number; + share_cube_lost: number; + share_cube_won: number; + share_loss: number; + share_total: number; + share_win: number; + stats_cuberate: number; + stats_winrate: number; + collectible: string; + stats_cube_lost: string; + stats_cube_won: string; + stats_loss: string; + stats_win: string; + stats_position: string; + PrimaryColor: string; + RingColor: string; + SecondaryColor: string; + stats_winrate_played: string; + stats_cuberate_played: string; + CardSeriesDefId: string; + SeriesStartDates: string; } -export interface Cardnfo { - battleusage: number; - battleusage_draft: number; - drafteval2: number; - id: number; - market: number; - mtga_id: number; - reprints: number[]; - wleval: number; - wleval_draft: number; +export interface Variant { + id: string; + source: string; + category: string; + credits?: string; + released?: string; + possession?: string | null; + usage_count?: string | null; + ReleaseDate?: string; + wasAddedIn?: string; } -export interface Expcount { - cardcount: number; - rar_1: number; - rar_2: number; - rar_3: number; - rar_4: number; -} - -export interface CardFilterResult { - data: Cardnfo[]; - maxdrafteval2: number; - maxprice: number; - maxusage: number; - minusage: number; - maxusagedraft: number; - minusagedraft: number; - maxwleval: number; - maxwleval_draft: number; - mindrafteval2: number; - minwleval: number; - minwleval_draft: number; -} +export type Cards = Record; -export interface CardRequestFilters { - color: string[]; - expansion: string; - mana: string; - type: string; - subtype: string; +export interface Location { + CardDefId: string; + abilities: string; + description: string; + difficulty: string; + name: string; rarity: string; - rulings: string; - srt: string; - direct: string; - smrtsrhc: string; - collection?: string; - booster: string; - TraditionalStandardBan: string; - TraditionalHistoricBan: string; - StandardBan: string; - HistoricBan: string; + tip: string; + released: string; } -export interface CardFilterReq { - direct: number; - filter: {[index: string]: string[] | number[]}; - lib: number; - limit: number; - page: number; - srt: number; -} +export type Locations = Record; -export interface CardPriceData { - date: string; - bid: number; - ask: number; - market: number; -} +export type VariantFiltersStrings = 'status' | 'srt' | 'direct' | 'rarity' | 'category' | 'smrtsrhc' | 'clearfilters'; + +export type CardFiltersStrings = + | 'cost' + | 'power' + | 'pool' + | 'srt' + | 'direct' + | 'smrtsrhc' + | 'clearfilters' + | 'usecount' + | 'collection' + | 'dataToShow' + | 'releaseStatus' + | 'tokenStatus'; + +export type LocationFiltersStrings = 'smrtsrhc' | 'released' | 'rarity' | 'difficulty' | 'clearfilters'; -export interface CardPlayed { - grpId: number; - instanceId: number; - ownerSeatId: number; - visibility: string; - zoneId: number; +export interface CardBack { + CardBackDefId: string; + Name: string; + Enabled: string; + source: string; } diff --git a/src/models/match.ts b/src/models/match.ts index 60eeb2a..faf8445 100644 --- a/src/models/match.ts +++ b/src/models/match.ts @@ -34,9 +34,9 @@ export class Match { public DecisionPlayer: number = 0; public totalCards: number = 0; public oppEntityId: number = 0; - public oppDeckStable: Array<{cardDefId: string; rarity: string; artVariantDefId: string}> = []; + public oppDeckStable: SnapCard[] = []; - public over(purgeOpp?:boolean): void { + public over(purgeOpp?: boolean): void { this.matchId = ''; this.ourUid = ''; this.zones = {}; @@ -50,8 +50,8 @@ export class Match { this.DecisionPlayer = 0; this.totalCards = 0; this.timers = {me: 0, opponent: 0}; - if(purgeOpp){ - this.oppDeckStable=[]; + if (purgeOpp) { + this.oppDeckStable = []; } } diff --git a/src/models/overlay.ts b/src/models/overlay.ts index 7794e29..95ab1d3 100644 --- a/src/models/overlay.ts +++ b/src/models/overlay.ts @@ -1,9 +1,9 @@ import {OverlaySettings} from 'root/app/settings-store/settings_store'; -import {Card} from 'root/models/cards'; +import {Cards} from 'root/models/cards'; export interface OverlayConfig { ovlSettings: OverlaySettings | undefined; - allCards: Map; + allCards: Cards; selectedDeck: string; currentScale: number; currentOpacity: number; diff --git a/src/windows/overlay/functions/drawdeck.ts b/src/windows/overlay/functions/drawdeck.ts index 9acb083..dd17838 100644 --- a/src/windows/overlay/functions/drawdeck.ts +++ b/src/windows/overlay/functions/drawdeck.ts @@ -1,9 +1,11 @@ import {makeCard} from 'root/windows/overlay/functions/makecard'; +import {sortDeck} from 'root/windows/overlay/functions/sortdeck'; import {currentMatch, overlayConfig, overlayElements, toggleButtonClass} from 'root/windows/overlay/overlay'; export function drawDeck(): void { let output = ''; currentMatch.totalCards = 0; + currentMatch.myFullDeck = sortDeck(currentMatch.myFullDeck, true); currentMatch.myFullDeck.forEach((card) => { output += makeCard(card.CardDefId, true, card.RarityDefId, card.ArtVariantDefId); }); diff --git a/src/windows/overlay/functions/makecard.ts b/src/windows/overlay/functions/makecard.ts index 936de5a..eae455d 100644 --- a/src/windows/overlay/functions/makecard.ts +++ b/src/windows/overlay/functions/makecard.ts @@ -1,13 +1,18 @@ -import {currentMatch, overlayConfig} from 'root/windows/overlay/overlay'; - export function makeCard(cardDefId: string, side: boolean, rarity?: string, variant?: string): string { + const today = new Date(); + const yyyy = today.getFullYear(); + const mm = today.getMonth() + 1; // Months start at 0! + const dd = today.getDate(); + const formattedToday = dd + '-' + mm + '-' + yyyy; return `
+ side ? 'me' : 'opp' + }" id="card${cardDefId}${side ? 'me' : 'opp'}" style="width: 80px; height:104px;">
+ }${ + rarity && rarity != '' && rarity !== 'Common' ? `-${rarity.toLowerCase()}` : '' + }.webp?anticache=${formattedToday}')">
`; } diff --git a/src/windows/overlay/functions/messages_ipcmain.ts b/src/windows/overlay/functions/messages_ipcmain.ts index 0231da1..1c8a684 100644 --- a/src/windows/overlay/functions/messages_ipcmain.ts +++ b/src/windows/overlay/functions/messages_ipcmain.ts @@ -81,11 +81,10 @@ export function SetMessages(setInteractiveHandler: (overlaySettings: OverlaySett sendMessageToIpcMain('set-scale', zoom); }); - /*onMessageFromIpcMain('set-metadata', (meta) => { - overlayConfig.metaData = meta; - overlayConfig.allCards = new Map(meta.allcards); - overlayConfig.metaData.allcards = []; - });*/ + onMessageFromIpcMain('cards-message', (cards) => { + overlayConfig.allCards = cards; + //console.log(overlayConfig.allCards); + }); onMessageFromIpcMain('match-started', (newMatch) => { //console.log('match-started', newMatch); diff --git a/src/windows/overlay/functions/sortdeck.ts b/src/windows/overlay/functions/sortdeck.ts new file mode 100644 index 0000000..0c28c7c --- /dev/null +++ b/src/windows/overlay/functions/sortdeck.ts @@ -0,0 +1,18 @@ +import {SnapCard} from 'root/models/snap_deck'; +import {overlayConfig} from 'root/windows/overlay/overlay'; + +export function sortDeck(deck: SnapCard[], asc: boolean): SnapCard[] { + deck.sort((a, b) => { + const cardA = overlayConfig.allCards[a.CardDefId.toLowerCase()]; + const cardB = overlayConfig.allCards[b.CardDefId.toLowerCase()]; + return +cardA.cost === +cardB.cost + ? +cardA.power === +cardB.power + ? asc + ? cardA.name.localeCompare(cardB.name) + : cardB.name.localeCompare(cardA.name) + : (asc ? +cardA.power : +cardB.power) - (asc ? +cardB.power : +cardA.power) + : (asc ? +cardA.cost : +cardB.cost) - (asc ? +cardB.cost : +cardA.cost); + }); + + return deck; +} diff --git a/src/windows/overlay/functions/updatedeck.ts b/src/windows/overlay/functions/updatedeck.ts index 40fb067..c71904c 100644 --- a/src/windows/overlay/functions/updatedeck.ts +++ b/src/windows/overlay/functions/updatedeck.ts @@ -1,11 +1,10 @@ +import {SnapCard} from 'root/models/snap_deck'; import {makeCard} from 'root/windows/overlay/functions/makecard'; +import {sortDeck} from 'root/windows/overlay/functions/sortdeck'; import {currentMatch, overlayConfig, overlayElements} from 'root/windows/overlay/overlay'; export function updateDeck(highlight: string[]): void { - /*currentMatch.myFullDeck.forEach((TheCard) => { - genBattleCardNum(TheCard.CardDefId); - });*/ - const graveyard: string[] = []; + let graveyard: SnapCard[] = []; let output = ''; let graveyardString = ''; @@ -16,17 +15,19 @@ export function updateDeck(highlight: string[]): void { TheEntity.cardDefId !== '' && currentMatch.zones[TheEntity.zoneId].type === 'graveyardEntity' ) { - graveyard.push(TheEntity.cardDefId); + graveyard.push({ + CardDefId: TheEntity.cardDefId, + RarityDefId: TheEntity.rarityDefId, + ArtVariantDefId: TheEntity.artVariantDefId, + }); } }); + graveyard = sortDeck(graveyard, true); + if (graveyard.length > 0) { - currentMatch.myFullDeck.forEach((card) => { - if (graveyard.includes(card.CardDefId)) { - graveyardString += makeCard(card.CardDefId, true, card.RarityDefId, card.ArtVariantDefId); - } else { - output += makeCard(card.CardDefId, true, card.RarityDefId, card.ArtVariantDefId); - } + graveyard.forEach((card) => { + graveyardString += makeCard(card.CardDefId, true, card.RarityDefId, card.ArtVariantDefId); }); overlayElements.MainOut.innerHTML = diff --git a/src/windows/overlay/functions/updateoppdeck.ts b/src/windows/overlay/functions/updateoppdeck.ts index e006508..39e93b4 100644 --- a/src/windows/overlay/functions/updateoppdeck.ts +++ b/src/windows/overlay/functions/updateoppdeck.ts @@ -1,33 +1,33 @@ +import {SnapCard} from 'root/models/snap_deck'; import {makeCard} from 'root/windows/overlay/functions/makecard'; +import {sortDeck} from 'root/windows/overlay/functions/sortdeck'; import {currentMatch, overlayConfig, overlayElements, toggleButtonClass} from 'root/windows/overlay/overlay'; export function updateOppDeck(highlight: string[]): void { - const oppGraveyard: Array<{cardDefId: string; rarity: string; artVariantDefId: string}> = []; + let oppGraveyard: SnapCard[] = []; Object.keys(currentMatch.cardEntityIDs).forEach((cardEntityID) => { const TheEntity = currentMatch.cardEntityIDs[+cardEntityID]; if ( +TheEntity.ownerEntityId === +currentMatch.oppEntityId && TheEntity.cardDefId !== '' && - currentMatch.oppDeckStable.findIndex((el) => el.cardDefId === TheEntity.cardDefId) === -1 && - currentMatch.zones[TheEntity.zoneId].type !== 'graveyardEntity' + currentMatch.oppDeckStable.findIndex((el) => el.CardDefId === TheEntity.cardDefId) === -1 ) { currentMatch.oppDeckStable.push({ - cardDefId: TheEntity.cardDefId, - rarity: TheEntity.rarityDefId, - artVariantDefId: TheEntity.artVariantDefId, + CardDefId: TheEntity.cardDefId, + RarityDefId: TheEntity.rarityDefId, + ArtVariantDefId: TheEntity.artVariantDefId, }); } if ( +TheEntity.ownerEntityId === +currentMatch.oppEntityId && TheEntity.cardDefId !== '' && - currentMatch.oppDeckStable.findIndex((el) => el.cardDefId === TheEntity.cardDefId) === -1 && currentMatch.zones[TheEntity.zoneId].type === 'graveyardEntity' ) { oppGraveyard.push({ - cardDefId: TheEntity.cardDefId, - rarity: TheEntity.rarityDefId, - artVariantDefId: TheEntity.artVariantDefId, + CardDefId: TheEntity.cardDefId, + RarityDefId: TheEntity.rarityDefId, + ArtVariantDefId: TheEntity.artVariantDefId, }); } }); @@ -35,12 +35,16 @@ export function updateOppDeck(highlight: string[]): void { let output = ''; let outputGrave = ''; + currentMatch.oppDeckStable = sortDeck(currentMatch.oppDeckStable, true); + currentMatch.oppDeckStable.forEach((card) => { - output += makeCard(card.cardDefId, false, card.rarity, card.artVariantDefId); + output += makeCard(card.CardDefId, false, card.RarityDefId, card.ArtVariantDefId); }); + oppGraveyard = sortDeck(oppGraveyard, true); + oppGraveyard.forEach((card) => { - outputGrave += makeCard(card.cardDefId, false, card.rarity, card.artVariantDefId); + outputGrave += makeCard(card.CardDefId, false, card.RarityDefId, card.ArtVariantDefId); }); overlayElements.OpponentOut.innerHTML =