-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-pages-fix.js
More file actions
61 lines (54 loc) · 1.86 KB
/
github-pages-fix.js
File metadata and controls
61 lines (54 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// This is the fix for game.js
// Add this function at the beginning of your game.js file
// Function to get base URL for GitHub Pages
function getBaseUrl() {
// Check if we're on GitHub Pages
if (window.location.hostname.includes('github.io')) {
// Extract the repository name from the pathname
const pathParts = window.location.pathname.split('/');
if (pathParts.length > 1) {
const repoName = pathParts[1];
return `/${repoName}`;
}
}
// Return empty string for localhost
return '';
}
// Update path handling in loadScene function
function loadScene(sceneKey) {
const baseUrl = getBaseUrl();
const scene = scenes[sceneKey];
// Fix the background image path
const backgroundPath = scene.background.startsWith('./')
? baseUrl + scene.background.substring(1)
: baseUrl + scene.background;
// Rest of your loadScene code with the fixed path
const gameDiv = document.getElementById("game");
const sceneBackground = document.getElementById("scene-background");
// ... other variables
// Set background with fixed path
sceneBackground.style.backgroundImage = `url('${backgroundPath}')`;
// ... rest of the function
}
// Update all scene background paths in your scenes object
// For each scene in your scenes object:
Object.keys(scenes).forEach(key => {
// Ensure background paths use the correct format
if (scenes[key].background.startsWith('./assets/')) {
scenes[key].background = scenes[key].background.replace('./assets/', '/assets/');
}
});
// Also update the sw.js file to use relative paths:
// const CACHE_NAME = 'pope-game-cache-v1';
// const urlsToCache = [
// './',
// './index.html',
// './styles.css',
// './game.js',
// './sw.js',
// './favicon.ico',
// './assets/medieval_village.png',
// './assets/villager.png',
// './assets/plant_icon.png',
// './assets/question_mark.png'
// ];