Changes for how play time is handled

This commit is contained in:
Flashfyre 2024-01-11 20:27:50 -05:00
parent f9c3023e6d
commit 4c07c6d5cb
5 changed files with 41 additions and 25 deletions

View File

@ -363,9 +363,8 @@ export class EncounterPhase extends BattlePhase {
start() {
super.start();
this.scene.updateWaveCountText();
this.scene.updateMoneyText();
this.scene.initSession();
const loadEnemyAssets = [];
const battle = this.scene.currentBattle;

View File

@ -84,6 +84,7 @@ export default class BattleScene extends Phaser.Scene {
public rexUI: UIPlugin;
public auto: boolean;
public sessionPlayTime: integer = null;
public masterVolume: number = 0.5;
public bgmVolume: number = 1;
public seVolume: number = 1;
@ -141,6 +142,7 @@ export default class BattleScene extends Phaser.Scene {
private bgm: AnySound;
private bgmResumeTimer: Phaser.Time.TimerEvent;
private bgmCache: Set<string> = new Set();
private playTimeTimer: Phaser.Time.TimerEvent;
private buttonKeys: Phaser.Input.Keyboard.Key[][];
@ -402,15 +404,6 @@ export default class BattleScene extends Phaser.Scene {
this.gameData = new GameData(this);
this.time.addEvent({
delay: Utils.fixedInt(1000),
repeat: -1,
callback: () => {
if (this.gameData)
this.gameData.gameStats.playTime++;
}
})
this.setupControls();
this.load.setBaseURL();
@ -578,6 +571,27 @@ export default class BattleScene extends Phaser.Scene {
});
}
initSession(): void {
this.sessionPlayTime = 0;
if (this.playTimeTimer)
this.playTimeTimer.destroy();
this.playTimeTimer = this.time.addEvent({
delay: Utils.fixedInt(1000),
repeat: -1,
callback: () => {
if (this.gameData)
this.gameData.gameStats.playTime++;
if (this.sessionPlayTime !== null)
this.sessionPlayTime++;
}
});
this.updateWaveCountText();
this.updateMoneyText();
}
setupControls() {
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
const keyConfig = {

View File

@ -58,6 +58,7 @@ interface SystemSaveData {
interface SessionSaveData {
seed: string;
playTime: integer;
gameMode: GameMode;
party: PokemonData[];
enemyParty: PokemonData[];
@ -360,6 +361,7 @@ export class GameData {
const sessionData = {
seed: scene.seed,
playTime: scene.sessionPlayTime,
gameMode: scene.gameMode,
party: scene.getParty().map(p => new PokemonData(p)),
enemyParty: scene.getEnemyParty().map(p => new PokemonData(p)),
@ -408,6 +410,8 @@ export class GameData {
scene.seed = sessionData.seed || scene.game.config.seed[0];
scene.resetSeed();
scene.sessionPlayTime = sessionData.playTime || 0;
scene.gameMode = sessionData.gameMode || GameMode.CLASSIC;
const loadPokemonAssets: Promise<void>[] = [];

View File

@ -1,5 +1,4 @@
import BattleScene, { Button } from "../battle-scene";
import { GameStats } from "../system/game-stats";
import { TextStyle, addTextObject, getTextColor } from "./text";
import { Mode } from "./ui";
import UiHandler from "./ui-handler";
@ -18,20 +17,9 @@ interface DisplayStats {
[key: string]: DisplayStat | string
}
const secondsInHour = 3600;
const displayStats: DisplayStats = {
playTime: {
sourceFunc: gameData => {
const totalSeconds = gameData.gameStats.playTime;
const days = `${Math.floor(totalSeconds / (secondsInHour * 24))}`;
const hours = `${Math.floor(totalSeconds % (secondsInHour * 24) / secondsInHour)}`;
const minutes = `${Math.floor(totalSeconds % secondsInHour / 60)}`;
const seconds = `${Math.floor(totalSeconds % 60)}`;
return `${days.padStart(2, '0')}:${hours.padStart(2, '0')}:${minutes.padStart(2, '0')}:${seconds.padStart(2, '0')}`;
}
sourceFunc: gameData => Utils.getPlayTimeString(gameData.gameStats.playTime)
},
battles: 'Total Battles',
startersUnlocked: {

View File

@ -88,6 +88,17 @@ export function getCurrentTime(): number {
return (((date.getHours() * 60 + date.getMinutes()) / 1440) + 0.675) % 1;
}
const secondsInHour = 3600;
export function getPlayTimeString(totalSeconds: integer): string {
const days = `${Math.floor(totalSeconds / (secondsInHour * 24))}`;
const hours = `${Math.floor(totalSeconds % (secondsInHour * 24) / secondsInHour)}`;
const minutes = `${Math.floor(totalSeconds % secondsInHour / 60)}`;
const seconds = `${Math.floor(totalSeconds % 60)}`;
return `${days.padStart(2, '0')}:${hours.padStart(2, '0')}:${minutes.padStart(2, '0')}:${seconds.padStart(2, '0')}`;
}
export function binToDec(input: string): integer {
let place: integer[] = [];
let binary: string[] = [];