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

Function frame_selected_node

perro_editor/res/scripts/scene/editor_nav.rs:1422–1469  ·  view source on GitHub ↗
(ctx: &mut ScriptContext<'_, API>)

Source from the content-addressed store, hash-verified

1420 (state.preview_camera_2d != 0).then(|| NodeID::from_u64(state.preview_camera_2d))
1421 }).unwrap_or_default()
1422 .or_else(|| find_named(ctx, "editor_camera_2d"));
1423 let Some(camera) = camera else {
1424 return;
1425 };
1426 let (pos, zoom) = with_state!(ctx.run, EditorState, ctx.id, |state| {
1427 (Vector2::new(state.cam2_x, state.cam2_y), state.cam2_zoom)
1428 }).unwrap_or_default();
1429 let _ = with_node_mut!(ctx.run, Camera2D, camera, |node| {
1430 node.active = false;
1431 node.zoom = zoom;
1432 });
1433 let _ = ctx
1434 .run
1435 .Nodes()
1436 .set_local_transform_2d(camera, Transform2D::new(pos, 0.0, Vector2::ONE));
1437}
1438
1439pub fn frame_selected_node<API: ScriptAPI + ?Sized>(ctx: &mut ScriptContext<'_, API>) {
1440 let framed = with_state_mut!(ctx.run, EditorState, ctx.id, |state| {
1441 let Some(key) = state.selected_key else {
1442 state.log = "frame fail\nselect node".to_string();
1443 return false;
1444 };
1445 if state.doc_text.is_empty() {
1446 state.log = "frame fail\nno open scene".to_string();
1447 return false;
1448 }
1449 let doc = cached_scene_doc_shared(&state.doc_text);
1450 let Some(node) = cached_scene_node(&state.doc_text, key) else {
1451 state.log = "frame fail\nmissing node".to_string();
1452 return false;
1453 };
1454 let name = doc.scene.key_name_or_id(node.key).to_string();
1455 if state.viewport_mode == "3D" {
1456 let point = find_vec3_value(&node.data, "position").unwrap_or(Vector3::ZERO);
1457 state.cam_x = point.x;
1458 state.cam_y = point.y + 3.0;
1459 state.cam_z = point.z + 8.0;
1460 state.cam_yaw = 0.0;
1461 state.cam_pitch = -0.32;
1462 state.log = format!("frame 3d\n{name}");
1463 return true;
1464 }
1465 if state.viewport_mode == "2D" {
1466 let point = find_vec2_value(&node.data, "position").unwrap_or(Vector2::ZERO);
1467 state.cam2_x = point.x;
1468 state.cam2_y = point.y;
1469 state.cam2_zoom = state.cam2_zoom.max(1.0);
1470 state.log = format!("frame 2d\n{name}");
1471 return true;
1472 }

Callers 2

update_editor_shortcutsFunction · 0.85
open_sidebar_selectionFunction · 0.85

Calls 4

apply_freecamFunction · 0.85
apply_freecam_2dFunction · 0.85
apply_viewport_canvasFunction · 0.85
refresh_allFunction · 0.85

Tested by

no test coverage detected