mirror of
https://github.com/tiennm99/sokoban.git
synced 2026-10-14 06:18:03 +00:00
fix(pages): load levels
This commit is contained in:
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,5 +1,6 @@
|
||||
import Phaser from 'phaser';
|
||||
import game from '../main.js';
|
||||
import { getAssetPath } from '../utils/assetUtils.js';
|
||||
|
||||
class LevelScene extends Phaser.Scene {
|
||||
constructor() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import Phaser from 'phaser';
|
||||
import { getAssetPath } from '../utils/assetUtils.js';
|
||||
|
||||
class MenuScene extends Phaser.Scene {
|
||||
constructor() {
|
||||
super({ key: 'MenuScene' });
|
||||
|
||||
@@ -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
@@ -1,7 +1,7 @@
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
export default defineConfig({
|
||||
base: './',
|
||||
base: '/',
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in new issue
Block a user