Skip to content

Commit 40c22da

Browse files
committed
update showcase
1 parent 824a750 commit 40c22da

File tree

3 files changed

+25
-96
lines changed

3 files changed

+25
-96
lines changed

src/demo.html

Lines changed: 14 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,23 @@ <h2 id="demo-id"> </h2>
55
You can download the native app for your platform, or try the web version below.
66
</p>
77
<nav>
8-
<a id="dl" href="https://github.com/NostrGameEngine"><ion-icon name="download-outline"></ion-icon>Download and Install</a>
8+
<a id="dl" href="https://github.com/NostrGameEngine"><ion-icon name="download-outline"></ion-icon>Download Native Build</a>
99
<a id="src" href="https://github.com/NostrGameEngine"><ion-icon name="logo-github"></ion-icon>Source Code</a>
1010
<a href="/showcase.html"><ion-icon name="albums-outline"></ion-icon>See more Demos</a>
1111
<a href="/showcase.html"><ion-icon name="planet-outline"></ion-icon>Check out NGE</a>
1212
</nav>
13+
<div class="warning" id="noweb" style="display:none">
14+
This demo is not fully optimized for the web.
15+
<br>
16+
Performance may be poor on older / low-power hardware, throttled laptops, or browsers with limited WebGL2 support.
17+
<br>
18+
For the best experience (faster startup, better memory usage), download the native build from the link above.
19+
</div>
1320
<iframe id="webapp"
1421
style="width:100%; height:80vh; border:none"
15-
sandbox="allow-forms allow-modals allow-pointer-lock allow-popups allow-presentation allow-same-origin allow-scripts"
1622
src="">
1723
</iframe>
18-
<div id="iframe-console" class="iframe-console" aria-live="polite"></div>
19-
20-
<style>
21-
.iframe-console {
22-
font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
23-
background: var(--bg-2, #0f1220);
24-
color: var(--fg, #e6f1ff);
25-
border: 1px solid rgba(255, 255, 255, .08);
26-
border-radius: 6px;
27-
padding: 8px;
28-
margin-top: 10px;
29-
max-height: 240px;
30-
overflow: auto;
31-
}
32-
33-
.iframe-console .row {
34-
white-space: pre-wrap;
35-
word-break: break-word;
36-
margin: 2px 0;
37-
}
38-
39-
.iframe-console .row .ts {
40-
opacity: .6;
41-
margin-right: .5em;
42-
}
43-
44-
.iframe-console .row.log {}
45-
46-
.iframe-console .row.info {
47-
color: #9cdcfe;
48-
}
49-
50-
.iframe-console .row.warn {
51-
color: #d7ba7d;
52-
}
53-
54-
.iframe-console .row.error {
55-
color: #f48771;
56-
}
57-
</style>
24+
5825
<script>
5926
window.addEventListener('load', (event) => {
6027
const params = new URLSearchParams(window.location.search);
@@ -68,59 +35,12 @@ <h2 id="demo-id"> </h2>
6835
document.getElementById('dl').href = "https://github.com/NostrGameEngine/" + demoId + "/releases";
6936
const frame = document.getElementById('webapp');
7037
frame.src = "https://ngengine.org/" + demoId;
71-
const panel = document.getElementById('iframe-console');
72-
73-
function toStr(v) {
74-
if (v instanceof Error) return v.stack || (v.name + ': ' + v.message);
75-
const t = typeof v;
76-
if (t === 'string') return v;
77-
if (t === 'function') return v.toString();
78-
try { return JSON.stringify(v, null, 2); } catch { return String(v); }
79-
}
80-
function append(type, args) {
81-
const row = document.createElement('div');
82-
row.className = 'row ' + type;
83-
const ts = new Date().toISOString().split('T')[1].replace('Z', '');
84-
row.innerHTML = `<span class="ts">${ts}</span>${args.map(toStr).join(' ')}`;
85-
panel.appendChild(row);
86-
panel.scrollTop = panel.scrollHeight;
87-
}
88-
89-
// Receive forwarded logs (works for both same-origin and cross-origin if the app posts messages)
90-
window.addEventListener('message', (ev) => {
91-
const d = ev.data;
92-
if (!d || d.__iframeConsole !== true) return;
93-
if (ev.source && frame.contentWindow && ev.source !== frame.contentWindow) return;
94-
append(d.type || 'log', Array.isArray(d.data) ? d.data : [d.data]);
95-
});
96-
97-
// Try to hook same-origin iframe console automatically
98-
function hookSameOrigin() {
99-
try {
100-
const cw = frame.contentWindow;
101-
if (!cw || !cw.console) return;
102-
['log', 'info', 'warn', 'error', 'debug'].forEach((k) => {
103-
const orig = cw.console[k]?.bind(cw.console) || function () { };
104-
cw.console[k] = (...a) => {
105-
try { window.postMessage({ __iframeConsole: true, type: k, data: a }, '*'); } catch { }
106-
orig(...a);
107-
};
108-
});
109-
cw.addEventListener('error', (e) => {
110-
window.postMessage({ __iframeConsole: true, type: 'error', data: [e.message, `${e.filename}:${e.lineno}:${e.colno}`] }, '*');
111-
});
112-
cw.addEventListener('unhandledrejection', (e) => {
113-
window.postMessage({ __iframeConsole: true, type: 'error', data: ['Unhandled rejection:', e.reason] }, '*');
114-
});
115-
} catch {
116-
// Cross-origin: cannot hook; rely on shim inside the app (below).
117-
}
118-
}
38+
39+
}
40+
const noWeb = params.get('noweb');
41+
if (noWeb === '1') {
42+
document.getElementById('noweb').style.display = 'block';
11943

120-
frame.addEventListener('load', () => {
121-
append('info', ['iframe loaded', frame.src]);
122-
hookSameOrigin();
123-
});
12444
}
12545
});
12646
</script>

src/showcase.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ <h2>Sea of Nostriches</h2>
2525
</p>
2626

2727
</article><footer>
28-
<a href="/demo.html?id=sea-of-nostriches-demo">
28+
<a href="/demo.html?id=sea-of-nostriches-demo&noweb=1">
2929
<button>Check it out</button>
3030
</a>
3131
</footer>
@@ -42,7 +42,7 @@ <h2>Ads City</h2>
4242

4343
</article>
4444
<footer>
45-
<a href="/demo.html?id=adcity-demo">
45+
<a href="/demo.html?id=adcity-demo&noweb=1">
4646
<button>Check it out</button>
4747
</a>
4848
</footer>

static/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@
246246
}
247247

248248

249+
.warning{
250+
border: 2px dotted var(--accent-purple);
251+
padding:2rem;
252+
border-radius:0.5rem;
253+
font-size: 1.2rem;
254+
font-weight: bold;
255+
line-height: 1.8rem;
256+
}
257+
249258

250259

251260

0 commit comments

Comments
 (0)