(
ctx: &mut ScriptContext<'_, API>,
root: String,
)
| 26 | }; |
| 27 | use std::borrow::Cow; |
| 28 | use std::fs; |
| 29 | use std::path::{Path, PathBuf}; |
| 30 | use std::str::FromStr; |
| 31 | pub fn open_project<API: ScriptAPI + ?Sized>( |
| 32 | ctx: &mut ScriptContext<'_, API>, |
| 33 | root: String, |
| 34 | ) -> Result<(), String> { |
| 35 | clear_preview(ctx); |
| 36 | clear_scene_doc_cache(); |
| 37 | clear_editor_tree_icon_cache(); |
| 38 | let root_path = PathBuf::from(&root); |
| 39 | validate_project_root(&root_path)?; |
| 40 | editor_file_watch::retain_project_scan_job(&root_path); |
| 41 | let project_text = |
| 42 | FileMod::load_string(root_path.join("project.toml").to_string_lossy().as_ref()) |
| 43 | .map_err(|err| err.to_string())?; |
| 44 | let project_name = parse_project_name(&project_text).unwrap_or_else(|| { |
| 45 | root_path |
| 46 | .file_name() |
| 47 | .and_then(|v| v.to_str()) |
| 48 | .unwrap_or("Perro Project") |
| 49 | .to_string() |
| 50 | }); |
| 51 | let file_paths = scan_res_paths(&root_path)?; |
| 52 | let scene_paths = file_paths |
| 53 | .iter() |
| 54 | .filter(|path| path.ends_with(".scn")) |
| 55 | .cloned() |
| 56 | .collect::<Vec<_>>(); |
| 57 | let initial_scene = editor_manager::project_main_scene(&project_text) |
| 58 | .filter(|path| scene_paths.iter().any(|scene| scene == path)) |
| 59 | .or_else(|| scene_paths.first().cloned()); |
| 60 | let log = format!( |
| 61 | "open project\nroot: {}\nscenes: {}", |
| 62 | root_path.display(), |
| 63 | scene_paths.len() |
| 64 | ); |
| 65 | |
| 66 | crate::scripts::ui::editor_inspector_values::clear_script_schema_cache(); |
| 67 | load_editor_shell(ctx)?; |
| 68 | |
| 69 | let _ = with_state_mut!(ctx.run, EditorState, ctx.id, |state| { |
| 70 | state.project_root = root_path.to_string_lossy().to_string(); |
| 71 | state.project_name = project_name; |
| 72 | state.file_paths = file_paths; |
| 73 | state.file_scope.clear(); |
| 74 | state.file_expanded_paths.clear(); |
| 75 | state.file_expanded_paths.push("res://".to_string()); |
| 76 | state.scene_paths = scene_paths; |
| 77 | state.open_paths.clear(); |
| 78 | state.scene_sessions.clear(); |
| 79 | state.active_asset_path.clear(); |
| 80 | state.active_open = 0; |
| 81 | state.doc_text.clear(); |
| 82 | state.scene_undo_stack.clear(); |
| 83 | state.scene_redo_stack.clear(); |
| 84 | state.preview_scene_paths.clear(); |
| 85 | state.preview_root = 0; |
no test coverage detected