Skip to content

Commit

Permalink
1.2.18
Browse files Browse the repository at this point in the history
  • Loading branch information
Razviar committed Sep 3, 2023
1 parent 870df1f commit b93fc70
Show file tree
Hide file tree
Showing 24 changed files with 242 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "marvelsnaptracker",
"productName": "Marvel Snap Tracker",
"version": "1.2.17",
"version": "1.2.18",
"description": "Marvel Snap Tracker",
"main": "./.webpack/main",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/cards.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Cards} from 'root/models/cards';
import {Request} from 'root/app/request';
import {Cards} from 'root/models/cards';

export async function getCards(): Promise<Cards> {
const res = await Request.get('/snap/do.php?cmd=getcards', {
Expand Down
1 change: 1 addition & 0 deletions src/app/game_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions src/app/ipc_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ export function setupIpcMain(app: App): void {
'set-setting-o-savepositionleftopp',
'set-setting-o-savescale',
'set-setting-o-opacity',
'set-setting-o-cardsinarow',
];

overlaySettings.forEach((settingName, i) => {
Expand Down
8 changes: 4 additions & 4 deletions src/app/locatewindow.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {ChildProcessWithoutNullStreams} from 'child_process';
import {app, screen} from 'electron';
import fs from 'fs';
import {jsonrepair} from 'jsonrepair';
import {join} from 'path';

import {gameState} from 'root/app/game_state';
import {join} from 'path';
import {sendMessageToOverlayWindow} from 'root/app/messages';
import ourActiveWin from 'root/our-active-win';
import {settingsStore} from 'root/app/settings-store/settings_store';
import {jsonrepair} from 'jsonrepair';
import ourActiveWin from 'root/our-active-win';

export class WindowLocator {
public bounds: {x: number; y: number; width: number; height: number} = {x: 0, y: 0, width: 0, height: 0};
Expand Down Expand Up @@ -96,7 +96,7 @@ export class WindowLocator {
}
}

private interestingStrings = [
private readonly interestingStrings = [
'CubeGame.GameCreateChange',
'CubeGame.GameCreatePlayerChange',
'CubeGame.GameCreateLocationChange',
Expand Down
19 changes: 9 additions & 10 deletions src/app/log-parser/log_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {StateInfo, stateStore} from 'root/app/state_store';
import {getAccountFromScreenName} from 'root/app/userswitch';
import {asyncForEach} from 'root/lib/asyncforeach';
import {error} from 'root/lib/logger';

import {ParseResults} from 'root/models/indicators';
import {DeckCardArray, SnapCard, UserDeck} from 'root/models/snap_deck';

Expand All @@ -26,7 +25,7 @@ const FIVE_SECONDS = 5000;
export class LogParser {
private shouldStop: boolean = false;
public isRunning: boolean = false;
private currentState: StateInfo;
private readonly currentState: StateInfo;
private internalLoopTimeout: number = 0;
private parsingMetadata: ParsingMetadata | undefined;
private justStarted = true;
Expand Down Expand Up @@ -102,17 +101,17 @@ export class LogParser {
return;
}
//console.log('loop!');
let parsedResults: {[index: string]: any} = {};
let nextFilesState: {[index: string]: FileParsingState} = {};
let latestUpdateDate: Date | undefined = undefined;
const parsedResults: {[index: string]: any} = {};
const nextFilesState: {[index: string]: FileParsingState} = {};
let latestUpdateDate: Date | undefined;
const variables: {[index: string]: any} = {};

try {
await asyncForEach(parsingMetadata.FilesToParse, async (fileToParse) => {
const path = this.getPath(fileToParse);
//console.log(path);
//const LogFromMTGAFolder = locateMostRecentDate();
let stats: Stats | undefined = undefined;
let stats: Stats | undefined;
try {
stats = statSync(path);
} catch (e) {
Expand Down Expand Up @@ -154,7 +153,7 @@ export class LogParser {
return;
}
const pathToVariableToExtract = parsingMetadata.Variables[Variable].slice(1);
const extractedElementToProcess = extractValue(dataParsed, pathToVariableToExtract) as Array<any>;
const extractedElementToProcess = extractValue(dataParsed, pathToVariableToExtract) as any[];
//console.log('extractedElementToProcess', extractedElementToProcess);
switch (Variable) {
case 'PLAYER_ID':
Expand Down Expand Up @@ -214,7 +213,7 @@ export class LogParser {
}

const pathToInterestingArray = parsingMetadata.GatherFromArray[DataObjectArray].path.slice(1);
const interestingArray = extractValue(dataParsed, pathToInterestingArray, variables) as Array<any>;
const interestingArray = extractValue(dataParsed, pathToInterestingArray, variables) as any[];

interestingArray?.map((_, interestingArrayIndex) => {
const gatheredResult: any = {};
Expand Down Expand Up @@ -359,9 +358,9 @@ export class LogParser {
setTimeout(() => this.internalLoop(parsingMetadata), timeout);
}

private handleDecksMessage(decks: Array<any>): void {
private handleDecksMessage(decks: any[]): void {
try {
const DecksArray: Array<UserDeck> = [];
const DecksArray: UserDeck[] = [];
decks.forEach((deckDetails) => {
const cardsInDeck: DeckCardArray = [];
if (deckDetails.Cards === undefined || !Array.isArray(deckDetails.Cards)) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/log_parser_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface LogParserEvents {
state: LogFileParsingState;
};
'deck-message': string;
'decks-message': Array<UserDeck>;
'decks-message': UserDeck[];
'turn-info': {decisionPlayer: number; turnNumber?: number};
nologfile: undefined;
}
Expand Down
1 change: 1 addition & 0 deletions src/app/log_parser_manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import electronIsDev from 'electron-is-dev';

import {sendEventsToServer} from 'root/api/logsender';
import {gameState} from 'root/app/game_state';
import {LogParser} from 'root/app/log-parser/log_parser';
Expand Down
106 changes: 102 additions & 4 deletions src/app/settings-store/settings_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {join} from 'path';
import {AccountV0, OverlaySettingsV0, SettingsV1} from 'root/app/settings-store/v0';
import {AccountV9, OverlaySettingsV7, SettingsV10} from 'root/app/settings-store/v10';
import {AccountV10, SettingsV11} from 'root/app/settings-store/v11';
import {AccountV11, OverlaySettingsV8, SettingsV12} from 'root/app/settings-store/v12';
import {AccountV2, OverlaySettingsV2, SettingsV2} from 'root/app/settings-store/v2';
import {AccountV3, OverlaySettingsV3, SettingsV3} from 'root/app/settings-store/v3';
import {AccountV4, OverlaySettingsV4, SettingsV4} from 'root/app/settings-store/v4';
Expand Down Expand Up @@ -80,9 +81,9 @@ class SettingsStore {
}
}

export type LatestSettings = SettingsV11;
export type OverlaySettings = OverlaySettingsV7;
export type Account = AccountV10;
export type LatestSettings = SettingsV12;
export type OverlaySettings = OverlaySettingsV8;
export type Account = AccountV11;
type AllSettings =
| SettingsV0
| SettingsV1
Expand All @@ -95,7 +96,8 @@ type AllSettings =
| SettingsV8
| SettingsV9
| SettingsV10
| SettingsV11;
| SettingsV11
| SettingsV12;

export enum Version {
v0,
Expand All @@ -110,6 +112,7 @@ export enum Version {
v9,
v10,
v11,
v12,
}

export interface SettingsBase {
Expand Down Expand Up @@ -419,6 +422,64 @@ function asOverlaySettingsV7(ovlSettings: OverlaySettingsV6 | undefined): Overla
};
}

function asOverlaySettingsV8(ovlSettings: OverlaySettingsV7 | undefined): OverlaySettingsV8 | undefined {
if (!ovlSettings) {
return undefined;
}

const leftdigit = ovlSettings.leftdigit;
const rightdigit = ovlSettings.rightdigit;
const bottomdigit = ovlSettings.bottomdigit;
const rightdraftdigit = ovlSettings.rightdraftdigit;
const leftdraftdigit = ovlSettings.leftdigit;
const hidemy = ovlSettings.hidemy;
const hideopp = ovlSettings.hideopp;
const hidezero = ovlSettings.hidezero;
const showcardicon = ovlSettings.showcardicon;
const cardsinarow = 6;
const timers = ovlSettings.timers;
const neverhide = ovlSettings.neverhide;
const mydecks = ovlSettings.mydecks;
const cardhover = ovlSettings.cardhover;
const savepositiontop = ovlSettings.savepositiontop;
const savepositionleft = ovlSettings.savepositionleft;
const savepositiontopopp = ovlSettings.savepositiontopopp;
const savepositionleftopp = ovlSettings.savepositionleftopp;
const savescale = ovlSettings.savescale;
const opacity = ovlSettings.opacity;
const fontcolor = ovlSettings.fontcolor;
const detach = false;
const hidemain = false;
const interactive = !isMac();

return {
leftdigit,
rightdigit,
bottomdigit,
rightdraftdigit,
leftdraftdigit,
hidemy,
hideopp,
hidezero,
showcardicon,
timers,
neverhide,
mydecks,
cardhover,
savepositiontop,
savepositionleft,
savepositiontopopp,
savepositionleftopp,
savescale,
opacity,
cardsinarow,
fontcolor,
detach,
hidemain,
interactive,
};
}

function asPlayer(anyMap: AnyMap | undefined): Player | undefined {
if (!anyMap) {
return undefined;
Expand Down Expand Up @@ -622,6 +683,23 @@ function asAccountsV10(accountsV9: AccountV9[]): AccountV10[] {
return res;
}

function asAccountsV11(accountsV10: AccountV10[]): AccountV11[] {
const res: AccountV11[] = [];
accountsV10.forEach((acc) => {
res.push({
uid: acc.uid,
token: acc.token,
nick: acc.nick,
overlay: acc.overlay,
player: acc.player,
overlaySettings: asOverlaySettingsV8(acc.overlaySettings),
hotkeysSettings: acc.hotkeysSettings,
game: 'mtga',
});
});
return res;
}

function migrateV0toV1(v0: SettingsV0): SettingsV1 {
return {
version: Version.v1,
Expand Down Expand Up @@ -808,6 +886,24 @@ function migrateV10toV11(v10: SettingsV10): SettingsV11 {
};
}

function migrateV11toV12(v11: SettingsV11): SettingsV12 {
return {
version: Version.v12,
accounts: asAccountsV11(v11.accounts),
userToken: undefined,
icon: v11.icon,
autorun: v11.autorun,
minimized: v11.minimized,
overlay: v11.overlay,
manualUpdate: v11.manualUpdate,
awaiting: v11.awaiting,
logPath: v11.logPath,
mtgaPath: v11.mtgaPath,
nohotkeys: v11.nohotkeys,
uploads: v11.uploads,
};
}

function parseSettings(settings: AllSettings): LatestSettings {
// Recursively parse settings and migrate them to arrive at latest version
switch (settings.version) {
Expand All @@ -833,6 +929,8 @@ function parseSettings(settings: AllSettings): LatestSettings {
return parseSettings(migrateV9toV10(settings));
case Version.v10:
return parseSettings(migrateV10toV11(settings));
case Version.v11:
return parseSettings(migrateV11toV12(settings));
default:
return settings;
}
Expand Down
66 changes: 66 additions & 0 deletions src/app/settings-store/v12.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {Player, SettingsBase, Version} from 'root/app/settings-store/settings_store';

export interface SettingsV12 extends SettingsBase {
version: Version.v12;
accounts: AccountV11[];
userToken?: string;
icon?: string;
autorun: boolean;
minimized: boolean;
overlay: boolean;
manualUpdate: boolean;
awaiting?: Player;
logPath?: string;
mtgaPath?: string;
uploads?: boolean;
nohotkeys?: boolean;
}

export interface AccountV11 {
game: 'mtga' | 'lor';
uid: string;
token: string;
nick: string;
overlay: boolean;
player?: Player;
overlaySettings?: OverlaySettingsV8;
hotkeysSettings?: HotkeysSettingsV2;
}

export interface HotkeysSettingsV2 {
'hk-my-deck': string;
'hk-opp-deck': string;
'hk-overlay': string;
'hk-inc-size': string;
'hk-dec-size': string;
'hk-inc-opac': string;
'hk-dec-opac': string;
'hk-restart-mtga': string;
}

export interface OverlaySettingsV8 {
leftdigit: number;
rightdigit: number;
bottomdigit: number;
rightdraftdigit: number;
leftdraftdigit: number;
hidemy: boolean;
hideopp: boolean;
hidezero: boolean;
showcardicon: boolean;
neverhide: boolean;
mydecks: boolean;
cardhover: boolean;
timers: boolean;
savepositiontop: number;
savepositionleft: number;
savepositiontopopp: number;
savepositionleftopp: number;
savescale: number;
opacity: number;
cardsinarow: number;
fontcolor: number;
detach: boolean;
hidemain: boolean;
interactive: boolean;
}
8 changes: 4 additions & 4 deletions src/lib/func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,20 @@ export function Cut(str: string, from: string, to: string, offset?: number): str
}*/

export function getObject(o: any, prop: any, val: any): any {
if (o == null) return false;
if (o == undefined) { return false; }
if (o[prop] === val) {
return o;
}
var result;
let result;
if (o instanceof Array) {
for (var i = 0; i < o.length; i++) {
for (let i = 0; i < o.length; i++) {
result = getObject(o[i], prop, val);
if (result) {
return result;
}
}
} else {
for (var p in o) {
for (let p in o) {
if (p == prop) {
if (o[p] == val) {
return o;
Expand Down
Loading

0 comments on commit b93fc70

Please sign in to comment.