Compare commits

...

3 Commits

Author SHA1 Message Date
fabske0
5fe1afce95
Merge 1b57ee0959 into b2990aaa15 2025-08-15 11:38:45 +02:00
Sirz Benjie
b2990aaa15
[Bug] [Beta] Fix renaming runs (#6268)
Rename run name field, don't encrypt before updating
2025-08-14 16:57:01 -05:00
fabske0
1b57ee0959 chnage nature locales use 2025-08-14 21:51:09 +02:00
9 changed files with 98 additions and 97 deletions

View File

@ -29,6 +29,7 @@
"devDependencies": { "devDependencies": {
"@biomejs/biome": "2.0.0", "@biomejs/biome": "2.0.0",
"@ls-lint/ls-lint": "2.3.1", "@ls-lint/ls-lint": "2.3.1",
"@types/crypto-js": "^4.2.0",
"@types/jsdom": "^21.1.7", "@types/jsdom": "^21.1.7",
"@types/node": "^22.16.5", "@types/node": "^22.16.5",
"@vitest/coverage-istanbul": "^3.2.4", "@vitest/coverage-istanbul": "^3.2.4",

View File

@ -48,6 +48,9 @@ importers:
'@ls-lint/ls-lint': '@ls-lint/ls-lint':
specifier: 2.3.1 specifier: 2.3.1
version: 2.3.1 version: 2.3.1
'@types/crypto-js':
specifier: ^4.2.0
version: 4.2.2
'@types/jsdom': '@types/jsdom':
specifier: ^21.1.7 specifier: ^21.1.7
version: 21.1.7 version: 21.1.7
@ -718,6 +721,9 @@ packages:
'@types/cookie@0.6.0': '@types/cookie@0.6.0':
resolution: {integrity: sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==} resolution: {integrity: sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==}
'@types/crypto-js@4.2.2':
resolution: {integrity: sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==}
'@types/deep-eql@4.0.2': '@types/deep-eql@4.0.2':
resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==} resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==}
@ -2525,6 +2531,8 @@ snapshots:
'@types/cookie@0.6.0': {} '@types/cookie@0.6.0': {}
'@types/crypto-js@4.2.2': {}
'@types/deep-eql@4.0.2': {} '@types/deep-eql@4.0.2': {}
'@types/estree@1.0.8': {} '@types/estree@1.0.8': {}

View File

@ -17,8 +17,7 @@ export function initLoggedInUser(): void {
}; };
} }
export function updateUserInfo(): Promise<[boolean, number]> { export async function updateUserInfo(): Promise<[boolean, number]> {
return new Promise<[boolean, number]>(resolve => {
if (bypassLogin) { if (bypassLogin) {
loggedInUser = { loggedInUser = {
username: "Guest", username: "Guest",
@ -36,7 +35,7 @@ export function updateUserInfo(): Promise<[boolean, number]> {
} }
loggedInUser.lastSessionSlot = lastSessionSlot; loggedInUser.lastSessionSlot = lastSessionSlot;
// Migrate old data from before the username was appended // Migrate old data from before the username was appended
["data", "sessionData", "sessionData1", "sessionData2", "sessionData3", "sessionData4"].map(d => { ["data", "sessionData", "sessionData1", "sessionData2", "sessionData3", "sessionData4"].forEach(d => {
const lsItem = localStorage.getItem(d); const lsItem = localStorage.getItem(d);
if (lsItem && !!loggedInUser?.username) { if (lsItem && !!loggedInUser?.username) {
const lsUserItem = localStorage.getItem(`${d}_${loggedInUser.username}`); const lsUserItem = localStorage.getItem(`${d}_${loggedInUser.username}`);
@ -47,15 +46,13 @@ export function updateUserInfo(): Promise<[boolean, number]> {
localStorage.removeItem(d); localStorage.removeItem(d);
} }
}); });
return resolve([true, 200]); return [true, 200];
} }
pokerogueApi.account.getInfo().then(([accountInfo, status]) => {
const [accountInfo, status] = await pokerogueApi.account.getInfo();
if (!accountInfo) { if (!accountInfo) {
resolve([false, status]); return [false, status];
return;
} }
loggedInUser = accountInfo; loggedInUser = accountInfo;
resolve([true, 200]); return [true, 200];
});
});
} }

View File

@ -3,7 +3,7 @@ import { EFFECTIVE_STATS, getShortenedStatKey, Stat } from "#enums/stat";
import { TextStyle } from "#enums/text-style"; import { TextStyle } from "#enums/text-style";
import { UiTheme } from "#enums/ui-theme"; import { UiTheme } from "#enums/ui-theme";
import { getBBCodeFrag } from "#ui/text"; import { getBBCodeFrag } from "#ui/text";
import { toTitleCase } from "#utils/strings"; import { toCamelCase } from "#utils/strings";
import i18next from "i18next"; import i18next from "i18next";
export function getNatureName( export function getNatureName(
@ -13,7 +13,7 @@ export function getNatureName(
ignoreBBCode = false, ignoreBBCode = false,
uiTheme: UiTheme = UiTheme.DEFAULT, uiTheme: UiTheme = UiTheme.DEFAULT,
): string { ): string {
let ret = toTitleCase(Nature[nature]); let ret = toCamelCase(Nature[nature]);
//Translating nature //Translating nature
if (i18next.exists(`nature:${ret}`)) { if (i18next.exists(`nature:${ret}`)) {
ret = i18next.t(`nature:${ret}` as any); ret = i18next.t(`nature:${ret}` as any);

View File

@ -56,15 +56,15 @@ export class PokerogueSessionSavedataApi extends ApiBase {
/** /**
* Update a session savedata. * Update a session savedata.
* @param params The {@linkcode UpdateSessionSavedataRequest} to send * @param params - The request to send
* @param rawSavedata The raw savedata (as `string`) * @param rawSavedata - The raw, unencrypted savedata
* @returns An error message if something went wrong * @returns An error message if something went wrong
*/ */
public async update(params: UpdateSessionSavedataRequest, rawSavedata: string) { public async update(params: UpdateSessionSavedataRequest, rawSavedata: string): Promise<string> {
try { try {
const urlSearchParams = this.toUrlSearchParams(params); const urlSearchParams = this.toUrlSearchParams(params);
const response = await this.doPost(`/savedata/session/update?${urlSearchParams}`, rawSavedata);
const response = await this.doPost(`/savedata/session/update?${urlSearchParams}`, rawSavedata);
return await response.text(); return await response.text();
} catch (err) { } catch (err) {
console.warn("Could not update session savedata!", err); console.warn("Could not update session savedata!", err);

View File

@ -128,7 +128,8 @@ export interface SessionSaveData {
battleType: BattleType; battleType: BattleType;
trainer: TrainerData; trainer: TrainerData;
gameVersion: string; gameVersion: string;
runNameText: string; /** The player-chosen name of the run */
name: string;
timestamp: number; timestamp: number;
challenges: ChallengeData[]; challenges: ChallengeData[];
mysteryEncounterType: MysteryEncounterType | -1; // Only defined when current wave is ME, mysteryEncounterType: MysteryEncounterType | -1; // Only defined when current wave is ME,
@ -986,21 +987,21 @@ export class GameData {
} }
async renameSession(slotId: number, newName: string): Promise<boolean> { async renameSession(slotId: number, newName: string): Promise<boolean> {
return new Promise(async resolve => {
if (slotId < 0) { if (slotId < 0) {
return resolve(false); return false;
}
if (newName === "") {
return true;
} }
const sessionData: SessionSaveData | null = await this.getSession(slotId); const sessionData: SessionSaveData | null = await this.getSession(slotId);
if (!sessionData) { if (!sessionData) {
return resolve(false); return false;
} }
if (newName === "") { sessionData.name = newName;
return resolve(true); // update timestamp by 1 to ensure the session is saved
} sessionData.timestamp += 1;
sessionData.runNameText = newName;
const updatedDataStr = JSON.stringify(sessionData); const updatedDataStr = JSON.stringify(sessionData);
const encrypted = encrypt(updatedDataStr, bypassLogin); const encrypted = encrypt(updatedDataStr, bypassLogin);
const secretId = this.secretId; const secretId = this.secretId;
@ -1011,26 +1012,20 @@ export class GameData {
`sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`, `sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`,
encrypt(updatedDataStr, bypassLogin), encrypt(updatedDataStr, bypassLogin),
); );
resolve(true); return true;
return; }
const response = await pokerogueApi.savedata.session.update(
{ slot: slotId, trainerId, secretId, clientSessionId },
updatedDataStr,
);
if (response) {
return false;
} }
pokerogueApi.savedata.session
.update({ slot: slotId, trainerId, secretId, clientSessionId }, encrypted)
.then(error => {
if (error) {
console.error("Failed to update session name:", error);
resolve(false);
} else {
localStorage.setItem(`sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`, encrypted); localStorage.setItem(`sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`, encrypted);
updateUserInfo().then(success => { const success = await updateUserInfo();
if (success !== null && !success) { return !(success !== null && !success);
return resolve(false);
}
});
resolve(true);
}
});
});
} }
loadSession(slotId: number, sessionData?: SessionSaveData): Promise<boolean> { loadSession(slotId: number, sessionData?: SessionSaveData): Promise<boolean> {

View File

@ -208,7 +208,7 @@ export class RunInfoUiHandler extends UiHandler {
headerText.setOrigin(0, 0); headerText.setOrigin(0, 0);
headerText.setPositionRelative(headerBg, 8, 4); headerText.setPositionRelative(headerBg, 8, 4);
this.runContainer.add(headerText); this.runContainer.add(headerText);
const runName = addTextObject(0, 0, this.runInfo.runNameText, TextStyle.WINDOW); const runName = addTextObject(0, 0, this.runInfo.name, TextStyle.WINDOW);
runName.setOrigin(0, 0); runName.setOrigin(0, 0);
runName.setPositionRelative(headerBg, 60, 4); runName.setPositionRelative(headerBg, 60, 4);
this.runContainer.add(runName); this.runContainer.add(runName);

View File

@ -377,7 +377,7 @@ export class SaveSlotSelectUiHandler extends MessageUiHandler {
"select_cursor_highlight_thick", "select_cursor_highlight_thick",
undefined, undefined,
294, 294,
this.sessionSlots[prevSlotIndex ?? 0]?.saveData?.runNameText ? 50 : 60, this.sessionSlots[prevSlotIndex ?? 0]?.saveData?.name ? 50 : 60,
6, 6,
6, 6,
6, 6,
@ -553,10 +553,10 @@ class SessionSlot extends Phaser.GameObjects.Container {
} }
async setupWithData(data: SessionSaveData) { async setupWithData(data: SessionSaveData) {
const hasName = data?.runNameText; const hasName = data?.name;
this.remove(this.loadingLabel, true); this.remove(this.loadingLabel, true);
if (hasName) { if (hasName) {
const nameLabel = addTextObject(8, 5, data.runNameText, TextStyle.WINDOW); const nameLabel = addTextObject(8, 5, data.name, TextStyle.WINDOW);
this.add(nameLabel); this.add(nameLabel);
} else { } else {
const fallbackName = this.decideFallback(data); const fallbackName = this.decideFallback(data);

View File

@ -45,17 +45,17 @@ export function deepMergeSpriteData(dest: object, source: object) {
} }
export function encrypt(data: string, bypassLogin: boolean): string { export function encrypt(data: string, bypassLogin: boolean): string {
return (bypassLogin if (bypassLogin) {
? (data: string) => btoa(encodeURIComponent(data)) return btoa(encodeURIComponent(data));
: (data: string) => AES.encrypt(data, saveKey))(data) as unknown as string; // TODO: is this correct? }
return AES.encrypt(data, saveKey).toString();
} }
export function decrypt(data: string, bypassLogin: boolean): string { export function decrypt(data: string, bypassLogin: boolean): string {
return ( if (bypassLogin) {
bypassLogin return decodeURIComponent(atob(data));
? (data: string) => decodeURIComponent(atob(data)) }
: (data: string) => AES.decrypt(data, saveKey).toString(enc.Utf8) return AES.decrypt(data, saveKey).toString(enc.Utf8);
)(data);
} }
// the latest data saved/loaded for the Starter Preferences. Required to reduce read/writes. Initialize as "{}", since this is the default value and no data needs to be stored if present. // the latest data saved/loaded for the Starter Preferences. Required to reduce read/writes. Initialize as "{}", since this is the default value and no data needs to be stored if present.