MCPcopy Create free account
hub / github.com/PerroEngine/Perro / open_project

Function open_project

perro_editor/res/scripts/assets/editor_assets.rs:28–118  ·  view source on GitHub ↗
(
    ctx: &mut ScriptContext<'_, API>,
    root: String,
)

Source from the content-addressed store, hash-verified

26};
27use std::borrow::Cow;
28use std::fs;
29use std::path::{Path, PathBuf};
30use std::str::FromStr;
31pub 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;

Callers 3

open_project_dialogFunction · 0.85
open_recent_projectFunction · 0.85

Calls 15

clear_previewFunction · 0.85
clear_scene_doc_cacheFunction · 0.85
validate_project_rootFunction · 0.85
parse_project_nameFunction · 0.85
scan_res_pathsFunction · 0.85
project_main_sceneFunction · 0.85
load_editor_shellFunction · 0.85
add_recent_projectFunction · 0.85
set_project_managerFunction · 0.85
refresh_allFunction · 0.85
open_scene_pathFunction · 0.85

Tested by

no test coverage detected