mirror of
https://github.com/storytold/effectcraft.git
synced 2026-12-05 08:21:21 -05:00
Merge branch 'feat/agents-open-window' of https://github.com/davidmann4/effectcraft into feat/control-token
This commit is contained in:
@@ -77,14 +77,19 @@ impl Session {
|
||||
r
|
||||
}
|
||||
|
||||
/// Runs `f` without the [`Session::command_gate`]: work the app does on its own (a Watch
|
||||
/// Folder's poll), not for the agent whose request or input is being handled.
|
||||
/// Runs `f` without the [`Session::command_gate`] and the agent's footage wrapper
|
||||
/// ([`Session::agent_footage`]): work the app does on its own (a Watch Folder's poll, the
|
||||
/// reload of a changed project), not for the agent whose request or input is being handled.
|
||||
pub fn without_gate<R>(&mut self, f: impl FnOnce(&mut Session) -> R) -> R {
|
||||
let gate = self.command_gate.take();
|
||||
let footage = self.agent_footage.take();
|
||||
let r = f(self);
|
||||
if self.command_gate.is_none() {
|
||||
self.command_gate = gate;
|
||||
}
|
||||
if self.agent_footage.is_none() {
|
||||
self.agent_footage = footage;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
|
||||
@@ -48,3 +48,18 @@ fn the_commands_a_command_runs_are_not_checked_again() {
|
||||
assert!(s.without_gate(|s| s.execute("layer.newSolid", json!({"name": "S"}))).is_ok());
|
||||
assert!(s.command_gate.is_some());
|
||||
}
|
||||
|
||||
/// The app's own work (the reload of a changed project) runs as the person's: a project it opens
|
||||
/// doesn't take the footage wrapper of an agent whose input waits, which comes back afterwards.
|
||||
#[test]
|
||||
fn work_without_the_gate_opens_projects_without_the_agents_footage_wrapper() {
|
||||
let seen = Arc::new(Mutex::new(vec![]));
|
||||
let wrapped: Arc<dyn effectcraft_engine::render::FootageSource> = Arc::new(effectcraft_engine::render::NoFootage);
|
||||
let wrapper = wrapped.clone();
|
||||
let wrap: effectcraft_engine::FootageWrap = Arc::new(move |_| wrapper.clone());
|
||||
let mut s = Session { command_gate: Some(gate(&seen)), agent_footage: Some(wrap), ..Default::default() };
|
||||
let own = s.footage.clone();
|
||||
s.without_gate(|s| s.execute("file.newProject", json!({}))).unwrap();
|
||||
assert!(Arc::ptr_eq(&s.footage, &own), "the app's own open took the agent's footage wrapper");
|
||||
assert!(s.agent_footage.is_some() && s.command_gate.is_some(), "the agent's scope didn't come back");
|
||||
}
|
||||
|
||||
@@ -358,7 +358,8 @@ impl EffectcraftApp {
|
||||
}
|
||||
if let Some(rx) = self.command_inbox.take() {
|
||||
while let Ok(id) = rx.try_recv() {
|
||||
if let Err(e) = menus::invoke(self, ctx, &id, json!({})) {
|
||||
// The person's native menu: not confined by an agent whose input waits.
|
||||
if let Err(e) = self.as_person(|app| menus::invoke(app, ctx, &id, json!({}))) {
|
||||
self.ui.status = e;
|
||||
}
|
||||
}
|
||||
@@ -904,7 +905,9 @@ impl EffectcraftApp {
|
||||
self.ui.status = "Project changed on disk. To keep your changes, use File ▸ Save As ▸ Save a Copy... Then File ▸ Revert loads the disk version; Revert discards unsaved changes.".into();
|
||||
return;
|
||||
}
|
||||
match self.session.execute("file.revert", serde_json::json!({})) {
|
||||
// The app's own reload, not an agent's request: its gate doesn't apply, and only the agent's
|
||||
// own project keeps the agent's footage limits (`Session::reverting`).
|
||||
match self.session.without_gate(|s| s.execute("file.revert", serde_json::json!({}))) {
|
||||
Ok(_) => {
|
||||
self.ui.status = format!("Reloaded {path} changed on disk");
|
||||
watcher.acknowledge(self.session.project_stamp);
|
||||
|
||||
@@ -86,6 +86,22 @@ impl EffectcraftApp {
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs `f` as the person: without the gate and footage wrapper of an agent whose queued
|
||||
/// input waits, both put back afterwards ([`effectcraft_engine::Session::without_gate`] for
|
||||
/// what needs the whole app, such as a native-menu command).
|
||||
pub(crate) fn as_person<R>(&mut self, f: impl FnOnce(&mut Self) -> R) -> R {
|
||||
let gate = self.session.command_gate.take();
|
||||
let footage = self.session.agent_footage.take();
|
||||
let r = f(self);
|
||||
if self.session.command_gate.is_none() {
|
||||
self.session.command_gate = gate;
|
||||
}
|
||||
if self.session.agent_footage.is_none() {
|
||||
self.session.agent_footage = footage;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
/// Take the pending synthetic input (from `ui.click`, `ui.key`, …). Hosts that don't call
|
||||
/// [`eframe::App::raw_input_hook`] (the headless test harness) feed these in themselves.
|
||||
pub fn take_synthetic_input(&mut self) -> Vec<egui::Event> {
|
||||
|
||||
Reference in New Issue
Block a user