Compare commits

...

2 Commits

Author SHA1 Message Date
j 398465db02 Console Logged brief Info on Save State 2024-04-14 20:51:40 -04:00
j 51a9aa3ee6 Refined Restart Command Logic 2024-04-14 20:51:13 -04:00
3 changed files with 6 additions and 4 deletions

View File

@ -12,8 +12,6 @@ class GameFlow {
async executeCurrentPhase(userInput?: string) { async executeCurrentPhase(userInput?: string) {
this.cleanupGameState(); this.cleanupGameState();
if (userInput && userInput?.toLowerCase().indexOf('restart') >= 0) this.gameState = await this.gameState.reset();
switch (this.gameState.phase) { switch (this.gameState.phase) {
case PHASE_ENUM.SETUP: case PHASE_ENUM.SETUP:
// Handle the setup phase, e.g., initial purchases // Handle the setup phase, e.g., initial purchases
@ -129,7 +127,7 @@ class GameFlow {
switch (this.gameState.subPhase) { switch (this.gameState.subPhase) {
case 0: case 0:
// Weapons Purchase Subphase // Weapons Purchase Subphase
if (!userInput || userInput === 'start') { if (!userInput || userInput === 'start' || userInput === 'restart') {
// Send instructions to the user for the current subphase // Send instructions to the user for the current subphase
responseMessage = `${MessageService.getRandomMessage( responseMessage = `${MessageService.getRandomMessage(
MessageFileName.Oregon_WeaponPurchase, MessageFileName.Oregon_WeaponPurchase,

View File

@ -58,6 +58,7 @@ class GameState {
* Saves the current game state to the database. * Saves the current game state to the database.
*/ */
public async save() { public async save() {
console.log(`Saving game state to database... Phase: ${this.phase} SubPhase: ${this.subPhase} Cash: ${this.cashLeftAfterInitialPurchases}`);
await DatabaseService.saveGameState(this.authorId, this); await DatabaseService.saveGameState(this.authorId, this);
} }

View File

@ -14,7 +14,10 @@ class WorkflowOrchestrator {
try { try {
const parsedComment = CommentParser.parseCommand(comment) const parsedComment = CommentParser.parseCommand(comment)
if (parsedComment.command === "") return if (parsedComment.command === "") return
const gameState = await GameState.load(comment)
let gameState = await GameState.load(comment)
if (parsedComment.command === 'restart') gameState = await gameState.reset();
const gameFlow = new GameFlow(gameState) const gameFlow = new GameFlow(gameState)
await gameFlow.executeCurrentPhase(parsedComment.command) await gameFlow.executeCurrentPhase(parsedComment.command)
await gameState.save() await gameState.save()