ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Add dockable Art tools, animation and previews, guarded asset workflows, and the Web Asset Studio built on the shared Art Core. Expand English and Russian documentation, interactive Try scenes, examples and editor icons. Add audio waveform navigation, source analysis, guarded previews and a browser Worker mixer. Preserve source changes and recovery with bounded checks, and strengthen native, browser and interoperability CI. Prepare version 0.12.5 and manually built native artifact candidates. Fix the production site image demo build dependency. Reuse immutable scene indices when capturing keyframes. Wait for real Persist save/load completion in component tests. Stabilize browser Game View captures outside pointer hover. Aseprite interchange and persistent Audio EDL recovery remain limited; the artifact workflow does not publish releases or change stable.
298 lines
14 KiB
JavaScript
298 lines
14 KiB
JavaScript
"use strict";
|
|
|
|
(function () {
|
|
const blocks = [...document.querySelectorAll(".try[data-scene]")];
|
|
if (!blocks.length) return;
|
|
globalThis.aegoSoundDefault = true;
|
|
const ru = document.documentElement.lang === "ru";
|
|
const t = (en, rus) => (ru ? rus : en);
|
|
const starters = new Map();
|
|
const texts = new Map();
|
|
let api = null;
|
|
let active = null;
|
|
let canvas = null;
|
|
let clearInputHint = null;
|
|
|
|
function boot(report) {
|
|
return globalThis.aegoRuntime("try", "aego-docs.wasm", "aegoDocsReady", "aegoDocs", report);
|
|
}
|
|
|
|
function call(method, payload) {
|
|
return JSON.parse(api.call(method, JSON.stringify(payload || {})));
|
|
}
|
|
|
|
// The Try it view follows the site's theme switch (D345).
|
|
function syncTheme() {
|
|
if (api) call("theme", { theme: globalThis.aegoTheme || "dark" });
|
|
if (api) call("lang", { lang: document.documentElement.lang || "en" });
|
|
}
|
|
document.addEventListener("aego-theme", syncTheme);
|
|
|
|
function status(b, text, error) {
|
|
const s = b.querySelector(".try-status");
|
|
s.textContent = text;
|
|
s.classList.toggle("error", !!error);
|
|
}
|
|
|
|
function setValue(cell, value) {
|
|
if (cell.dataset.kind === "color") {
|
|
cell.textContent = "";
|
|
const sw = document.createElement("i");
|
|
sw.className = "sw";
|
|
sw.style.background = value;
|
|
cell.append(sw, value);
|
|
} else {
|
|
cell.textContent = value;
|
|
}
|
|
}
|
|
|
|
function show(b, text, values) {
|
|
texts.set(b, text);
|
|
if (!values) return;
|
|
for (const cell of b.querySelectorAll(".st-fields .v[data-k]")) {
|
|
if (!(cell.dataset.k in values)) continue;
|
|
if (cell.dataset.orig === undefined) cell.dataset.orig = cell.textContent;
|
|
const v = values[cell.dataset.k];
|
|
if (cell.textContent !== v) setValue(cell, v);
|
|
cell.classList.toggle("changed", v !== cell.dataset.orig);
|
|
}
|
|
}
|
|
|
|
globalThis.aegoDocsChanged = (text, values) => {
|
|
if (active) show(active, text, values ? JSON.parse(values) : null);
|
|
};
|
|
|
|
function progress(b) {
|
|
const box = document.createElement("div");
|
|
box.className = "try-progress";
|
|
box.innerHTML = '<div class="label">Loading the engine</div><div class="bar"><i></i></div><div class="phase"></div>';
|
|
const bar = box.querySelector(".bar i");
|
|
const phase = box.querySelector(".phase");
|
|
const label = box.querySelector(".label");
|
|
const update = (s) => {
|
|
if (active !== b) return;
|
|
const pct = s.total ? Math.min(100, (s.got * 100) / s.total) : 0;
|
|
if (s.phase === "download") {
|
|
bar.style.width = pct + "%";
|
|
const wire = s.wire || s.total;
|
|
phase.textContent = s.total ? `${globalThis.aegoMB((s.got * wire) / s.total)} of ${globalThis.aegoMB(wire)}` : globalThis.aegoMB(s.got);
|
|
} else if (s.phase === "cache") {
|
|
label.textContent = t("Starting the engine", "Запуск движка");
|
|
phase.textContent = t("From the browser cache", "Из кэша браузера");
|
|
} else if (s.phase === "compile") {
|
|
bar.style.width = "100%";
|
|
label.textContent = t("Compiling", "Компиляция");
|
|
phase.textContent = "";
|
|
} else if (s.phase === "start") {
|
|
label.textContent = t("Starting the scene", "Запуск сцены");
|
|
}
|
|
};
|
|
return { box, update };
|
|
}
|
|
|
|
let soundTimer = 0;
|
|
|
|
function audio() {
|
|
if (typeof globalThis.aegoAudioStats !== "function") return null;
|
|
try {
|
|
return JSON.parse(globalThis.aegoAudioStats());
|
|
} catch (_) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function syncSound(b) {
|
|
const btn = b.querySelector(".try-sound");
|
|
const st = audio();
|
|
if (!btn || !st || active !== b) return;
|
|
const state = st.muted ? "muted" : st.running ? "on" : "blocked";
|
|
if (btn.dataset.state === state && !btn.hidden) return;
|
|
btn.hidden = false;
|
|
btn.dataset.state = state;
|
|
btn.setAttribute("aria-pressed", String(state === "on"));
|
|
btn.querySelector("span").textContent = state === "on" ? "Sound on" : state === "muted" ? "Sound off" : "Turn sound on";
|
|
btn.title = state === "on" ? t("Mute the scene", "Выключить звук сцены") : state === "muted" ? t("Unmute the scene", "Включить звук сцены") : t("The browser holds sound until you click the page", "Браузер не даёт звук, пока вы не нажмёте на страницу");
|
|
}
|
|
|
|
function watchSound(b) {
|
|
clearInterval(soundTimer);
|
|
if (!b.querySelector(".try-sound")) return;
|
|
syncSound(b);
|
|
soundTimer = setInterval(() => syncSound(b), 400);
|
|
}
|
|
|
|
function release(b) {
|
|
clearInterval(soundTimer);
|
|
if (clearInputHint) clearInputHint();
|
|
const sound = b.querySelector(".try-sound");
|
|
if (sound) sound.hidden = true;
|
|
b.classList.remove("active");
|
|
const stage = b.querySelector(".try-stage");
|
|
stage.textContent = "";
|
|
for (const el of starters.get(b)) stage.appendChild(el);
|
|
b.querySelector(".try-reset").disabled = true;
|
|
texts.set(b, b.dataset.scene);
|
|
for (const cell of b.querySelectorAll(".st-fields .v[data-k]")) {
|
|
if (cell.dataset.orig !== undefined) setValue(cell, cell.dataset.orig);
|
|
cell.classList.remove("changed");
|
|
}
|
|
status(b, "");
|
|
}
|
|
|
|
// The canvas also contains the Inspector and toolbar: only a primary click
|
|
// in the actual Game View gives the scene keyboard input.
|
|
function inputHint(stage) {
|
|
if (stage.querySelector(".try-input")) return;
|
|
const hint = document.createElement("div");
|
|
hint.className = "try-input";
|
|
const keys = stage.closest(".try").dataset.input;
|
|
hint.textContent = t("Click the canvas, then use WASD / arrows", "Нажмите на сцену, затем WASD / стрелки") + (keys ? ", " + keys : "");
|
|
stage.appendChild(hint);
|
|
const done = () => {
|
|
hint.remove();
|
|
canvas.removeEventListener("pointerdown", onPointerDown);
|
|
clearInputHint = null;
|
|
};
|
|
const onPointerDown = (event) => {
|
|
if (event.button !== 0 || event.isPrimary === false) return;
|
|
let v;
|
|
try {
|
|
v = call("viewport").viewport;
|
|
} catch (_) {
|
|
return;
|
|
}
|
|
const r = canvas.getBoundingClientRect();
|
|
if (!v || ![v.x, v.y, v.width, v.height, v.canvasWidth, v.canvasHeight, r.width, r.height].every(Number.isFinite) ||
|
|
v.width <= 0 || v.height <= 0 || v.canvasWidth <= 0 || v.canvasHeight <= 0 || r.width <= 0 || r.height <= 0) return;
|
|
const x = (event.clientX - r.left) * v.canvasWidth / r.width;
|
|
const y = (event.clientY - r.top) * v.canvasHeight / r.height;
|
|
if (x >= v.x && x < v.x + v.width && y >= v.y && y < v.y + v.height) done();
|
|
};
|
|
clearInputHint = done;
|
|
canvas.addEventListener("pointerdown", onPointerDown);
|
|
}
|
|
|
|
// unlockAudio runs inside the click on Try it: a context made here starts running, while one made after the runtime boots would wait for another click.
|
|
function unlockAudio(b) {
|
|
if (!b.querySelector(".try-sound")) return;
|
|
const old = globalThis.aegoAudioContext;
|
|
if (old && old.state !== "closed") {
|
|
old.resume().catch(() => {});
|
|
return;
|
|
}
|
|
const C = window.AudioContext || window.webkitAudioContext;
|
|
if (!C) return;
|
|
try {
|
|
globalThis.aegoAudioContext = new C({ latencyHint: "interactive", sampleRate: 48000 });
|
|
} catch (_) {
|
|
try {
|
|
globalThis.aegoAudioContext = new C({ latencyHint: "interactive" });
|
|
} catch (_) {
|
|
return;
|
|
}
|
|
}
|
|
globalThis.aegoAudioContext.resume().catch(() => {});
|
|
}
|
|
|
|
async function activate(b) {
|
|
if (active === b) return;
|
|
unlockAudio(b);
|
|
if (active) release(active);
|
|
active = b;
|
|
if (!canvas) {
|
|
canvas = document.createElement("canvas");
|
|
canvas.setAttribute("data-aego", "");
|
|
canvas.tabIndex = 0;
|
|
canvas.setAttribute("aria-label", t("Interactive scene with the Inspector", "Интерактивная сцена с Инспектором"));
|
|
}
|
|
const stage = b.querySelector(".try-stage");
|
|
stage.textContent = "";
|
|
stage.appendChild(canvas);
|
|
const p = progress(b);
|
|
if (!api) stage.appendChild(p.box);
|
|
b.classList.add("active");
|
|
try {
|
|
api = await boot(p.update);
|
|
p.box.remove();
|
|
if (active !== b) return;
|
|
syncTheme();
|
|
const res = call("load", { scene: b.dataset.scene, select: b.dataset.select || "", code: b.dataset.code || "", prefabs: b.dataset.prefabs ? JSON.parse(b.dataset.prefabs) : {}, artifacts: b.dataset.artifacts || "" });
|
|
if (res.error) throw new Error(res.error);
|
|
show(b, res.text, res.values);
|
|
b.querySelector(".try-reset").disabled = false;
|
|
watchSound(b);
|
|
if ("input" in b.dataset) inputHint(stage);
|
|
status(b, t("Change a field on the right: the scene restarts with it. Click the view to send input.", "Измените поле справа — сцена перезапустится с ним. Нажмите на вид, чтобы передать ввод."));
|
|
} catch (e) {
|
|
p.box.remove();
|
|
status(b, e.message, true);
|
|
}
|
|
}
|
|
|
|
function download(b) {
|
|
const blob = new Blob([texts.get(b) || b.dataset.scene], { type: "text/plain" });
|
|
const a = document.createElement("a");
|
|
a.href = URL.createObjectURL(blob);
|
|
a.download = (b.dataset.name || "scene") + ".aescene";
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
a.remove();
|
|
setTimeout(() => URL.revokeObjectURL(a.href), 1000);
|
|
status(b, t("Edited scene saved. Keep it with the scripts, prefabs and source assets from Download example project.", "Изменённая сцена сохранена. Используйте её вместе со скриптами, префабами и ресурсами из «Скачать проект примера»."));
|
|
}
|
|
|
|
for (const b of blocks) {
|
|
starters.set(b, [...b.querySelector(".try-stage").childNodes]);
|
|
texts.set(b, b.dataset.scene);
|
|
b.querySelector(".try-start").addEventListener("click", () => activate(b));
|
|
b.querySelector(".try-reset").addEventListener("click", () => {
|
|
if (active !== b || !api) return;
|
|
const res = call("reset");
|
|
if (res.error) status(b, res.error, true);
|
|
else show(b, res.text, res.values);
|
|
});
|
|
b.querySelector(".try-download").addEventListener("click", () => download(b));
|
|
const open = b.querySelector(".try-open");
|
|
if (open) open.addEventListener("click", (event) => {
|
|
// Links carry only the validated manifest URL and operation. A
|
|
// local/staging preview must not silently open production data.
|
|
const here = new URL(b.dataset.exampleManifest, location.href);
|
|
const link = new URL(open.href);
|
|
if (here.protocol !== "https:" || link.protocol !== "aego:" || link.hostname !== "example" || link.searchParams.get("manifest") !== here.href) {
|
|
event.preventDefault();
|
|
status(b, t("This is a local preview. Download the complete project, extract it and open project.aego in Aego.", "Это локальный предпросмотр. Скачайте полный проект, распакуйте его и откройте project.aego в Aego."));
|
|
return;
|
|
}
|
|
status(b, t("Aego will ask before downloading the original example. If Aego is not installed, use Download example project. Browser field edits stay here; download the edited scene to keep them.", "Aego запросит разрешение перед загрузкой исходного примера. Если редактор не установлен, скачайте проект примера. Изменения полей остаются здесь — скачайте изменённую сцену, чтобы сохранить их."));
|
|
});
|
|
const sound = b.querySelector(".try-sound");
|
|
if (sound) sound.addEventListener("click", () => {
|
|
const st = audio();
|
|
if (active !== b || !st) return;
|
|
if (st.muted || st.running) globalThis.aegoAudioMute(!st.muted);
|
|
setTimeout(() => syncSound(b), 50);
|
|
});
|
|
b.querySelector(".try-copy").addEventListener("click", async () => {
|
|
try {
|
|
await navigator.clipboard.writeText(texts.get(b));
|
|
status(b, t("Scene copied. The complete example download includes its scripts, prefabs and source assets.", "Сцена скопирована. Скрипты, префабы и ресурсы включены в полный проект примера."));
|
|
} catch (_) {
|
|
status(b, t("The browser blocked the clipboard", "Браузер заблокировал буфер обмена"), true);
|
|
}
|
|
});
|
|
}
|
|
|
|
globalThis.aegoRuntimeCached("try", "aego-docs.wasm").then((warm) => {
|
|
if (!warm || !("IntersectionObserver" in window)) return;
|
|
const seen = new IntersectionObserver((list) => {
|
|
for (const it of list) {
|
|
if (!it.isIntersecting || active) continue;
|
|
seen.disconnect();
|
|
activate(it.target.closest(".try"));
|
|
return;
|
|
}
|
|
}, { threshold: 0.35 });
|
|
for (const b of blocks) seen.observe(b.querySelector(".try-stage"));
|
|
});
|
|
})();
|