Skip to content

Bump the actions-deps group across 1 directory with 4 updates (#6) #37

Bump the actions-deps group across 1 directory with 4 updates (#6)

Bump the actions-deps group across 1 directory with 4 updates (#6) #37

Workflow file for this run

name: Wasm
on:
push:
paths:
- "src/**"
- "Cargo.toml"
- ".github/workflows/wasm.yaml"
branches:
- main
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: true
env:
binary: mageanoid
use_git_lfs: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
lfs: ${{ env.use_git_lfs }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: install wasm-bindgen-cli
run: |
cargo install wasm-bindgen-cli
- name: Build
run: |
cargo build --release --target wasm32-unknown-unknown
- name: Prepare package
run: |
wasm-bindgen --no-typescript --out-name ${{env.binary}} --out-dir wasm --target web target/wasm32-unknown-unknown/release/${{ env.binary }}.wasm
cp -r assets wasm/ || true # Try to copy, but ignore if it can't copy if source directory does not exist
- name: Create static HTML and JS files
run: |
cat > wasm/index.html <<EOF
<!DOCTYPE html>
<html lang="en">
<head>
<title>${{env.binary}}</title>
<link rel="shortcut icon" href="https://bloodmagesoftware.github.io/${{env.binary}}/assets/icon.png" type="image/png">
<link rel="icon" href="https://bloodmagesoftware.github.io/${{env.binary}}/assets/icon.png" type="image/png">
<link rel="apple-touch-icon" href="https://bloodmagesoftware.github.io/${{env.binary}}/assets/icon.png" type="image/png">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta rel="canonical" href="https://bloodmagesoftware.github.io/${{env.binary}}">
<meta name="darkreader-lock">
<meta name="generator" content="Bevy">
<meta name="description" content="Bloodmage Software :: Where the magic of gaming lives on">
<meta rel="icon" href="https://bloodmagesoftware.github.io/${{env.binary}}/assets/icon.png">
<!-- Open Graph / Facebook -->
<meta property="og:title" content="${{env.binary}}">
<meta property="og:description" content="Bloodmage Software :: Where the magic of gaming lives on">
<meta property="og:image" content="https://bloodmagesoftware.github.io/${{env.binary}}/assets/icon.png">
<meta property="og:url" content="https://bloodmagesoftware.github.io/${{env.binary}}">
<meta property="og:type" content="website">
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="${{env.binary}}">
<meta name="twitter:description" content="Bloodmage Software :: Where the magic of gaming lives on">
<meta name="twitter:image" content="https://bloodmagesoftware.github.io/${{env.binary}}/assets/icon.png">
<meta name="twitter:url" content="https://bloodmagesoftware.github.io/${{env.binary}}">
</head>
<body>
<span
onclick="document.querySelector('canvas').requestFullscreen()"
class="fullscreen"
>
<img
src="https://icons.getbootstrap.com/assets/icons/arrows-fullscreen.svg"
height="32"
alt="Fullscreen"
>
</span>
<script type="module">
import "./restart-audio-context.js";
import init from "./${{env.binary}}.js";
init().catch((error) => {
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
throw error;
}
});
</script>
<style>
:root, body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #000;
}
canvas {
margin: auto;
display: block;
position: relative;
width: 100dvw !important;
height: 100dvh !important;
min-width: unset !important;
min-height: unset !important;
outline: none;
}
.fullscreen {
cursor: pointer;
background-color: #fff4;
backdrop-filter: blur(4px);
padding: 8px;
border-radius: 8px;
position: fixed;
top: 8px;
right: 8px;
z-index: 1000;
width: 48px;
height: 48px;
}
.fullscreen:hover {
background-color: #fff8;
}
* {
user-select: none;
box-sizing: border-box;
margin: 0;
padding: 0;
}
</style>
</body>
</html>
EOF
cat > wasm/restart-audio-context.js <<EOF
// taken from https://developer.chrome.com/blog/web-audio-autoplay/#moving-forward
(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
if (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);
});
})();
EOF
- name: Upload binaries to artifacts
uses: actions/[email protected]
with:
path: ./wasm
retention-days: 1
name: github-pages
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4