Skip to content

Commit 4e90b3e

Browse files
committed
Add account-viewer
1 parent f9aa6ba commit 4e90b3e

13 files changed

Lines changed: 1356 additions & 1 deletion

File tree

site/account-viewer/index.html

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>AccountViewer</title>
8+
</head>
9+
10+
<body>
11+
<main class="dashboard">
12+
<nav>
13+
<div class="nav-container">
14+
<div class="logo">SWGoH Updates</div>
15+
<button class="menu-toggle" aria-label="Toggle menu"></button>
16+
<ul class="nav-links">
17+
<li><a href="javascript:history.back()">Back</a></li>
18+
<li><a href="/">Home</a></li>
19+
<li><a href="../swgoh-portrait-maker/">SWGoH Portrait Maker</a></li>
20+
<li><a href="../swgoh-updates/">SWGoH Updates</a></li>
21+
<li><a href="../about/">About</a></li>
22+
</ul>
23+
</div>
24+
</nav>
25+
<div id="gap-1" style="height:5px;"></div>
26+
27+
<section class="allycode-input card">
28+
<h2>Enter AllyCode</h2>
29+
<input type="text" id="allyCodeInput" placeholder="AllyCode" maxlength="11" inputmode="numeric" />
30+
<button id="submitAllyCode">Submit</button>
31+
<p id="inputError" style="display: none;">Please enter a valid 9-digit Ally Code</p>
32+
</section>
33+
34+
<section class="loading-screen card hidden" id="loadingScreen">
35+
<h2>Loading player data...</h2>
36+
</section>
37+
38+
<section class="back hidden">
39+
<button id="backToInput">Select Other Player</button>
40+
</section>
41+
42+
<section class="player-info card hidden">
43+
<h2>Player Information</h2>
44+
<ul id="mainList"></ul>
45+
</section>
46+
47+
<section class="stats-grid hidden">
48+
<div class="card">
49+
<h3>Galactic Power</h3>
50+
<ul id="GPList"></ul>
51+
</div>
52+
53+
<div class="card">
54+
<h3>Mod Pips</h3>
55+
<ul id="pipList"></ul>
56+
</div>
57+
58+
<div class="card">
59+
<h3>Speed Mods</h3>
60+
<ul id="modsList"></ul>
61+
</div>
62+
63+
<div class="card">
64+
<h3>Offense Mods</h3>
65+
<ul id="offenseModsList"></ul>
66+
</div>
67+
</section>
68+
69+
<section class="charts-grid hidden">
70+
<div id="relicCanvas-container" class="chart-card"></div>
71+
<div id="gearCanvas-container" class="chart-card"></div>
72+
<div id="starCanvas-container" class="chart-card"></div>
73+
<div id="activeCanvas-container" class="chart-card"></div>
74+
</section>
75+
76+
<section class="stats-grid-2 hidden">
77+
<div class="card">
78+
<h3>Profile Stats</h3>
79+
<ul id="profileStatList"></ul>
80+
</div>
81+
</section>
82+
</main>
83+
84+
<script type="module" src="/src/account-viewer/main.ts"></script>
85+
</body>
86+
87+
</html>

site/package-lock.json

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
"preview": "vite preview"
1010
},
1111
"devDependencies": {
12+
"@types/crypto-js": "^4.2.2",
1213
"vite": "^7.1.7"
14+
},
15+
"dependencies": {
16+
"chart.js": "^4.5.1",
17+
"chartjs-plugin-datalabels": "^2.2.0",
18+
"crypto-js": "^4.2.0"
1319
}
1420
}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
import { getPlayer, getUnits } from "./requestMaker.ts";
2+
import type { PlayerResp, UnitsResp } from "./requestMaker.ts";
3+
import { profileStatMappings, playerMappings, galacticPowerMappings, speedModMappings, pipMappings, relicMappings, gearMappings, rarityMappings } from "./listBuilderMappings.ts";
4+
import { getSpeedModCount, getPipCount, countOffensePercentRolls } from "./mods.ts";
5+
import { ULLocation, relicChart, gearChart, starChart, activeChart } from "./locations.ts"
6+
7+
function handleProfileStat(player: PlayerResp): void {
8+
profileStatMappings.forEach(stat => {
9+
const playerStat = player.profileStat.find(ps => ps.index === stat.index);
10+
if (playerStat) {
11+
ULLocation("profileStatList", `${stat.displayName}: ${playerStat.value}`);
12+
}
13+
});
14+
}
15+
16+
function handleGP(player: PlayerResp): void {
17+
galacticPowerMappings.forEach(stat => {
18+
const playerStat = player.profileStat.find(ps => ps.index === stat.index)
19+
if (playerStat) {
20+
ULLocation("GPList", `${stat.displayName}: ${playerStat.value}`);
21+
}
22+
});
23+
}
24+
25+
function handleGear(player: PlayerResp, units: UnitsResp[]): void {
26+
let tracker: number[] = [];
27+
for (let key in gearMappings) {
28+
let counter = 0;
29+
player.rosterUnit.forEach(unit => {
30+
if (unit.currentTier && !checkIfShip(units, unit.definitionId)) {
31+
if (unit.currentTier === Number(key)) {
32+
counter++;
33+
}
34+
}
35+
});
36+
tracker.push(counter);
37+
}
38+
39+
gearChart(tracker);
40+
}
41+
42+
function handleRelics(player: PlayerResp, units: UnitsResp[]): void {
43+
let tracker: number[] = [];
44+
for (let key in relicMappings) {
45+
let counter = 0;
46+
player.rosterUnit.forEach(unit => {
47+
if (checkIfShip(units, unit.definitionId)) {
48+
return;
49+
}
50+
if (unit.relic && unit.relic.currentTier) {
51+
if (unit.relic.currentTier === Number(key)) {
52+
counter++;
53+
}
54+
}
55+
});
56+
tracker.push(counter);
57+
}
58+
relicChart(tracker);
59+
}
60+
61+
function handleActivated(player: PlayerResp, units: UnitsResp[]): void {
62+
let activated = 0, notActivated = 0;
63+
units.forEach(unit => {
64+
if (!unit.id.endsWith(":SEVEN_STAR")) {
65+
return;
66+
}
67+
if (!unit.obtainable || unit.obtainableTime != 0) {
68+
return;
69+
}
70+
const trimmed = unit.id.split(":")[0];
71+
let found = false;
72+
for (const pUnit of player.rosterUnit) {
73+
if (pUnit.definitionId.split(":")[0] === trimmed) {
74+
found = true;
75+
activated++;
76+
break;
77+
}
78+
}
79+
if (!found) {
80+
notActivated++;
81+
//console.log(`${trimmed} not activated`);
82+
}
83+
});
84+
85+
activeChart(activated, notActivated);
86+
}
87+
88+
function handleSpeedMods(player: PlayerResp): void {
89+
speedModMappings.forEach(stat => {
90+
ULLocation("modsList", `${stat.displayName}: ${getSpeedModCount(player, stat.min, stat.max)}`);
91+
});
92+
}
93+
94+
function handleOffenseMods(player: PlayerResp): void {
95+
const offenseStats = countOffensePercentRolls(player)
96+
for (const key in offenseStats) {
97+
ULLocation("offenseModsList", `${key}: ${offenseStats[key]}`)
98+
}
99+
}
100+
101+
function handlePips(player: PlayerResp): void {
102+
const { sixDot, fiveDot, other } = getPipCount(player);
103+
104+
ULLocation("pipList", `${pipMappings.sixDot}: ${sixDot}`);
105+
ULLocation("pipList", `${pipMappings.fiveDot}: ${fiveDot}`);
106+
ULLocation("pipList", `${pipMappings.other}: ${other}`);
107+
}
108+
109+
function handleStars(player: PlayerResp): void {
110+
let tracker: number[] = [];
111+
for (let rarity in rarityMappings) {
112+
let counter = 0;
113+
player.rosterUnit.forEach(unit => {
114+
if (unit.currentRarity === Number(rarity)) {
115+
counter++;
116+
}
117+
});
118+
tracker.push(counter);
119+
}
120+
starChart(tracker);
121+
}
122+
123+
function checkIfShip(units: UnitsResp[], defId: string): boolean {
124+
for (const unit of units) {
125+
if (unit.id === defId) {
126+
return unit.combatType === 2;
127+
}
128+
}
129+
130+
console.log(`Unit not found: ${defId}`);
131+
return false;
132+
}
133+
134+
export async function FillList(allyCode: string) {
135+
const units = await getUnits();
136+
if (!units) {
137+
console.error(`Failed to get units`)
138+
return
139+
}
140+
141+
const player: PlayerResp = await getPlayer(allyCode);
142+
143+
for (const playerKey in playerMappings) {
144+
const key = playerKey as keyof PlayerResp;
145+
if (!(key in playerMappings)) {
146+
console.error(`Missing ${key} in playerMappings`)
147+
continue
148+
}
149+
150+
switch (playerMappings[key].displayType) {
151+
case 0:
152+
ULLocation("mainList", `${playerMappings[key].displayName}: ${player[key]}`);
153+
break;
154+
case 1:
155+
handleProfileStat(player);
156+
break;
157+
case 2:
158+
handleGP(player);
159+
break;
160+
case 3:
161+
handleSpeedMods(player);
162+
break;
163+
case 4:
164+
handlePips(player);
165+
break;
166+
case 5:
167+
handleRelics(player, units);
168+
break;
169+
case 6:
170+
handleGear(player, units);
171+
break;
172+
case 7:
173+
handleStars(player);
174+
break;
175+
case 8:
176+
handleActivated(player, units);
177+
break;
178+
case 9:
179+
handleOffenseMods(player)
180+
break;
181+
default:
182+
console.error(`Found unknown playerMappings key: ${key}`)
183+
}
184+
}
185+
}

0 commit comments

Comments
 (0)