mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-06-21 17:12:44 +02:00
Implemented Default Name Logic
Altered logic in save-slot-select-ui-handler.ts to support default naming of runs based on the run game mode with decideFallback function. In game-data.ts, to prevent inconsistent naming, added check for unfilled input, ignoring empty rename requests. Signed-off-by: Matheus Alves matheus.r.noya.alves@tecnico.ulisboa.pt Co-authored-by: Inês Simões ines.p.simoes@tecnico.ulisboa.pt
This commit is contained in:
parent
de66b9a4f1
commit
d3f47f0824
@ -990,6 +990,10 @@ export class GameData {
|
|||||||
return resolve(false);
|
return resolve(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newName === "") {
|
||||||
|
return resolve(true);
|
||||||
|
}
|
||||||
|
|
||||||
sessionData.runNameText = newName;
|
sessionData.runNameText = newName;
|
||||||
const updatedDataStr = JSON.stringify(sessionData);
|
const updatedDataStr = JSON.stringify(sessionData);
|
||||||
const encrypted = encrypt(updatedDataStr, bypassLogin);
|
const encrypted = encrypt(updatedDataStr, bypassLogin);
|
||||||
@ -997,7 +1001,9 @@ export class GameData {
|
|||||||
const trainerId = this.trainerId;
|
const trainerId = this.trainerId;
|
||||||
|
|
||||||
if (!bypassLogin) {
|
if (!bypassLogin) {
|
||||||
pokerogueApi.savedata.session.update({ slot: slotId, trainerId, secretId, clientSessionId },encrypted).then(error => {
|
pokerogueApi.savedata.session
|
||||||
|
.update({ slot: slotId, trainerId, secretId, clientSessionId }, encrypted)
|
||||||
|
.then(error => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("Failed to update session name:", error);
|
console.error("Failed to update session name:", error);
|
||||||
resolve(false);
|
resolve(false);
|
||||||
@ -1006,7 +1012,8 @@ export class GameData {
|
|||||||
updateUserInfo().then(success => {
|
updateUserInfo().then(success => {
|
||||||
if (success !== null && !success) {
|
if (success !== null && !success) {
|
||||||
return resolve(false);
|
return resolve(false);
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
resolve(true);
|
resolve(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -13,6 +13,7 @@ import { TextStyle, addTextObject } from "./text";
|
|||||||
import { UiMode } from "#enums/ui-mode";
|
import { UiMode } from "#enums/ui-mode";
|
||||||
import { addWindow } from "./ui-theme";
|
import { addWindow } from "./ui-theme";
|
||||||
import { RunDisplayMode } from "#app/ui/run-info-ui-handler";
|
import { RunDisplayMode } from "#app/ui/run-info-ui-handler";
|
||||||
|
import { GameModes } from "#enums/game-modes";
|
||||||
|
|
||||||
const SESSION_SLOTS_COUNT = 5;
|
const SESSION_SLOTS_COUNT = 5;
|
||||||
const SLOTS_ON_SCREEN = 2;
|
const SLOTS_ON_SCREEN = 2;
|
||||||
@ -385,7 +386,6 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
|
|||||||
this.sessionSlotsContainer.add(this.cursorObj);
|
this.sessionSlotsContainer.add(this.cursorObj);
|
||||||
}
|
}
|
||||||
const cursorPosition = cursor + this.scrollCursor;
|
const cursorPosition = cursor + this.scrollCursor;
|
||||||
const valueHeight = this.sessionSlots[prevSlotIndex ?? 0]?.saveData?.runNameText ? 76 : 76;
|
|
||||||
const cursorIncrement = cursorPosition * 76;
|
const cursorIncrement = cursorPosition * 76;
|
||||||
if (this.sessionSlots[cursorPosition] && this.cursorObj) {
|
if (this.sessionSlots[cursorPosition] && this.cursorObj) {
|
||||||
const hasData = this.sessionSlots[cursorPosition].hasData;
|
const hasData = this.sessionSlots[cursorPosition].hasData;
|
||||||
@ -413,7 +413,7 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
|
|||||||
revertSessionSlot(slotIndex: number): void {
|
revertSessionSlot(slotIndex: number): void {
|
||||||
const sessionSlot = this.sessionSlots[slotIndex];
|
const sessionSlot = this.sessionSlots[slotIndex];
|
||||||
if (sessionSlot) {
|
if (sessionSlot) {
|
||||||
const valueHeight = sessionSlot.saveData?.runNameText ? 76 : 76;
|
const valueHeight = 76;
|
||||||
sessionSlot.setPosition(0, slotIndex * valueHeight);
|
sessionSlot.setPosition(0, slotIndex * valueHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -498,34 +498,55 @@ class SessionSlot extends Phaser.GameObjects.Container {
|
|||||||
this.add(this.loadingLabel);
|
this.add(this.loadingLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
decideFallback(data: SessionSaveData) {
|
||||||
|
let fallbackName;
|
||||||
|
switch (data.gameMode) {
|
||||||
|
case GameModes.CLASSIC:
|
||||||
|
fallbackName = `${GameMode.getModeName(data.gameMode)} (${globalScene.gameData.gameStats.classicSessionsPlayed + 1})`;
|
||||||
|
break;
|
||||||
|
case GameModes.ENDLESS:
|
||||||
|
case GameModes.SPLICED_ENDLESS:
|
||||||
|
fallbackName = `${GameMode.getModeName(data.gameMode)} (${globalScene.gameData.gameStats.endlessSessionsPlayed + 1})`;
|
||||||
|
break;
|
||||||
|
case GameModes.DAILY:
|
||||||
|
const runDay = new Date(data.timestamp).toLocaleDateString();
|
||||||
|
fallbackName = `${GameMode.getModeName(data.gameMode)} (${runDay})`;
|
||||||
|
break;
|
||||||
|
case GameModes.CHALLENGE:
|
||||||
|
fallbackName = `${GameMode.getModeName(data.gameMode)}`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return fallbackName;
|
||||||
|
}
|
||||||
|
|
||||||
async setupWithData(data: SessionSaveData) {
|
async setupWithData(data: SessionSaveData) {
|
||||||
const hasName = data?.runNameText;
|
const hasName = data?.runNameText;
|
||||||
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.runNameText, TextStyle.WINDOW);
|
||||||
this.add(nameLabel);
|
this.add(nameLabel);
|
||||||
|
} else {
|
||||||
|
const fallbackName = this.decideFallback(data);
|
||||||
|
await globalScene.gameData.renameSession(this.slotId, fallbackName);
|
||||||
|
const nameLabel = addTextObject(8, 5, fallbackName, TextStyle.WINDOW);
|
||||||
|
this.add(nameLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
const gameModeLabel = addTextObject(
|
const gameModeLabel = addTextObject(
|
||||||
8,
|
8,
|
||||||
hasName ? 19 : 12,
|
19,
|
||||||
`${GameMode.getModeName(data.gameMode) || i18next.t("gameMode:unkown")} - ${i18next.t("saveSlotSelectUiHandler:wave")} ${data.waveIndex}`,
|
`${GameMode.getModeName(data.gameMode) || i18next.t("gameMode:unkown")} - ${i18next.t("saveSlotSelectUiHandler:wave")} ${data.waveIndex}`,
|
||||||
TextStyle.WINDOW,
|
TextStyle.WINDOW,
|
||||||
);
|
);
|
||||||
this.add(gameModeLabel);
|
this.add(gameModeLabel);
|
||||||
|
|
||||||
const timestampLabel = addTextObject(
|
const timestampLabel = addTextObject(8, 33, new Date(data.timestamp).toLocaleString(), TextStyle.WINDOW);
|
||||||
8,
|
|
||||||
hasName ? 33 : 26,
|
|
||||||
new Date(data.timestamp).toLocaleString(),
|
|
||||||
TextStyle.WINDOW,
|
|
||||||
);
|
|
||||||
this.add(timestampLabel);
|
this.add(timestampLabel);
|
||||||
|
|
||||||
const playTimeLabel = addTextObject(8, hasName ? 47 : 40, getPlayTimeString(data.playTime), TextStyle.WINDOW);
|
const playTimeLabel = addTextObject(8, 47, getPlayTimeString(data.playTime), TextStyle.WINDOW);
|
||||||
this.add(playTimeLabel);
|
this.add(playTimeLabel);
|
||||||
|
|
||||||
const pokemonIconsContainer = globalScene.add.container(144, hasName ? 16 : 9);
|
const pokemonIconsContainer = globalScene.add.container(144, 16);
|
||||||
data.party.forEach((p: PokemonData, i: number) => {
|
data.party.forEach((p: PokemonData, i: number) => {
|
||||||
const iconContainer = globalScene.add.container(26 * i, 0);
|
const iconContainer = globalScene.add.container(26 * i, 0);
|
||||||
iconContainer.setScale(0.75);
|
iconContainer.setScale(0.75);
|
||||||
|
Loading…
Reference in New Issue
Block a user