fix(pages): load levels

This commit is contained in:
tiennm99 committed 2025-04-27 00:57:51 +07:00
1 parent 40fe7bc1b7
commit b7a38ce3da
9 files changed
+24 -7

No files matched your search

File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
View File
@@ -1,5 +1,6 @@
import Phaser from 'phaser';
import game from '../main.js';
import { getAssetPath } from '../utils/assetUtils.js';
class LevelScene extends Phaser.Scene {
constructor() {
+4 -3
View File
@@ -1,5 +1,6 @@
import Phaser from 'phaser';
import game from '../main.js';
import { getAssetPath } from '../utils/assetUtils.js';
class MainScene extends Phaser.Scene {
constructor() {
@@ -33,9 +34,9 @@ class MainScene extends Phaser.Scene {
preload() {
// Load level data
this.load.json('level1', 'public/assets/levels/level1.json');
this.load.json('level2', 'public/assets/levels/level2.json');
this.load.json('level3', 'public/assets/levels/level3.json');
this.load.json('level1', getAssetPath('assets/levels/level1.json'));
this.load.json('level2', getAssetPath('assets/levels/level2.json'));
this.load.json('level3', getAssetPath('assets/levels/level3.json'));
}
create() {
+3
View File
@@ -1,3 +1,6 @@
import Phaser from 'phaser';
import { getAssetPath } from '../utils/assetUtils.js';
class MenuScene extends Phaser.Scene {
constructor() {
super({ key: 'MenuScene' });
+12
View File
@@ -0,0 +1,12 @@
/**
* Utility function to get the correct asset path based on the environment
* This helps ensure assets load correctly both locally and on GitHub Pages
*
* @param {string} path - The relative path to the asset
* @returns {string} The correct path to use for loading the asset
*/
export function getAssetPath(path) {
// The path should be used as-is since Vite handles the base path
// during build based on the config.base setting
return path;
}
+1 -1
View File
@@ -1,7 +1,7 @@
import { defineConfig } from 'vite';
export default defineConfig({
base: './',
base: '/',
build: {
rollupOptions: {
output: {
+3 -3
View File
@@ -10,14 +10,14 @@ const phasermsg = () => {
const line = "---------------------------------------------------------";
const msg = `❤️❤️❤️ Tell us about your game! - games@phaser.io ❤️❤️❤️`;
process.stdout.write(`${line}\n${msg}\n${line}\n`);
process.stdout.write(`✨ Done ✨\n`);
}
}
}
}
export default defineConfig({
base: './',
base: '/sokoban/',
logLevel: 'warn',
build: {
rollupOptions: {