diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 0143d66c..9c65ba75 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -748,7 +748,12 @@ fn panic_hunt_every_command() { json!({"items": (0..1500).map(|_| json!({"symbol": ball})).collect::>(), "x": 0, "y": 0}), json!({"sound": SOUND, "symbol": ball, "x": 10, "y": 10}), ]); - for start in [Session::default(), Session::new(sample::demo()), Session::new(with_sound), on_path, raw, rig, layered, in_symbol, keyed, library] { + // A button open for editing, its hit area drawn over its other states (ADR 0057). + let mut button = Session::new(sample::interactive()); + if let Some(id) = button.doc.library.iter().find(|x| x.kind == anicraft_doc::SymbolKind::Button).map(|x| x.id) { + button.execute("symbol.edit", &json!({"symbol": id.0})).unwrap(); + } + for start in [Session::default(), Session::new(sample::demo()), Session::new(with_sound), on_path, raw, rig, layered, in_symbol, keyed, library, button] { let mut s = start; for spec in commands().iter().filter(|c| !skip(c.id)) { for p in &hostile { @@ -764,7 +769,14 @@ fn panic_hunt_every_command() { for f in [0, 1, 5, 47, 1000] { let _ = anicraft_render::render_frame(&s.doc, f, 0.1); } + s.hit_area = Some((anicraft_doc::Rgba::WHITE, 0.4)); let pic = s.stage_picture(); + // ...and every button's hit area draws, under a pointer that goes over and presses. + let mut ns = anicraft_doc::player::NoScripts; + let st = anicraft_doc::player::start(&s.doc, &mut ns).state; + let p = anicraft_geom::Vec2::new(640.0, 400.0); + let st = anicraft_doc::player::input(&s.doc, &st, &[anicraft_doc::player::Event::Move(p), anicraft_doc::player::Event::Down(p), anicraft_doc::player::Event::Up(p)], &mut ns).state; + let _ = anicraft_render::render(&anicraft_doc::player::hit_overlay(&s.doc, &st, anicraft_doc::Rgba::WHITE, 0.4), &anicraft_render::View { transform: anicraft_geom::Affine::scale(0.1, 0.1), width: 128, height: 72, background: None }); let _ = anicraft_render::render_frame(&pic.doc, pic.frame, 0.1); // ...and its sounds lay out and mix. let voices = anicraft_doc::sound::voices(&s.doc, 8000); diff --git a/src/test_movie.rs b/src/test_movie.rs index e6b7d9e0..467d3abc 100644 --- a/src/test_movie.rs +++ b/src/test_movie.rs @@ -452,6 +452,34 @@ mod tests { assert!(app.test_movie.is_none()); } + #[test] + fn an_open_button_names_its_states_widens_its_frames_and_shows_its_hit_area() { + let ctx = egui::Context::default(); + let session = anicraft_engine::Session::new(anicraft_engine::doc::sample::interactive()); + let mut app = App::with_context(&ctx, session, Some(std::path::PathBuf::from("unused.png"))); + frame(&ctx, &mut app, vec![]); + let zoom = app.tl_cell_w; + assert!(crate::timeline::button_states(&app).is_none(), "on the stage, frames are numbered"); + let button = app.s.doc.library.iter().find(|s| s.kind == anicraft_engine::doc::SymbolKind::Button).map(|s| s.id.0); + app.run("symbol.edit", json!({"symbol": button})); + app.run("timeline.goto", json!({"frame": 1})); + frame(&ctx, &mut app, vec![]); + assert_eq!(crate::timeline::button_states(&app).map(|s| s.len()), Some(4)); + assert!(app.tl_cell_w > zoom, "wide enough for “Over”: {} vs {zoom}", app.tl_cell_w); + assert!(app.s.hit_overlay().is_some(), "the Hit area over the Over state, in the theme's colour"); + app.run("symbol.exit", json!({})); + frame(&ctx, &mut app, vec![]); + assert_eq!(app.tl_cell_w, zoom, "the zoom it had comes back"); + // Test Movie keeps Show hit areas across a restart. + open(&mut app); + if let Some(tm) = app.test_movie.as_mut() { + tm.hit_areas = true; + } + open(&mut app); + assert!(app.test_movie.as_ref().is_some_and(|t| t.hit_areas)); + frame(&ctx, &mut app, vec![]); + } + #[test] fn key_codes_are_actionscript_s() { use egui::Key as K;