Editor: "New Script" button on the Script inspector

Stage-10 editor-UX follow-up. The Script component's inspector section
now ends with a name field + " New Script" button (Enter in the field
also submits): it writes a fresh .rhai from the tested template into
assets/scripts/ via create_script_file (sanitized stem, collisions
suffixed), registers it in the asset database, saves the manifest, and
assigns it to the component's `source` through the normal edit path —
so the assignment is one undoable SetFieldCmd. Disabled with a hint
while no project is open; failures land in the Console via the log.

GUI piece — needs an eye-check before promotion to main.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Homer
2026-07-10 20:33:23 +02:00
parent d6cb9947b2
commit 4f1e9a48d7
3 changed files with 79 additions and 0 deletions
+7
View File
@@ -207,6 +207,13 @@ Scripting plugs into the editor the same way physics does:
rendered generically from its fields. The `source` field is an
`AssetRef<ScriptAsset>`, which the inspector shows as an asset picker filtered
to the project's `scripts/` folder (`AssetKind::Script`).
- **New Script button.** The `Script` section of the inspector ends with a name
field + ** New Script**: it writes a fresh `.rhai` from the built-in template
into `assets/scripts/` (name sanitized, collisions suffixed `_2`, `_3`, …),
registers it in the asset database, and assigns it to the component through
the undo stack — no round-trip through an external file manager. The template
is `oxide_editor::assets::script_template` (a unit test compiles it under the
sandboxed engine so it can never ship a syntax error).
- **Play loop.** When Play starts, the editor's play `App` adds `ScriptModule`
alongside `PhysicsModule`, **shares the editor's `AssetServer`**, and is handed
a snapshot of the project `AssetDatabase`. Sharing the server is what lets the