summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2024-07-07 11:59:23 -0500
committersanine <sanine.not@pm.me>2024-07-07 11:59:23 -0500
commitf549c7e2fc520fff17ddfe868267c28ef91bf822 (patch)
treec38634aa0b5d3fff4a181684cca07d7fc0adb1ee
parenta4d923659f49ccd44e1d6bd09804ba658ca34ac4 (diff)
add sound controls and fullscreen
-rw-r--r--.gitignore2
-rw-r--r--index.html10
-rw-r--r--main.js91
-rw-r--r--mathjs/LICENSE.md9
-rw-r--r--render.js14
-rw-r--r--style.css37
6 files changed, 139 insertions, 24 deletions
diff --git a/.gitignore b/.gitignore
index 4709183..d3590e8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
# Godot 4+ specific ignores
.godot/
+*.swp
+*~
diff --git a/index.html b/index.html
index ccd16f1..efcf387 100644
--- a/index.html
+++ b/index.html
@@ -27,6 +27,14 @@
<audio preload="auto" id="sfx-listappear" src="sounds/sfx/gui-beep/33775__jobro__1-beep-a.wav"></audio>
<div id="root"></div>
- <div id="overlay"></div>
+ <!-- <div id="overlay"></div> -->
+ <div id="footer">
+ <a target="_blank" rel="noopener noreferrer"
+ href="./help.html">🛈 help</a>
+ <a id="sound-controls" href="#">♫ sounds</a>
+ <a target="_blank" rel="noopener noreferrer"
+ href="https://sanine.net/git/hyperspace-navigator/tree/?h=main">⌘ source code</a>
+ <a id="fullscreen-toggle" href="#">∷ toggle fullscreen</a>
+ </div>
</body>
</html>
diff --git a/main.js b/main.js
index 44a0fe3..94c3f31 100644
--- a/main.js
+++ b/main.js
@@ -27,6 +27,16 @@ window.onload = () => setTimeout(() => {
start.type = 'button';
start.value = 'connect to AMH';
start.onclick = () => {
+ // set up fullscreen
+ document.documentElement.requestFullscreen();
+ document.getElementById('fullscreen-toggle').onclick = () => {
+ if (document.fullscreenElement === null) {
+ document.documentElement.requestFullscreen();
+ } else {
+ document.exitFullscreen();
+ }
+ }
+
root.classList.remove('center');
root.innerText = '';
const audio = new AudioContext();
@@ -55,21 +65,22 @@ window.onload = () => setTimeout(() => {
musicList[0].element.play();
const sfx = {};
+ const sfxGain = audio.createGain();
sfx.buttonEnterAudio = document.getElementById('sfx-buttonenter');
sfx.buttonClickAudio = document.getElementById('sfx-buttonclick');
sfx.listAppearAudio = document.getElementById('sfx-listappear');
- audio.createMediaElementSource(sfx.buttonEnterAudio).connect(audio.destination);
- audio.createMediaElementSource(sfx.buttonClickAudio).connect(audio.destination);
- audio.createMediaElementSource(sfx.listAppearAudio).connect(audio.destination);
+ audio.createMediaElementSource(sfx.buttonEnterAudio).connect(sfxGain).connect(audio.destination);
+ audio.createMediaElementSource(sfx.buttonClickAudio).connect(sfxGain).connect(audio.destination);
+ audio.createMediaElementSource(sfx.listAppearAudio).connect(sfxGain).connect(audio.destination);
sfx.resourceAudio = document.getElementById('sfx-resource');
- audio.createMediaElementSource(sfx.resourceAudio).connect(audio.destination);
+ audio.createMediaElementSource(sfx.resourceAudio).connect(sfxGain).connect(audio.destination);
sfx.doneAudio = document.getElementById('sfx-done');
- audio.createMediaElementSource(sfx.doneAudio).connect(audio.destination);
+ audio.createMediaElementSource(sfx.doneAudio).connect(sfxGain).connect(audio.destination);
sfx.wrongAudio = document.getElementById('sfx-wrong');
- audio.createMediaElementSource(sfx.wrongAudio).connect(audio.destination);
+ audio.createMediaElementSource(sfx.wrongAudio).connect(sfxGain).connect(audio.destination);
// const level = setupLevel([[2, 2], [3,3]], [7, 7]);
// const ui = setupLevelUi(level, root, audio);
@@ -77,9 +88,71 @@ window.onload = () => setTimeout(() => {
Promise.all([...Object.values(sfx)].map(x => new Promise(resolve => {
x.load();
x.addEventListener('canplaythrough', resolve, false);
- }))).then(
- () => setupLevelSelectUi(root, sfx)
- );
+ }))).then(() => {
+ sfx.gain = sfxGain;
+ document.getElementById('sound-controls').onclick = () => showSoundControls(root, sfx, musicGain);
+ setupLevelSelectUi(root, sfx)
+ });
};
root.appendChild(start);
}, 200);
+
+
+function showSoundControls(root, sfx, musicGain) {
+ const div = document.createElement('div');
+ div.classList.add('center-screen-container');
+ const div2 = document.createElement('div');
+ div2.classList.add('center-screen');
+ div.appendChild(div2);
+ const p = document.createElement('p');
+ p.classList.add('alert-box');
+ p.innerText = 'sound settings';
+ div2.appendChild(p);
+ root.appendChild(div);
+
+ const musicLabel = document.createElement('label');
+ musicLabel.innerText = 'music:';
+ const musicRange = document.createElement('input');
+ musicRange.type = 'range';
+ musicRange.min = 0;
+ musicRange.max = 1;
+ musicRange.step = 0.1;
+ musicRange.value = 2*musicGain.gain.value;
+ musicRange.onchange = e => {
+ musicGain.gain.value = 0.5*e.target.value;
+ }
+ p.appendChild(document.createElement('br'));
+ p.appendChild(musicLabel);
+ p.appendChild(musicRange);
+
+ const sfxLabel = document.createElement('label');
+ sfxLabel.innerText = 'sfx:';
+ const sfxRange = document.createElement('input');
+ sfxRange.type = 'range';
+ sfxRange.min = 0;
+ sfxRange.max = 1;
+ sfxRange.step = 0.1;
+ sfxRange.value = sfx.gain.gain.value;
+ sfxRange.onchange = e => {
+ sfx.gain.gain.value = e.target.value;
+ }
+ p.appendChild(document.createElement('br'));
+ p.appendChild(sfxLabel);
+ p.appendChild(sfxRange);
+
+
+ const button = document.createElement('input');
+ button.type = 'button';
+ button.value = 'OK';
+ button.onmouseenter = () => {
+ sfx.buttonEnterAudio.currentTime = 0;
+ sfx.buttonEnterAudio.play();
+ }
+ button.onclick = () => {
+ sfx.buttonClickAudio.currentTime = 0;
+ sfx.buttonClickAudio.play();
+ root.removeChild(div);
+ }
+ p.appendChild(document.createElement('br'));
+ p.appendChild(button);
+}
diff --git a/mathjs/LICENSE.md b/mathjs/LICENSE.md
new file mode 100644
index 0000000..2163c09
--- /dev/null
+++ b/mathjs/LICENSE.md
@@ -0,0 +1,9 @@
+The MIT License
+
+Copyright (c) 2017 Jos de Jong
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/render.js b/render.js
index ce31973..66cf32c 100644
--- a/render.js
+++ b/render.js
@@ -1,5 +1,5 @@
export function render(ctx, level, index) {
- ctx.fillStyle = 'white';
+ ctx.fillStyle = 'orange';
const [x0, y0] = level.path[index];
const [x1, y1] = level.path[index+1] || level.path[index];
@@ -28,7 +28,7 @@ export function drawShip(ctx, pos, angle) {
const [x, y] = pos;
ctx.translate(x, y);
ctx.rotate(angle);
- ctx.fillStyle = 'white';
+ ctx.fillStyle = 'orange';
const STEP = 0.4;
ctx.beginPath();
ctx.moveTo(0, 0);
@@ -43,8 +43,8 @@ export function drawShip(ctx, pos, angle) {
export function drawGrid(ctx) {
ctx.scale(1, -1);
- ctx.strokeStyle = 'white';
- ctx.fillStyle = 'white';
+ ctx.strokeStyle = 'orange';
+ ctx.fillStyle = 'orange';
const { width, height } = ctx.canvas;
ctx.font = `0.4px monospace`;
ctx.lineWidth = 4 / Math.max(width, height);
@@ -83,7 +83,7 @@ export function drawGrid(ctx) {
export function drawPath(ctx, path) {
const [ start, ...line ] = path;
- ctx.strokeStyle = 'white';
+ ctx.strokeStyle = 'orange';
ctx.lineWidth = 0.04;
ctx.beginPath();
ctx.moveTo(start[0], start[1]);
@@ -93,8 +93,8 @@ export function drawPath(ctx, path) {
export function drawMark(ctx, mark, x, y) {
- ctx.strokeStyle = 'white';
- ctx.fillStyle = 'white';
+ ctx.strokeStyle = 'orange';
+ ctx.fillStyle = 'orange';
ctx.font = `0.5px monospace`;
ctx.lineWidth = 0.1;
diff --git a/style.css b/style.css
index 2b3b0fe..2b3b86e 100644
--- a/style.css
+++ b/style.css
@@ -1,9 +1,10 @@
body {
- color: white;
+ color: orange;
background-color: black;
font-family: "VT323", monospace;
position: relative;
overflow-x: hidden;
+ margin-bottom: 0;
}
.logo {
@@ -29,12 +30,34 @@ body {
font-family: "VT323", monospace;
width: min(90vw, 800px);
margin: auto;
- border-left: 1px solid white;
- border-right: 1px solid white;
+ border-left: 1px solid orange;
+ border-right: 1px solid orange;
padding: 8px;
min-height: 95vh;
}
+#footer {
+ position: sticky;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ border-top: 1px solid orange;
+ text-transform: uppercase;
+ font-family: "VT323", monospace;
+ font-size: 16px;
+ background-color: black;
+ color: orange;
+ margin: 0;
+ height: 32px;
+ overflow: hidden;
+ text-align: center;
+ padding-top: 8px;
+}
+
+#footer a {
+ color: orange;
+}
+
.center-screen-container {
position: absolute;
top: 0;
@@ -52,7 +75,7 @@ body {
}
.alert-box {
- border: 2px solid white;
+ border: 2px solid orange;
background-color: black;
padding: 16px;
max-width: min(80vw, 600px);
@@ -60,7 +83,7 @@ body {
}
.bordered {
- border: 2px solid white;
+ border: 2px solid orange;
}
h1 {
@@ -82,7 +105,7 @@ p {
input {
font-family: "VT323", monospace;
- color: white;
+ color: orange;
background-color: black;
font-size: 16px;
padding: 8px;
@@ -96,7 +119,7 @@ input[type=button] {
}
input[type=button]:hover {
color: black;
- background-color: white;
+ background-color: orange;
}
input[type=button]:active {
color: black;