(args: &[String], cwd: &Path)
| 455 | } |
| 456 | |
| 457 | pub(crate) fn new_scene_command(args: &[String], cwd: &Path) -> Result<(), String> { |
| 458 | let Some(raw_name) = parse_flag_value(args, "--name") else { |
| 459 | return Err("missing required flag `--name`".to_string()); |
| 460 | }; |
| 461 | let file_name = sanitize_scene_file_name(&raw_name)?; |
| 462 | let template = parse_scene_template(args)?; |
| 463 | |
| 464 | let project_dir = if let Some(raw_project) = parse_flag_value(args, "--path") { |
| 465 | resolve_local_path(&raw_project, cwd) |
| 466 | } else { |
| 467 | find_project_root(cwd).ok_or_else(|| { |
| 468 | "could not find project.toml. Run from a project directory or pass --path <project_dir>." |
| 469 | .to_string() |
| 470 | })? |
| 471 | }; |
| 472 | let project_dir = project_dir.canonicalize().unwrap_or(project_dir); |
| 473 | let content_root = resolve_content_root(&project_dir, args)?; |
| 474 | let content_prefix = resolve_content_prefix(args)?; |
| 475 | |
| 476 | let target_dir = if let Some(raw_path) = parse_flag_value(args, "--res") { |
| 477 | resolve_res_subdir(&raw_path, &content_root, &content_prefix)? |
| 478 | } else { |
| 479 | content_root |
| 480 | }; |
| 481 | |
| 482 | let target_path = target_dir.join(file_name); |
| 483 | let contents = match template { |
| 484 | SceneTemplate::TwoD => default_scene_2d(), |
| 485 | SceneTemplate::ThreeD => default_scene_3d(), |
| 486 | }; |
| 487 | write_new_file(&target_path, &contents)?; |
| 488 | println!( |
| 489 | "created scene at {}", |
| 490 | normalize_powershell_path(&target_path) |
| 491 | ); |
| 492 | maybe_open_file_in_editor(args, &target_path)?; |
| 493 | Ok(()) |
| 494 | } |
| 495 | |
| 496 | fn default_animation_panim(animation_name: &str) -> String { |
| 497 | r#"[Animation] |
no test coverage detected