Skip to content
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ option(STEADING_WITH_STRATA "Build the playable game and save integration on the
option(STEADING_WEB "Build the browser game (Emscripten + Strata's WebGL 2 backend; no OpenUSD, no saves)" OFF)
# The Strata commit the game is built against (the v0.7.0 tag; strata.ref
# carries the same SHA for CI). Pinned; bump deliberately.
set(STEADING_STRATA_REF "20827c3d67e71c1f942c29e7cf8adfa4801188a8" CACHE STRING "Strata git ref (a full commit SHA in CI)")
set(STEADING_STRATA_REF "5ea7e14f0e59618179c11fe9784e9b4102acc0f1" CACHE STRING "Strata git ref (a full commit SHA in CI)")

# Emscripten: the rules, tools and tests build as they are and the tests run
# under Node; STEADING_WEB adds the browser game. Strata compiles C++
Expand Down
2 changes: 1 addition & 1 deletion strata.ref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20827c3d67e71c1f942c29e7cf8adfa4801188a8
5ea7e14f0e59618179c11fe9784e9b4102acc0f1
2 changes: 1 addition & 1 deletion web/strata-kit/PIN
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20827c3d67e71c1f942c29e7cf8adfa4801188a8
5ea7e14f0e59618179c11fe9784e9b4102acc0f1
2 changes: 1 addition & 1 deletion web/strata-kit/SHA256SUMS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
fa03e8ed92759359359f29f40668c947e63b0c9f3eabafcce2f911110637f5c3 strata-loader.js
c4079c74093525b25dac4fcac7c4d56976f1d1e03ef5239a5f873878d0119eb6 strata-loader.js
8e3fc647b4775773eabc147e564ffbddd0653b252eff96c5432213ee362798df LICENSE
41 changes: 35 additions & 6 deletions web/strata-kit/strata-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
trailer: {webm: "...", mp4: "..."}, // optional: played when the page can't run live
fallback: {href: "/", text: "Open the 2D dashboard"}, // optional link on every fallback
gate: false, // true: wait for a tap when the device asks for less
mount: el, contain: true, // optional: cover only `el` (a page section), not the viewport
});
// ... create the scene with StrataKit.create({module: mod, ...}), then:
StrataLoader.done();
Expand All @@ -28,7 +29,7 @@
}

show() takes load()'s display options (title, poster, trailer, fallback,
mount) and returns false, with the fallback showing, when WebGL 2 is
mount, contain) and returns false, with the fallback showing, when WebGL 2 is
missing. progress(fraction, label) clamps the fraction to 0..1 and never
moves the bar back; the label (or the percentage) replaces the size line.

Expand All @@ -50,6 +51,14 @@
Save-Data, or under 4 GB of device memory where the browser says) gets the
poster and a "Start" button instead of an automatic download.

By default the overlay covers the viewport (position:fixed), whatever
`mount` is. With contain: true it covers only `mount` instead
(position:absolute inside it, scrolling with it): for a scene in one
section of a longer page, such as a hero render or a card. A `mount` whose
position is static is made position:relative so the overlay has something
to be absolute to. The slow bar (slow()) then sits at the bottom of `mount`
too. Without `mount`, contain does nothing.

load() resolves with the module, or rejects with an Error whose `code` is
"no-webgl2", "network" or "engine" after the fallback is already showing.

Expand All @@ -65,6 +74,7 @@
.sk-loader{position:fixed;inset:0;z-index:20;display:grid;place-items:center;padding:16px;
background:var(--sk-loader-bg,#101712);color:var(--sk-loader-fg,#e3ece4);
font:14px/1.4 system-ui,-apple-system,"Segoe UI",sans-serif;transition:opacity .3s}
.sk-loader.sk-contained{position:absolute}
.sk-loader[hidden]{display:none}
.sk-loader.sk-done{opacity:0;pointer-events:none}
.sk-loader .sk-backdrop{position:absolute;inset:0;background-size:cover;background-position:center;
Expand All @@ -90,6 +100,11 @@

let root = null, opts = {}, state = "idle", shown = 0;

// The element the overlay covers when contain is set, else null (the viewport).
function container() {
return opts.contain && opts.mount ? opts.mount : null;
}

function el(tag, cls, text) {
const e = document.createElement(tag);
if (cls) e.className = cls;
Expand All @@ -110,6 +125,11 @@
document.head.appendChild(style);
root = el("div", "sk-loader");
root.setAttribute("role", "status");
const scope = container();
if (scope) {
root.classList.add("sk-contained");
if (getComputedStyle(scope).position === "static") scope.style.position = "relative";
}
if (opts.poster) {
const b = el("div", "sk-backdrop");
b.style.backgroundImage = `url("${String(opts.poster).replace(/"/g, "%22")}")`;
Expand Down Expand Up @@ -372,10 +392,18 @@
if (document.querySelector(".sk-slow")) return;
const bar = el("div", "sk-slow");
bar.setAttribute("role", "status");
bar.style.cssText = "position:fixed;left:50%;transform:translateX(-50%);bottom:max(12px,env(safe-area-inset-bottom));" +
const inside = container();
bar.style.cssText = (inside ? "position:absolute;" : "position:fixed;") + "left:50%;transform:translateX(-50%);bottom:max(12px,env(safe-area-inset-bottom));" +
"z-index:21;background:rgba(0,0,0,.7);color:#fff;padding:8px 12px;border-radius:8px;" +
"font:13px system-ui,sans-serif;display:flex;gap:10px;align-items:center;max-width:calc(100vw - 32px)";
"font:13px system-ui,sans-serif;display:flex;flex-wrap:wrap;gap:10px;align-items:center;width:max-content;" +
(inside ? "max-width:calc(100% - 32px)" : "max-width:calc(100vw - 32px)");
bar.appendChild(el("span", "", "This device is drawing slowly."));
// The buttons wrap under the text together when the row is too narrow
// (a 390 px phone), rather than squeezing it onto several lines. The
// width is max-content because left:50% alone would cap an auto width at
// half the viewport.
const buttons = el("div", "");
buttons.style.cssText = "display:flex;gap:10px;margin-left:auto";
const b = el("button", "", opts.trailer ? "Show the clip" : (opts.fallback.text || "Open the simpler view"));
b.type = "button";
b.style.cssText = "font:inherit;min-height:36px;padding:4px 10px;border-radius:6px;border:0;cursor:pointer";
Expand All @@ -388,9 +416,10 @@
x.setAttribute("aria-label", "Dismiss");
x.style.cssText = b.style.cssText;
x.addEventListener("click", () => bar.remove());
bar.appendChild(b);
bar.appendChild(x);
document.body.appendChild(bar);
buttons.appendChild(b);
buttons.appendChild(x);
bar.appendChild(buttons);
(inside || document.body).appendChild(bar);
}

window.StrataLoader = {load, show, progress, done, fallback, slow, hasWebGL2, get state() { return state; }};
Expand Down
Loading