mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-21 19:28:03 +00:00
Import ApiClient in main game and use correct gameId path
- Import ApiClient in game.js to ensure window.ApiClient is set early - Use window.breakEscapeConfig?.gameId instead of window.gameId in minigames - Consistent with the rest of the codebase Without importing ApiClient in the main game flow, window.ApiClient wasn't available when minigames needed it.
This commit is contained in:
@@ -19,6 +19,7 @@ import { NPCHealthBars } from '../ui/npc-health-bars.js';
|
||||
import { GameOverScreen } from '../ui/game-over-screen.js';
|
||||
import { PlayerCombat } from '../systems/player-combat.js';
|
||||
import { NPCCombat } from '../systems/npc-combat.js';
|
||||
import { ApiClient } from '../api-client.js'; // Import to ensure window.ApiClient is set
|
||||
|
||||
// Global variables that will be set by main.js
|
||||
let gameScenario;
|
||||
|
||||
@@ -376,12 +376,13 @@ export class PasswordMinigame extends MinigameScene {
|
||||
}
|
||||
|
||||
async submitPassword() {
|
||||
const gameId = window.breakEscapeConfig?.gameId;
|
||||
console.log('submitPassword called', {
|
||||
isActive: this.gameState.isActive,
|
||||
correctPassword: this.correctPassword,
|
||||
hasApiClient: !!window.ApiClient,
|
||||
hasAPIClient: !!window.APIClient,
|
||||
gameId: window.gameId
|
||||
gameId: gameId
|
||||
});
|
||||
|
||||
if (!this.gameState.isActive) return;
|
||||
@@ -399,14 +400,14 @@ export class PasswordMinigame extends MinigameScene {
|
||||
|
||||
// Check if we need server-side validation (correctPassword is null or empty string)
|
||||
const apiClient = window.ApiClient || window.APIClient;
|
||||
if ((!this.correctPassword || this.correctPassword === '') && apiClient && window.gameId) {
|
||||
if ((!this.correctPassword || this.correctPassword === '') && apiClient && gameId) {
|
||||
console.log('Using server-side validation');
|
||||
await this.validatePasswordWithServer(enteredPassword);
|
||||
} else {
|
||||
console.log('Using client-side validation', {
|
||||
correctPassword: this.correctPassword,
|
||||
hasApiClient: !!apiClient,
|
||||
gameId: window.gameId
|
||||
gameId: gameId
|
||||
});
|
||||
// Client-side validation (backwards compatibility)
|
||||
if (enteredPassword === this.correctPassword) {
|
||||
|
||||
@@ -250,7 +250,8 @@ export class PinMinigame extends MinigameScene {
|
||||
// Check if we need server-side validation (correctPin is null or empty)
|
||||
let isCorrect;
|
||||
const apiClient = window.ApiClient || window.APIClient;
|
||||
if ((!this.correctPin || this.correctPin === '') && apiClient && window.gameId) {
|
||||
const gameId = window.breakEscapeConfig?.gameId;
|
||||
if ((!this.correctPin || this.correctPin === '') && apiClient && gameId) {
|
||||
console.log('Using server-side PIN validation');
|
||||
isCorrect = await this.validatePinWithServer(this.currentInput);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user