Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added customized HTML shell for web exports #60

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 232 additions & 0 deletions p0ng/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
<title>$GODOT_PROJECT_NAME</title>
<style>
html, body, #canvas {
margin: 0;
padding: 0;
border: 0;
}

body {
color: white;
background-color: black;
overflow: hidden;
touch-action: none;
}

progress[value] {
appearance: none;
border: none;

width: 100%; height: 6px;

background-color: #180c21;
border-radius: 0px;
box-shadow: 0 2px 3px rgba(0, 0, 0, .5) inset;

color: #6f324e;
accent-color: #6f324e;

position: relative;
margin: 0 0 1.5em;
}

progress[value]::-webkit-progress-bar {
background-color: #180c21;
border-radius: 0px;
box-shadow: 0 2px 3px rgba(0, 0, 0, .5) inset;
}

progress[value]::-webkit-progress-value {
position: relative;
background-color: #6f324e;
background-size: 35px 6px, 100% 100%, 100% 100%;
border-radius: 0;
}

progress[value]::-moz-progress-bar {
background-color: #6f324e;
background-size: 35px 6px, 100% 100%, 100% 100%;
border-radius: 0;
}

#canvas {
display: block;
}

#canvas:focus {
outline: none;
}

#status, #status-splash, #status-progress {
position: absolute;
left: 0;
right: 0;
}

#status, #status-splash {
top: 0;
bottom: 0;
}

#status {
background-color: #242424;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
visibility: hidden;
}

#status-splash {
max-height: 100%;
max-width: 100%;
margin: auto;
}

#status-progress, #status-notice {
display: none;
}

#status-progress {
bottom: 10%;
width: 50%;
margin: 0 auto;
}

#status-notice {
background-color: #5b3943;
border-radius: 0.5rem;
border: 1px solid #9b3943;
color: #e0e0e0;
font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
line-height: 1.3;
margin: 0 2rem;
overflow: hidden;
padding: 1rem;
text-align: center;
z-index: 1;
}
</style>
$GODOT_HEAD_INCLUDE
</head>
<body>
<canvas id="canvas">
Your browser does not support the canvas tag.
</canvas>

<noscript>
Your browser does not support JavaScript.
</noscript>

<div id="status">
<img id="status-splash" src="$GODOT_SPLASH" alt="">
<progress id="status-progress"></progress>
<div id="status-notice"></div>
</div>

<script src="$GODOT_URL"></script>
<script>
const GODOT_CONFIG = $GODOT_CONFIG;
const GODOT_THREADS_ENABLED = $GODOT_THREADS_ENABLED;
const engine = new Engine(GODOT_CONFIG);

(function () {
const statusOverlay = document.getElementById('status');
const statusProgress = document.getElementById('status-progress');
const statusNotice = document.getElementById('status-notice');

let initializing = true;
let statusMode = '';

function setStatusMode(mode) {
if (statusMode === mode || !initializing) {
return;
}
if (mode === 'hidden') {
statusOverlay.remove();
initializing = false;
return;
}
statusOverlay.style.visibility = 'visible';
statusProgress.style.display = mode === 'progress' ? 'block' : 'none';
statusNotice.style.display = mode === 'notice' ? 'block' : 'none';
statusMode = mode;
}

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) {
console.error(err);
if (err instanceof Error) {
setStatusNotice(err.message);
} else if (typeof err === 'string') {
setStatusNotice(err);
} else {
setStatusNotice('An unknown error occured');
}
setStatusMode('notice');
initializing = false;
}

const missing = Engine.getMissingFeatures({
threads: GODOT_THREADS_ENABLED,
});

if (missing.length !== 0) {
if (GODOT_CONFIG['serviceWorker'] && GODOT_CONFIG['ensureCrossOriginIsolationHeaders'] && 'serviceWorker' in navigator) {
// There's a chance that installing the service worker would fix the issue
Promise.race([
navigator.serviceWorker.getRegistration().then((registration) => {
if (registration != null) {
return Promise.reject(new Error('Service worker already exists.'));
}
return registration;
}).then(() => engine.installServiceWorker()),
// For some reason, `getRegistration()` can stall
new Promise((resolve) => {
setTimeout(() => resolve(), 2000);
}),
]).catch((err) => {
console.error('Error while registering service worker:', err);
}).then(() => {
window.location.reload();
});
} else {
// Display the message as usual
const missingMsg = 'Error\nThe following features required to run Godot projects on the Web are missing:\n';
displayFailureNotice(missingMsg + missing.join('\n'));
}
} else {
setStatusMode('progress');
engine.startGame({
'onProgress': function (current, total) {
if (current > 0 && total > 0) {
statusProgress.value = current;
statusProgress.max = total;
} else {
statusProgress.removeAttribute('value');
statusProgress.removeAttribute('max');
}
},
}).then(() => {
setStatusMode('hidden');
}, displayFailureNotice);
}
}());
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion p0ng/export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ variant/thread_support=false
vram_texture_compression/for_desktop=true
vram_texture_compression/for_mobile=false
html/export_icon=true
html/custom_html_shell=""
html/custom_html_shell="res://dist/index.html"
html/head_include=""
html/canvas_resize_policy=2
html/focus_canvas_on_start=true
Expand Down
3 changes: 2 additions & 1 deletion p0ng/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ config_version=5
[application]

config/name="p0ng"
config/version="2.0.2"
config/version="2.0.3"
run/main_scene="res://scenes/main.tscn"
config/use_custom_user_dir=true
config/custom_user_dir_name="ambientlamp/p0ng"
Expand Down Expand Up @@ -49,6 +49,7 @@ enabled=PackedStringArray("res://addons/AsepriteWizard/plugin.cfg")

folder_colors={
"res://assets/": "red",
"res://dist/": "orange",
"res://scenes/": "purple",
"res://scripts/": "blue"
}
Expand Down
Loading