mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-17 00:13:17 +00:00
8bf4abc3a4
This PR adds the bones of a user-facing scene inspector. ### Work Done To facilitate this work, the Bevy/frontend interface has been expanded to accommodate two-way communications: - The Bevy app can now dispatch JavaScript `CustomEvent`s via `wasm::dispatch_to_js(...)` - The frontend application can receive those events by listening for the given event type on the `window` object In its current state, the inspection system works by attaching the `Inspectable` marker component to any entities which should be exposed to the user. A Bevy system runs on `Update` to check for newly spawned or despawned entities with that component, and emits events to notify the frontend. The frontend listens for those events and updates its model of the scene accordingly, which is then displayed with a simple tree view. ### Future Enhancements There are many improvements that must be made to make this system actually useful, but this PR is being expedited to focus on migrating to Bevy 0.12. A shortlist of planned updates: - Identify and expose the "type" of entity (e.g. lights, cameras, meshes, skeletons, etc.) via a field on the `Inspectable` component - Highlight the currently selected entity in the frontend hierarchy - Ask the Bevy app to update the selection when the user selects an entry in the hierarchy - Add a separate UI panel to inspect and modify the selected entity's components via the frontend
80 lines
2.0 KiB
JavaScript
80 lines
2.0 KiB
JavaScript
import chalk from "chalk";
|
|
import { glob } from "glob";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import url from "node:url";
|
|
|
|
export default async function main() {
|
|
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
const assetsSrc = path.resolve(__dirname, "../assets");
|
|
const assetsDest = path.resolve(__dirname, "../../dist/studio/public/assets");
|
|
|
|
console.log("");
|
|
console.log(`Copying assets from "${assetsSrc}" to "${assetsDest}"`);
|
|
|
|
let count = 0;
|
|
const start = performance.now();
|
|
|
|
try {
|
|
/** @type string[] */
|
|
let ignore = [];
|
|
const cpIgnorePath = path.join(assetsSrc, ".cp-ignore");
|
|
if (fs.existsSync(cpIgnorePath))
|
|
ignore = (await fs.promises.readFile(cpIgnorePath, "utf-8"))
|
|
.split(/\r?\n/)
|
|
.map(line => `assets/${line}`);
|
|
|
|
const files = await glob("assets/**/*", {
|
|
ignore,
|
|
absolute: true,
|
|
nodir: true,
|
|
});
|
|
count = files.length;
|
|
|
|
await Promise.all(files.map(async src => {
|
|
const relSrc = path.relative(assetsSrc, src);
|
|
const dest = path.resolve(assetsDest, relSrc);
|
|
const destDir = path.dirname(dest);
|
|
|
|
if (!fs.existsSync(destDir))
|
|
await fs.promises.mkdir(destDir, { recursive: true });
|
|
|
|
await fs.promises.copyFile(src, dest);
|
|
}));
|
|
}
|
|
catch (err) {
|
|
handleError(err);
|
|
}
|
|
|
|
const elapsed = Math.round(performance.now() - start);
|
|
const label = chalk.bold.greenBright.inverse(" DONE ");
|
|
console.log(`${label} Copied ${count} files in ${elapsed} ms`);
|
|
}
|
|
|
|
/**
|
|
* @param {any} err
|
|
* @returns {never}
|
|
*/
|
|
function handleError(err) {
|
|
const label = chalk.bold.redBright.inverse(" ERROR ");
|
|
switch (typeof err) {
|
|
case "number":
|
|
console.log(`${label} Process exited with code ${err}`);
|
|
process.exit(err);
|
|
|
|
case "string":
|
|
console.log(`${label} ${err}`);
|
|
process.exit(1);
|
|
|
|
case "object":
|
|
console.log(`${label} ${err.message}`);
|
|
if (err.stack && err.stack !== err.message)
|
|
console.log(chalk.dim(err.stack));
|
|
process.exit(1);
|
|
|
|
default:
|
|
console.log(`${label} An unknown error occured`);
|
|
process.exit(1);
|
|
}
|
|
}
|