Merge pull request #479 from MarekSpodBiedry/issue-475

# Conflicts:
#	crates/script/src/tests.rs
This commit is contained in:
Claude 2026-10-10 12:51:16 +00:00
commit adeccc02e0
No known key found for this signature in database
2 changed files with 37 additions and 1 deletions

View File

@ -1724,7 +1724,10 @@ Project.prototype = {
importFile: function (opts) {
var f = opts instanceof ImportOptions ? opts.file : opts;
if (!f) throw __err("importFile(): no file");
var r = __call("file.import", { paths: [__str(f)] });
var args = { paths: [__str(f)] };
// After Effects imports just the picked file unless ImportOptions.sequence is set.
if (opts instanceof ImportOptions) args.sequence = !!opts.sequence;
var r = __call("file.import", args);
if (r.errors && r.errors.length) throw __err(r.errors.join("; "));
return __item(r.items[0]);
},

View File

@ -656,3 +656,36 @@ fn group_selected_false_deselects_masks_and_effects() {
);
assert_eq!(out.result, json!([[true, true], [false, true], [false, false]]));
}
/// Probes every file as a 64x32 still (the media layer's single-file probe).
struct Stills;
impl effectcraft_engine::Importer for Stills {
fn probe(&self, path: &str) -> Result<effectcraft_engine::project::Footage, String> {
use effectcraft_engine::project::{Footage, FootageKind};
Ok(Footage { path: path.into(), kind: FootageKind::Still, width: 64, height: 32, has_video: true, codec: "PNG".into(), ..Default::default() })
}
}
/// `importFile(new ImportOptions(file))` imports just the picked file unless `sequence` is set (#475).
#[test]
fn import_options_sequence_picks_one_still_or_the_run() {
use effectcraft_engine::project::{FootageKind, ItemKind};
let dir = std::env::temp_dir().join(format!("ec-script-seq-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
for n in ["shot_0001.png", "shot_0002.png", "shot_0003.png"] {
std::fs::write(dir.join(n), b"").unwrap();
}
let pick = dir.join("shot_0002.png").to_string_lossy().replace('\\', "/");
let mut s = session();
s.importer = Some(Arc::new(Stills));
let kind_of = |s: &Session, name: &str| {
let it = s.project.items.values().find(|i| i.name == name).unwrap_or_else(|| panic!("no item {name}"));
let ItemKind::Footage(f) = &it.kind else { panic!("footage") };
f.kind
};
ok(&mut s, &format!("var io = new ImportOptions(new File('{pick}')); app.project.importFile(io);"));
assert_eq!(kind_of(&s, "shot_0002.png"), FootageKind::Still);
ok(&mut s, &format!("var io = new ImportOptions(new File('{pick}')); io.sequence = true; app.project.importFile(io);"));
assert_eq!(kind_of(&s, "shot_[0001-0003].png"), FootageKind::Sequence);
let _ = std::fs::remove_dir_all(&dir);
}