Commit 59d32ebf authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: move all game init inside DOMContentLoaded to fix local mode

External scripts load after inline code; LudoConstants was referenced
before its script tag was parsed in local mode.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 1dcfdbc8
...@@ -29,7 +29,7 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js ...@@ -29,7 +29,7 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js
</div> </div>
<script> <script>
(function() { document.addEventListener('DOMContentLoaded', function() {
var params = new URLSearchParams(window.location.search); var params = new URLSearchParams(window.location.search);
var mode = params.get('mode') || 'local'; var mode = params.get('mode') || 'local';
var playerCount = parseInt(params.get('players') || '4', 10); var playerCount = parseInt(params.get('players') || '4', 10);
...@@ -56,12 +56,11 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js ...@@ -56,12 +56,11 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js
activePlayers = allPlayers.slice(0, playerCount); activePlayers = allPlayers.slice(0, playerCount);
bots = {}; bots = {};
playerNames = {}; playerNames = {};
activePlayers.forEach(function(p, idx) { activePlayers.forEach(function(p) {
playerNames[p] = LudoConstants.PLAYER_LABELS[p]; playerNames[p] = LudoConstants.PLAYER_LABELS[p];
}); });
} }
document.addEventListener('DOMContentLoaded', function() {
LudoUI.renderBoard('#ludo-board'); LudoUI.renderBoard('#ludo-board');
var isMobile = window.innerWidth < 768; var isMobile = window.innerWidth < 768;
...@@ -93,15 +92,13 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js ...@@ -93,15 +92,13 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js
mode: mode, mode: mode,
bots: bots, bots: bots,
difficulty: difficulty, difficulty: difficulty,
playerNames: playerNames, playerNames: playerNames
onGameEnd: arguments.callee
}); });
}); });
} }
} }
}); });
}); });
})();
</script> </script>
<?php require __DIR__ . '/../includes/footer.php'; ?> <?php require __DIR__ . '/../includes/footer.php'; ?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment