forked from NiklasEi/bevy_game_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
106 additions
and
150 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ target/ | |
.idea/ | ||
.DS_Store | ||
|
||
build/web/ | ||
dist/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Insert hack to make sound autoplay on Chrome as soon as the user interacts with the tab: | ||
// https://developers.google.com/web/updates/2018/11/web-audio-autoplay#moving-forward | ||
|
||
// the following function keeps track of all AudioContexts and resumes them on the first user | ||
// interaction with the page. If the function is called and all contexts are already running, | ||
// it will remove itself from all event listeners. | ||
(function () { | ||
// An array of all contexts to resume on the page | ||
const audioContextList = []; | ||
|
||
// An array of various user interaction events we should listen for | ||
const userInputEventNames = [ | ||
"click", | ||
"contextmenu", | ||
"auxclick", | ||
"dblclick", | ||
"mousedown", | ||
"mouseup", | ||
"pointerup", | ||
"touchend", | ||
"keydown", | ||
"keyup", | ||
]; | ||
|
||
// A proxy object to intercept AudioContexts and | ||
// add them to the array for tracking and resuming later | ||
self.AudioContext = new Proxy(self.AudioContext, { | ||
construct(target, args) { | ||
const result = new target(...args); | ||
audioContextList.push(result); | ||
return result; | ||
}, | ||
}); | ||
|
||
// To resume all AudioContexts being tracked | ||
function resumeAllContexts(_event) { | ||
let count = 0; | ||
|
||
audioContextList.forEach((context) => { | ||
if (context.state !== "running") { | ||
context.resume(); | ||
} else { | ||
count++; | ||
} | ||
}); | ||
|
||
// If all the AudioContexts have now resumed then we unbind all | ||
// the event listeners from the page to prevent unnecessary resume attempts | ||
// Checking count > 0 ensures that the user interaction happens AFTER the game started up | ||
if (count > 0 && count === audioContextList.length) { | ||
userInputEventNames.forEach((eventName) => { | ||
document.removeEventListener(eventName, resumeAllContexts); | ||
}); | ||
} | ||
} | ||
|
||
// We bind the resume function for each user interaction | ||
// event on the page | ||
userInputEventNames.forEach((eventName) => { | ||
document.addEventListener(eventName, resumeAllContexts); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
body { | ||
background: linear-gradient( | ||
135deg, | ||
white 0%, | ||
white 49%, | ||
black 49%, | ||
black 51%, | ||
white 51%, | ||
white 100% | ||
) repeat; | ||
background-size: 20px 20px; | ||
margin: 0; | ||
} | ||
canvas { | ||
background-color: white; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<style> | ||
body { | ||
background: linear-gradient( | ||
135deg, | ||
white 0%, | ||
white 49%, | ||
black 49%, | ||
black 51%, | ||
white 51%, | ||
white 100% | ||
) repeat; | ||
background-size: 20px 20px; | ||
margin: 0; | ||
} | ||
canvas { | ||
background-color: white; | ||
} | ||
</style> | ||
<title>Bevy game</title> <!-- ToDo --> | ||
</head> | ||
<body> | ||
<script> | ||
// Insert hack to make sound autoplay on Chrome as soon as the user interacts with the tab: | ||
// https://developers.google.com/web/updates/2018/11/web-audio-autoplay#moving-forward | ||
|
||
// the following function keeps track of all AudioContexts and resumes them on the first user | ||
// interaction with the page. If the function is called and all contexts are already running, | ||
// it will remove itself from all event listeners. | ||
(function () { | ||
// An array of all contexts to resume on the page | ||
const audioContextList = []; | ||
|
||
// An array of various user interaction events we should listen for | ||
const userInputEventNames = [ | ||
"click", | ||
"contextmenu", | ||
"auxclick", | ||
"dblclick", | ||
"mousedown", | ||
"mouseup", | ||
"pointerup", | ||
"touchend", | ||
"keydown", | ||
"keyup", | ||
]; | ||
|
||
// A proxy object to intercept AudioContexts and | ||
// add them to the array for tracking and resuming later | ||
self.AudioContext = new Proxy(self.AudioContext, { | ||
construct(target, args) { | ||
const result = new target(...args); | ||
audioContextList.push(result); | ||
return result; | ||
}, | ||
}); | ||
|
||
// To resume all AudioContexts being tracked | ||
function resumeAllContexts(_event) { | ||
let count = 0; | ||
|
||
audioContextList.forEach((context) => { | ||
if (context.state !== "running") { | ||
context.resume(); | ||
} else { | ||
count++; | ||
} | ||
}); | ||
|
||
// If all the AudioContexts have now resumed then we unbind all | ||
// the event listeners from the page to prevent unnecessary resume attempts | ||
// Checking count > 0 ensures that the user interaction happens AFTER the game started up | ||
if (count > 0 && count === audioContextList.length) { | ||
userInputEventNames.forEach((eventName) => { | ||
document.removeEventListener(eventName, resumeAllContexts); | ||
}); | ||
} | ||
} | ||
|
||
// We bind the resume function for each user interaction | ||
// event on the page | ||
userInputEventNames.forEach((eventName) => { | ||
document.addEventListener(eventName, resumeAllContexts); | ||
}); | ||
})(); | ||
</script> | ||
<script type="module"> | ||
// load the actual game | ||
import init from './target/wasm.js' | ||
init(); | ||
</script> | ||
</body> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<title>Bevy game</title> <!-- ToDo --> | ||
<link data-trunk rel="copy-dir" href="assets"/> | ||
<link data-trunk rel="copy-dir" href="credits"/> | ||
<link data-trunk rel="copy-file" href="build/windows/icon.ico"/> | ||
<link rel="icon" href="icon.ico"> | ||
<link data-trunk rel="inline" href="build/web/styles.css"/> | ||
</head> | ||
<body> | ||
<link data-trunk rel="inline" href="build/web/sound.js"/> | ||
</body> | ||
</html> |