Skip to content

Commit

Permalink
reader test
Browse files Browse the repository at this point in the history
  • Loading branch information
Manwe-777 committed Mar 20, 2024
1 parent 59e94d3 commit 476b0c0
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 549 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: "actions/checkout@v2"

- name: "Install modules"
run: "npm run install:ci"
run: "npm set strict-ssl false && npm run install:ci"

- name: "Test"
run: "npm run jest:ci"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v2

- name: "Install modules"
run: "npm run install:ci"
run: "npm set strict-ssl false && npm run install:ci"

- name: "Generate build information json"
run: "node generateInfo.js"
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: "actions/checkout@v2"

- name: "Install modules"
run: "npm run install:ci"
run: "npm set strict-ssl false && npm run install:ci"

- name: "Test"
run: "npm run jest:ci"
Expand Down Expand Up @@ -57,8 +57,6 @@ jobs:
cd linux-installer
chmod +x *.AppImage
chmod +x *.sh
chmod +x mtga-tracker-daemon/*.sh
chmod +x mtga-tracker-daemon/bin/mtga-tracker-daemon
tar czvf "../dist/mtgatool-desktop-linux-installer.tar.gz" *
cd ..
Expand Down
4 changes: 2 additions & 2 deletions craco.web.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const ModuleReplacement = require("./module-resolver-file");
const WebpackReactComponentNamePlugin = require("webpack-react-component-name");
const ModuleReplacement = require("./module-resolver-file");

process.env.PORT = 3006;

Expand All @@ -14,7 +14,7 @@ module.exports = {
},
plugins: [
...ModuleReplacement({ webIndex: true, electronIndex: false }),
new WebpackReactComponentNamePlugin()
new WebpackReactComponentNamePlugin(),
],
},
eslint: {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"electron-log": "^5.0.0",
"electron-updater": "^6.1.4",
"extract-zip": "^2.0.1",
"find-process": "^1.4.7",
"mtga-reader": "https://mtgatool.com/libs/mtga-reader-1.0.0.tgz",
"follow-redirects": "^1.14.3",
"google-protobuf": "^3.15.6",
"history": "^4.10.1",
Expand Down Expand Up @@ -202,4 +204,4 @@
"type": "git",
"url": "https://github.com/mtgatool/mtgatool-desktop.git"
}
}
}
1 change: 0 additions & 1 deletion public/tooldb-worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,6 @@ function login(username, password) {
return keys;
})
.catch((err) => {
console.warn("Login error:", err);
self.postMessage({ type: "LOGIN_ERR", err });
});
}
Expand Down
92 changes: 45 additions & 47 deletions src/background/onLabel/MatchGameRoomStateChangedEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import {
} from "mtgatool-shared";

import postChannelMessage from "../../broadcastChannel/postChannelMessage";
import MtgaTrackerDaemon from "../../daemon/mtgaTrackerDaemon";
import LogEntry from "../../types/logDecoder";
import getLocalSetting from "../../utils/getLocalSetting";
import isLimitedEventId from "../../utils/isLimitedEventId";
import actionLog from "../actionLog";
import saveMatch from "../saveMatch";
import selectDeck from "../selectDeck";
Expand All @@ -29,7 +27,7 @@ interface Entry extends LogEntry {
json: MatchGameRoomStateChange;
}

const rankClass: Record<number, string> = {
export const rankClass: Record<number, string> = {
"-1": "Unranked",
"0": "Beginner",
"1": "Bronze",
Expand Down Expand Up @@ -180,53 +178,53 @@ export default function onLabelMatchGameRoomStateChangedEvent(
}
*/

if ((window as any).daemon) {
const isLimited = isLimitedEventId(gameRoom.gameRoomConfig.eventId);
// if ((window as any).daemon) {
// const isLimited = isLimitedEventId(gameRoom.gameRoomConfig.eventId);

((window as any).daemon as MtgaTrackerDaemon)
.getMatchState()
.then((state) => {
if (
state &&
state.matchId === gameRoom.gameRoomConfig.matchId &&
state.playerRank.class > 0
) {
const opponent = {
tier: state.opponentRank.tier,
rank: rankClass[state.opponentRank.class],
percentile: state.opponentRank.mythicPercentile,
leaderboardPlace: state.opponentRank.mythicPlacement,
};
setOpponent(opponent);
// ((window as any).daemon as MtgaTrackerDaemon)
// .getMatchState()
// .then((state) => {
// if (
// state &&
// state.matchId === gameRoom.gameRoomConfig.matchId &&
// state.playerRank.class > 0
// ) {
// const opponent = {
// tier: state.opponentRank.tier,
// rank: rankClass[state.opponentRank.class],
// percentile: state.opponentRank.mythicPercentile,
// leaderboardPlace: state.opponentRank.mythicPlacement,
// };
// setOpponent(opponent);

const player = {
tier: state.playerRank.tier,
rank: rankClass[state.playerRank.class],
percentile: state.playerRank.mythicPercentile,
leaderboardPlace: state.playerRank.mythicPlacement,
};
setPlayer(player);
// const player = {
// tier: state.playerRank.tier,
// rank: rankClass[state.playerRank.class],
// percentile: state.playerRank.mythicPercentile,
// leaderboardPlace: state.playerRank.mythicPlacement,
// };
// setPlayer(player);

if (isLimited) {
postChannelMessage({
type: "UPSERT_DB_RANK",
value: {
limitedClass: rankClass[state.playerRank.class],
limitedLevel: state.playerRank.tier,
},
});
} else {
postChannelMessage({
type: "UPSERT_DB_RANK",
value: {
constructedClass: rankClass[state.playerRank.class],
constructedLevel: state.playerRank.tier,
},
});
}
}
});
}
// if (isLimited) {
// postChannelMessage({
// type: "UPSERT_DB_RANK",
// value: {
// limitedClass: rankClass[state.playerRank.class],
// limitedLevel: state.playerRank.tier,
// },
// });
// } else {
// postChannelMessage({
// type: "UPSERT_DB_RANK",
// value: {
// constructedClass: rankClass[state.playerRank.class],
// constructedLevel: state.playerRank.tier,
// },
// });
// }
// }
// });
// }

setEventId(eventId);

Expand Down
18 changes: 0 additions & 18 deletions src/broadcastChannel/mainChannelListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import upsertDbRank from "../toolDb/upsertDbRank";
import { putData } from "../toolDb/worker-wrapper";
import LogEntry from "../types/logDecoder";
import bcConnect from "../utils/bcConnect";
import electron from "../utils/electron/electronWrapper";
import globalData from "../utils/globalData";
import switchPlayerUUID from "../utils/switchPlayerUUID";
import { ChannelMessage } from "./channelMessages";
Expand All @@ -27,23 +26,6 @@ export default function mainChannelListeners() {

let logReadFinished = false;

if (electron) {
electron.ipcRenderer.on(
"mtgaTrackerDaemonVersion",
(event: any, d: any) => {
console.log("mtgaTrackerDaemonVersion", d);
globalData.latestDaemon = d;
if (globalData.daemon) {
globalData.daemon.downloadLatestDaemon().finally(() => {
if (globalData.daemon) {
globalData.daemon.startDaemon();
}
});
}
}
);
}

channel.onmessage = (msg: MessageEvent<ChannelMessage>) => {
// console.log(msg.data.type);
if (logReadFinished && msg.data.type === "OVERLAY_UPDATE") {
Expand Down
96 changes: 8 additions & 88 deletions src/components/views/settings/DaemonSettingsPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,103 +1,23 @@
/* eslint-disable no-nested-ternary */
/* eslint-disable radix */
import { ChangeEvent, useCallback, useEffect, useState } from "react";
import { useEffect, useState } from "react";

import getLocalSetting from "../../../utils/getLocalSetting";
import globalData from "../../../utils/globalData";
import openExternal from "../../../utils/openExternal";
import Button from "../../ui/Button";

export default function DaemonSettingsPanel(): JSX.Element {
const [daemonStatus, setDaemonStatus] = useState("warn");
const [daemonPort, setDaemonPort] = useState(
parseInt(getLocalSetting("daemonPort"))
);

const [daemonPortReal, setDaemonPortReal] = useState(
parseInt(getLocalSetting("daemonPort"))
);

const handleSetDaemonPort = useCallback(
(event: ChangeEvent<HTMLInputElement>): void => {
setDaemonPort(parseInt(event.target.value));
},
[]
);

const changeDaemonPort = useCallback((): void => {
if (globalData.daemon) {
globalData.daemon.port = daemonPort;
}
setDaemonPortReal(daemonPort);
}, [daemonPort]);

useEffect(() => {
if (globalData.daemon) {
globalData.daemon
.getStatus()
.then((s) => {
if (s && s.isRunning) {
setDaemonStatus("ok");
} else {
setDaemonStatus("err");
}
})
.catch(() => {
setDaemonStatus("warn");
});
} else {
setDaemonStatus("warn");
}
}, [daemonPortReal]);
if (globalData.mtgaReader.status === "CONNECTED") setDaemonStatus("ok");
else if (globalData.mtgaReader.status === "DISCONNECTED")
setDaemonStatus("err");
else setDaemonStatus("warn");
}, []);

return (
<>
<div style={{ margin: "24px 0 12px 0" }}>
<p>
Mtga Tracker Daemon is a utility service app that reads MTG
Arena&apos;s process memory to access some of the information that is
not available on the logs. You can read more about it here;{" "}
<a
className="link"
onClick={(): void =>
openExternal("https://github.com/frcaton/mtga-tracker-daemon")
}
>
mtga-tracker-daemon
</a>
</p>
</div>
<div
className="input-container"
style={{
height: "40px",
}}
>
<label className="label">MTGA Tracker Daemon Port:</label>
<div
style={{
display: "flex",
width: "120px",
margin: "0 0 0 32px",
}}
>
<div
className="form-input-container"
style={{ padding: "0", margin: "auto" }}
>
<input
onChange={handleSetDaemonPort}
autoComplete="off"
type="text"
value={daemonPort}
/>
</div>
</div>
<Button
text="Set and check"
style={{ margin: "auto auto auto 32px" }}
onClick={changeDaemonPort}
/>
<div className="log-status-text">
<label className="label">MTGA:</label>
<div className={`log-status-${daemonStatus}`} />
</div>
</>
Expand Down
5 changes: 2 additions & 3 deletions src/components/views/settings/LogsSettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ export default function LogsSettingsPanel(): JSX.Element {

return (
<>
<DaemonSettingsPanel />
<div className="log-status-text">
Status:{" "}
Log Status:{" "}
<div
title={isReading ? `Reading` : "Not reading"}
className={isReading ? `log-status-ok` : "log-status-err"}
Expand Down Expand Up @@ -91,8 +92,6 @@ export default function LogsSettingsPanel(): JSX.Element {
}}
text={isReading ? "Stop reading log" : "Re-read log"}
/>

<DaemonSettingsPanel />
</>
);
}
23 changes: 8 additions & 15 deletions src/daemon/fetchCards.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import { Cards } from "mtgatool-shared";

import upsertDbCards from "../toolDb/upsertDbCards";
import globalData from "../utils/globalData";
import fetchPlayerId from "./fetchPlayerId";

export default function fetchCards() {
fetchPlayerId().then(() => {
if (globalData.daemon) {
globalData.daemon.getCards().then((cards) => {
if (cards && cards.length > 0) {
const parsedCards: Cards = {};
cards.forEach((c) => {
parsedCards[c.grpId] = c.owned;
});
fetchPlayerId();
const reader = globalData.mtgaReader;

const { cards } = reader.read("mtgaInventory") as any;
console.debug("cards info", cards);

upsertDbCards(parsedCards);
}
});
}
});
if (cards?.data) {
upsertDbCards(cards.data);
}
}
Loading

0 comments on commit 476b0c0

Please sign in to comment.