Skip to content

Commit 16b54f2

Browse files
feat(editor): mcp start/stop for play and scripting, hide panels while running
TogglePlay and ToggleScripting were the only handles, and a toggle is racy for an agent that does not know the current state. SetPlay and SetScripting take the desired state, so the editor mcp can start or stop either mode deterministically through the editor_action tool. While a game runs, in play or scripting mode, the page hides the scene and inspector panels for an unobstructed view and restores them on exit exactly as they were.
1 parent c67141e commit 16b54f2

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

apps/editor/src/app.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,32 @@ pub fn App() -> impl IntoView {
3434
crate::workspace::initialize_store(state, hearsay);
3535
let palette_open = state.palette_open;
3636

37+
// While a game runs (play or scripting mode), hide the side panels for an
38+
// unobstructed view, and restore them on exit exactly as they were.
39+
let panel_memory = StoredValue::new((false, false, false));
40+
Effect::new(move |_| {
41+
let running = state.flags.with(|flags| {
42+
flags
43+
.as_ref()
44+
.map(|flags| flags.play_active || flags.scripting_active)
45+
.unwrap_or(false)
46+
});
47+
let (was_running, saved_tree, saved_inspector) = panel_memory.get_value();
48+
if running && !was_running {
49+
panel_memory.set_value((
50+
true,
51+
state.tree_open.get_untracked(),
52+
state.inspector_open.get_untracked(),
53+
));
54+
state.tree_open.set(false);
55+
state.inspector_open.set(false);
56+
} else if !running && was_running {
57+
state.tree_open.set(saved_tree);
58+
state.inspector_open.set(saved_inspector);
59+
panel_memory.set_value((false, saved_tree, saved_inspector));
60+
}
61+
});
62+
3763
let last_saved = StoredValue::new(None::<crate::settings::UserSettings>);
3864
wasm_bindgen_futures::spawn_local(async move {
3965
let settings = crate::settings::load().await;

apps/editor/worker/src/actions.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,16 @@ pub fn apply(editor_world: &mut EditorWorld, world: &mut World, action: EditorAc
372372
EditorAction::ToggleScripting => {
373373
crate::systems::scripting::toggle(editor_world, world);
374374
}
375+
EditorAction::SetPlay(active) => {
376+
if editor_world.resources.play.active != active {
377+
crate::systems::play::toggle(editor_world, world);
378+
}
379+
}
380+
EditorAction::SetScripting(active) => {
381+
if editor_world.resources.scripting.active != active {
382+
crate::systems::scripting::toggle(editor_world, world);
383+
}
384+
}
375385
EditorAction::GlobalScript(command) => {
376386
apply_global_script_command(world, command);
377387
}

crates/nightshade-api/src/editor/protocol.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@ pub enum EditorAction {
446446
ToggleShowFinal,
447447
TogglePlay,
448448
ToggleScripting,
449+
/// Start or stop play mode (the first-person walkthrough) explicitly, so a
450+
/// caller drives it without knowing the current state, unlike `TogglePlay`.
451+
SetPlay(bool),
452+
/// Start or stop scripting mode (run the scene's scripts) explicitly,
453+
/// unlike `ToggleScripting`.
454+
SetScripting(bool),
449455
GlobalScript(GlobalScriptCommand),
450456
TogglePushPull,
451457
SetPlacementActive(bool),

0 commit comments

Comments
 (0)