-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebb.html
161 lines (144 loc) · 4.35 KB
/
webb.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>G 1</title>
<style>
body {
touch-action: none;
margin: 0;
padding: 0;
text-align: center;
background-color: black;
}
#canvas {
display: block;
margin: 0;
color: white;
}
#canvas:focus {
outline: none;
}
#status {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
visibility: hidden;
}
#status-progress {
width: 366px;
height: 7px;
background-color: #38363a;
border: 1px solid #444246;
box-shadow: 0 0 2px 1px #1b1c22;
border-radius: 2px;
visibility: visible;
}
#status-progress-inner {
height: 100%;
width: 0;
background-color: #202020;
box-shadow: 0 0 1px 1px #27282e;
border-radius: 3px;
transition: width 0.5s linear;
}
#status-notice {
margin: 0 100px;
line-height: 1.3;
visibility: visible;
padding: 4px 6px;
}
</style>
<link id="-gd-engine-icon" rel="icon" type="image/png" href="webg1.icon.png" />
<link rel="apple-touch-icon" href="webg1.apple-touch-icon.png" />
</head>
<body>
<canvas id="canvas">
HTML5 canvas appears to be unsupported in the current browser.<br />
Please try updating or use a different browser.
</canvas>
<div id="status">
<div id="status-progress" style="display: none;">
<div id="status-progress-inner"></div>
</div>
<div id="status-notice" class="godot" style="display: none;"></div>
</div>
<script src="webg1.js"></script>
<script>
const GODOT_CONFIG = {
args: [],
canvasResizePolicy: 2,
executable: "webg1",
fileSizes: { "webg1.pck": 2648784, "webg1.wasm": 49282035 },
focusCanvas: true,
};
const engine = new Engine(GODOT_CONFIG);
(function () {
const statusProgress = document.getElementById("status-progress");
const statusProgressInner = document.getElementById("status-progress-inner");
const statusNotice = document.getElementById("status-notice");
let initializing = true;
function setStatusMode(mode) {
[statusProgress, statusNotice].forEach((elem) => {
elem.style.display = "none";
});
if (mode === "progress") {
statusProgress.style.display = "block";
} else if (mode === "notice") {
statusNotice.style.display = "block";
}
}
function setStatusNotice(text) {
while (statusNotice.lastChild) {
statusNotice.removeChild(statusNotice.lastChild);
}
const lines = text.split("\n");
lines.forEach((line) => {
statusNotice.appendChild(document.createTextNode(line));
statusNotice.appendChild(document.createElement("br"));
});
}
function displayFailureNotice(err) {
const msg = err.message || err;
console.error(msg);
setStatusNotice(msg);
setStatusMode("notice");
initializing = false;
}
const missing = Engine.getMissingFeatures();
if (missing.length !== 0) {
displayFailureNotice(
"Error\nThe following features required to run Godot projects on the Web are missing:\n" +
missing.join("\n")
);
} else {
setStatusMode("progress");
engine
.startGame({
onProgress: function (current, total) {
if (total > 0) {
statusProgressInner.style.width = `${(current / total) * 100}%`;
if (current === total) {
setTimeout(() => {
setStatusMode("hidden");
}, 500);
}
}
},
})
.then(() => {
setStatusMode("hidden");
initializing = false;
})
.catch(displayFailureNotice);
}
})();
</script>
</body>
</html>