-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (184 loc) · 7.62 KB
/
wasm.yaml
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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