(ctx: &mut ScriptContext<'_, API>, node_type_name: &str)
| 907 | None |
| 908 | } |
| 909 | |
| 910 | pub fn asset_kind_for_path(path: &str) -> Option<perro_scene::SceneAssetKind> { |
| 911 | if editor_files::kind_label(path) == "image" { |
| 912 | return Some(perro_scene::SceneAssetKind::Texture); |
| 913 | } |
| 914 | if path.ends_with(".glb") || path.ends_with(".gltf") { |
| 915 | return Some(perro_scene::SceneAssetKind::Model); |
| 916 | } |
| 917 | if path.ends_with(".pmesh") || path.ends_with(".obj") || path.ends_with(".fbx") { |
| 918 | return Some(perro_scene::SceneAssetKind::Mesh); |
| 919 | } |
| 920 | if path.ends_with(".pmat") { |
| 921 | return Some(perro_scene::SceneAssetKind::Material); |
| 922 | } |
| 923 | if path.ends_with(".panim") { |
| 924 | return Some(perro_scene::SceneAssetKind::Animation); |
| 925 | } |
| 926 | if path.ends_with(".panimtree") { |
| 927 | return Some(perro_scene::SceneAssetKind::AnimationTree); |
| 928 | } |
| 929 | if path.ends_with(".pskel") || path.ends_with(".pskel2d") || path.ends_with(".pskel3d") { |
| 930 | return Some(perro_scene::SceneAssetKind::Skeleton); |
| 931 | } |
| 932 | if path.ends_with(".ppart") { |
| 933 | return Some(perro_scene::SceneAssetKind::ParticleProfile); |
| 934 | } |
| 935 | if path.ends_with(".ptileset") { |
| 936 | return Some(perro_scene::SceneAssetKind::TileSet); |
| 937 | } |
| 938 | if path.ends_with(".uistyle") { |
| 939 | return Some(perro_scene::SceneAssetKind::UiStyle); |
| 940 | } |
| 941 | None |
| 942 | } |
| 943 | |
| 944 | pub fn asset_field_value( |
| 945 | path: &str, |
| 946 | kind: perro_scene::SceneAssetKind, |
| 947 | glb_mesh_index: usize, |
| 948 | ) -> String { |
| 949 | match kind { |
| 950 | perro_scene::SceneAssetKind::Mesh if is_gltf_path(path) => { |
| 951 | format!("{path}:mesh[{glb_mesh_index}]") |
| 952 | } |
| 953 | _ => path.to_string(), |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | pub fn add_node<API: ScriptAPI + ?Sized>(ctx: &mut ScriptContext<'_, API>, node_type_name: &str) { |
| 958 | set_add_node_popup(ctx, false); |
| 959 | let Ok(node_type) = perro_scene::NodeType::from_str(node_type_name) else { |
| 960 | set_log(ctx, &format!("add node fail\nbad type: {node_type_name}")); |
| 961 | return; |
| 962 | }; |
| 963 | let mut msg = "no open scene".to_string(); |
| 964 | let _ = with_state_mut!(ctx.run, EditorState, ctx.id, |state| { |
| 965 | if state.doc_text.is_empty() { |
| 966 | return; |
no test coverage detected