Skip to content

Commit 898e41a

Browse files
authoredMar 10, 2025··
[Misc] StatsContainer.updateIvs() now has proper param typing (#814)
1 parent f9121e8 commit 898e41a

File tree

2 files changed

+63
-64
lines changed

2 files changed

+63
-64
lines changed
 

‎src/ui/starter-select-ui-handler.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -3037,8 +3037,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
30373037
this.showStats();
30383038
} else {
30393039
this.statsContainer.setVisible(false);
3040-
//@ts-ignore
3041-
this.statsContainer.updateIvs(null); // TODO: resolve ts-ignore. what. how? huh?
3040+
this.statsContainer.updateIvs(null);
30423041
}
30433042
}
30443043

@@ -4035,8 +4034,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
40354034
this.statsMode = false;
40364035
this.statsContainer.setVisible(false);
40374036
this.pokemonSprite.setVisible(!!this.speciesStarterDexEntry?.caughtAttr);
4038-
//@ts-ignore
4039-
this.statsContainer.updateIvs(null); // TODO: resolve ts-ignore. !?!?
4037+
this.statsContainer.updateIvs(null);
40404038
}
40414039
}
40424040

‎src/ui/stats-container.ts

+61-60
Original file line numberDiff line numberDiff line change
@@ -105,68 +105,69 @@ export class StatsContainer extends Phaser.GameObjects.Container {
105105
}
106106
}
107107

108-
updateIvs(ivs: number[], originalIvs?: number[]): void {
109-
if (ivs) {
110-
const ivChartData = new Array(6)
111-
.fill(null)
112-
.map((_, i) => [
113-
(ivs[ivChartStatIndexes[i]] / 31) * ivChartSize * ivChartStatCoordMultipliers[ivChartStatIndexes[i]][0],
114-
(ivs[ivChartStatIndexes[i]] / 31) * ivChartSize * ivChartStatCoordMultipliers[ivChartStatIndexes[i]][1],
115-
])
116-
.flat();
117-
const lastIvChartData = this.statsIvsCache || defaultIvChartData;
118-
this.statsIvsCache = ivChartData.slice(0);
119-
120-
this.ivStatValueTexts.map((t: BBCodeText, i: number) => {
121-
let label = "";
122-
123-
// Check to see if IVs are 31, if so change the text style to gold, otherwise leave them be.
124-
if (ivs[i] === 31) {
125-
label += getBBCodeFragment(ivs[i].toString(), TextStyle.PERFECT_IV, true, true);
126-
} else {
127-
label = ivs[i].toString();
128-
}
129-
if (this.showDiff && originalIvs) {
130-
if (originalIvs[i] < ivs[i]) {
131-
label += ` (${getBBCodeFragment(`+${ivs[i] - originalIvs[i]}`, TextStyle.SUMMARY_BLUE, true)})`;
132-
} else {
133-
label += " (-)";
134-
}
135-
}
136-
t.setText(`[shadow]${label}[/shadow]`);
137-
});
138-
139-
const newColor = ivs.every((iv) => iv === 31) ? 0xe8e8a8 : 0x98d8a0;
140-
const oldColor = this.ivChart.fillColor;
141-
const interpolateColor =
142-
oldColor !== newColor
143-
? [Phaser.Display.Color.IntegerToColor(oldColor), Phaser.Display.Color.IntegerToColor(newColor)]
144-
: null;
145-
146-
globalScene.tweens.addCounter({
147-
from: 0,
148-
to: 1,
149-
duration: 1000,
150-
ease: "Cubic.easeOut",
151-
onUpdate: (tween: Phaser.Tweens.Tween) => {
152-
const progress = tween.getValue();
153-
const interpolatedData = ivChartData.map(
154-
(v: number, i: number) => v * progress + lastIvChartData[i] * (1 - progress),
155-
);
156-
if (interpolateColor) {
157-
this.ivChart.setFillStyle(
158-
Phaser.Display.Color.ValueToColor(
159-
Phaser.Display.Color.Interpolate.ColorWithColor(interpolateColor[0], interpolateColor[1], 1, progress),
160-
).color,
161-
0.75,
162-
);
163-
}
164-
this.ivChart.setTo(interpolatedData);
165-
},
166-
});
167-
} else {
108+
updateIvs(ivs: number[] | null, originalIvs?: number[]): void {
109+
if (!ivs) {
168110
this.statsIvsCache = defaultIvChartData;
169111
this.ivChart.setTo(defaultIvChartData);
112+
return;
170113
}
114+
115+
const ivChartData = new Array(6)
116+
.fill(null)
117+
.map((_, i) => [
118+
(ivs[ivChartStatIndexes[i]] / 31) * ivChartSize * ivChartStatCoordMultipliers[ivChartStatIndexes[i]][0],
119+
(ivs[ivChartStatIndexes[i]] / 31) * ivChartSize * ivChartStatCoordMultipliers[ivChartStatIndexes[i]][1],
120+
])
121+
.flat();
122+
const lastIvChartData = this.statsIvsCache || defaultIvChartData;
123+
this.statsIvsCache = ivChartData.slice(0);
124+
125+
this.ivStatValueTexts.map((t: BBCodeText, i: number) => {
126+
let label = "";
127+
128+
// Check to see if IVs are 31, if so change the text style to gold, otherwise leave them be.
129+
if (ivs[i] === 31) {
130+
label += getBBCodeFragment(ivs[i].toString(), TextStyle.PERFECT_IV, true, true);
131+
} else {
132+
label = ivs[i].toString();
133+
}
134+
if (this.showDiff && originalIvs) {
135+
if (originalIvs[i] < ivs[i]) {
136+
label += ` (${getBBCodeFragment(`+${ivs[i] - originalIvs[i]}`, TextStyle.SUMMARY_BLUE, true)})`;
137+
} else {
138+
label += " (-)";
139+
}
140+
}
141+
t.setText(`[shadow]${label}[/shadow]`);
142+
});
143+
144+
const newColor = ivs.every((iv) => iv === 31) ? 0xe8e8a8 : 0x98d8a0;
145+
const oldColor = this.ivChart.fillColor;
146+
const interpolateColor =
147+
oldColor !== newColor
148+
? [Phaser.Display.Color.IntegerToColor(oldColor), Phaser.Display.Color.IntegerToColor(newColor)]
149+
: null;
150+
151+
globalScene.tweens.addCounter({
152+
from: 0,
153+
to: 1,
154+
duration: 1000,
155+
ease: "Cubic.easeOut",
156+
onUpdate: (tween: Phaser.Tweens.Tween) => {
157+
const progress = tween.getValue();
158+
const interpolatedData = ivChartData.map(
159+
(v: number, i: number) => v * progress + lastIvChartData[i] * (1 - progress),
160+
);
161+
if (interpolateColor) {
162+
this.ivChart.setFillStyle(
163+
Phaser.Display.Color.ValueToColor(
164+
Phaser.Display.Color.Interpolate.ColorWithColor(interpolateColor[0], interpolateColor[1], 1, progress),
165+
).color,
166+
0.75,
167+
);
168+
}
169+
this.ivChart.setTo(interpolatedData);
170+
},
171+
});
171172
}
172173
}

0 commit comments

Comments
 (0)
Please sign in to comment.