The VS Code of video editing, built for agents.
TypeScript
Enhance project initialization handling and update project configuration
konstantin-paulus1fc4d16bf83f
diff --git a/apps/desktop/src/projects.ts b/apps/desktop/src/projects.tsindex bd5ca0f4..6f6cef2c 100644--- a/apps/desktop/src/projects.ts+++ b/apps/desktop/src/projects.ts@@ -549,7 +549,7 @@ a new session.| Path | What it is || ---- | ---------- || \`index.tsx\` | The entry. Its default export renders the composition. |-| \`package.json\` | The project record: \`projectId\` (its identity, kept across renames), \`displayName\` (the name shown in the app), \`main\` (the entry), \`diffusion\` (how each scene is exported), and the diffusion commands as scripts. |+| \`package.json\` | The project record: \`projectId\` (its identity, kept across renames), \`displayName\` (the name shown in the app), \`main\` (the entry), \`diffusion\` (how each scene is exported, and whether the stage has ever had anything on it), and the diffusion commands as scripts. || \`tsconfig.json\` | Types for the composition tags, through \`jsxImportSource\`. || \`assets.yml\` | The asset library: for every asset its library path, where its bytes are, and what it was found to be. Written by the app; hand edits are read on the next load. || \`assets/\` | The library's files: put one here and it is taken in while the app watches, and the app writes its own here too. Media imported through the app is linked where it lies instead, never copied. |diff --git a/apps/web/src/components/canvas/scene-init-overlay.tsx b/apps/web/src/components/canvas/scene-init-overlay.tsxindex bbb89e01..0f33b279 100644--- a/apps/web/src/components/canvas/scene-init-overlay.tsx+++ b/apps/web/src/components/canvas/scene-init-overlay.tsx@@ -2,7 +2,7 @@* License, v. 2.0. If a copy of the MPL was not distributed with this* file, You can obtain one at http://mozilla.org/MPL/2.0/. */-import { createMemo, createSignal, For, Show } from "solid-js";+import { createEffect, createMemo, createSignal, For, Show } from "solid-js";import { useQuery, useTrait, useWorld } from "@diffusionstudio/koota-solid";import { ChildOf, Library, Root, setCamera, Source } from "@diffusionstudio/runtime";import { Icon } from "@/components/ui/icon";@@ -21,6 +21,7 @@ import {PRESET_CATEGORIES,} from "@/lib/layout-presets";import { useEditor } from "@/engine";+import { useProjectConfig } from "@/engine/project-config";import { droppedFiles, importFiles } from "@/engine/asset-actions";import { createScene, insertAssetsInNewScene } from "@/engine/new-scene";import { ASSET_DRAG_TYPE } from "@/components/sidebar-left/folder-item";@@ -33,9 +34,10 @@ const DEFAULT_NAME = "New Scene";const DEFAULT_PRESET: LayoutPreset = { label: "Long-form 16:9", width: 1920, height: 1080 };/**- * The empty-project prompt: a placeholder frame in the middle of the canvas+ * The new-project prompt: a placeholder frame in the middle of the canvas* that becomes the first scene on click, with the camera fitted to it so the- * scene lands exactly where the placeholder was.+ * scene lands exactly where the placeholder was. Only for a project whose+ * stage has never had anything on it: one emptied later stays empty.*/export function SceneInitOverlay() {const world = useWorld();@@ -43,6 +45,7 @@ export function SceneInitOverlay() {const root = world.get(Root)!;const source = useTrait(root, Source);const children = useQuery(ChildOf(root));+ const config = useProjectConfig();const [editing, setEditing] = createSignal(false);const [selectedPreset, setSelectedPreset] = createSignal<LayoutPreset>(DEFAULT_PRESET);@@ -52,7 +55,19 @@ export function SceneInitOverlay() {let overlayRef: HTMLDivElement | undefined;let buttonRef: HTMLButtonElement | undefined;- const showOverlay = createMemo(() => source()?.value && children().length === 0);+ // Without a project config there is nothing to remember it by: the+ // prompt shows whenever the stage is empty.+ const isNew = () => {+ const c = config();+ return !c || (c.loaded() && !c.initialized());+ };++ const showOverlay = createMemo(() => source()?.value && children().length === 0 && isNew());++ createEffect(() => {+ const c = config();+ if (c?.loaded() && children().length > 0) void c.markInitialized();+ });const aspectRatio = () => {const p = selectedPreset();diff --git a/apps/web/src/engine/project-config.ts b/apps/web/src/engine/project-config.tsindex d6128172..e04ca280 100644--- a/apps/web/src/engine/project-config.ts+++ b/apps/web/src/engine/project-config.ts@@ -18,6 +18,9 @@// A scene with no entry has nothing set up.//// { "export": { "intro": { "format": "mp4", ... } } }+//+// `initialized` says the stage has had something on it at least once: until+// then the project is new, and the canvas offers to make its first scene.import { createSignal } from 'solid-js';import { Source } from '@diffusionstudio/runtime';@@ -148,6 +151,8 @@ export class ProjectConfig {private raw: Record<string, unknown> = {};private disposed = false;private readonly exports = createSignal<Record<string, ExportConfig>>({});+ private readonly loadedSignal = createSignal(false);+ private readonly initializedSignal = createSignal(false);public constructor(world: World, dir: string) {this.world = world;@@ -166,6 +171,25 @@ export class ProjectConfig {this.raw = isRecord(value) ? value : {};this.exports[1](parseExports(this.raw.export));+ this.initializedSignal[1](this.raw.initialized === true);+ this.loadedSignal[1](true);+ }++ /** Whether the config has been read. Reactive. */+ public loaded(): boolean {+ return this.loadedSignal[0]();+ }++ /** Whether the stage has ever had something on it. Reactive. */+ public initialized(): boolean {+ return this.initializedSignal[0]();+ }++ /** Records that the stage has had something on it: here now, in the file after. */+ public async markInitialized(): Promise<void> {+ if (this.initialized()) return;+ this.initializedSignal[1](true);+ await this.save({ ...this.raw, initialized: true });}/**@@ -197,9 +221,13 @@ export class ProjectConfig {const next = { ...this.raw };if (Object.keys(exports).length) next.export = exports;else delete next.export;- this.raw = next;this.exports[1](parseExports(next.export));+ await this.save(next);+ }+ /** Makes `next` the config and writes it to the file. */+ private async save(next: Record<string, unknown>): Promise<void> {+ this.raw = next;try {await writeProjectConfig(this.dir, Object.keys(next).length ? next : null);} catch (error) {