dora_ssr/dora/platformer/
face.rs

1/* Copyright (c) 2016-2025 Li Jin <dragon-fly@qq.com>
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8
9extern "C" {
10	fn platformer_face_type() -> i32;
11	fn platformer_face_add_child(slf: i64, face: i64);
12	fn platformer_face_to_node(slf: i64) -> i64;
13	fn platformer_face_new(face_str: i64, point: i64, scale: f32, angle: f32) -> i64;
14	fn platformer_face_with_func(func0: i32, stack0: i64, point: i64, scale: f32, angle: f32) -> i64;
15}
16use crate::dora::IObject;
17/// Represents a definition for a visual component of a game bullet or other visual item.
18pub struct Face { raw: i64 }
19crate::dora_object!(Face);
20impl Face {
21	pub(crate) fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
22		(unsafe { platformer_face_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
23			match raw {
24				0 => None,
25				_ => Some(Box::new(Face { raw: raw }))
26			}
27		})
28	}
29	/// Adds a child `Face` definition to it.
30	///
31	/// # Arguments
32	///
33	/// * `face` - The child `Face` to add.
34	pub fn add_child(&mut self, face: &crate::dora::platformer::Face) {
35		unsafe { platformer_face_add_child(self.raw(), face.raw()); }
36	}
37	/// Returns a node that can be added to a scene tree for rendering.
38	///
39	/// # Returns
40	///
41	/// * `Node` - The `Node` representing this `Face`.
42	pub fn to_node(&mut self) -> crate::dora::Node {
43		unsafe { return crate::dora::Node::from(platformer_face_to_node(self.raw())).unwrap(); }
44	}
45	/// Creates a new `Face` definition using the specified attributes.
46	///
47	/// # Arguments
48	///
49	/// * `face_str` - A string for creating the `Face` component. Could be 'Image/file.png' and 'Image/items.clip|itemA'.
50	/// * `point` - The position of the `Face` component.
51	/// * `scale` - The scale of the `Face` component.
52	/// * `angle` - The angle of the `Face` component.
53	///
54	/// # Returns
55	///
56	/// * `Face` - The new `Face` component.
57	pub fn new(face_str: &str, point: &crate::dora::Vec2, scale: f32, angle: f32) -> Face {
58		unsafe { return Face { raw: platformer_face_new(crate::dora::from_string(face_str), point.into_i64(), scale, angle) }; }
59	}
60	/// Creates a new `Face` definition using the specified attributes.
61	///
62	/// # Arguments
63	///
64	/// * `create_func` - A function that returns a `Node` representing the `Face` component.
65	/// * `point` - The position of the `Face` component.
66	/// * `scale` - The scale of the `Face` component.
67	/// * `angle` - The angle of the `Face` component.
68	///
69	/// # Returns
70	///
71	/// * `Face` - The new `Face` component.
72	pub fn with_func(mut create_func: Box<dyn FnMut() -> crate::dora::Node>, point: &crate::dora::Vec2, scale: f32, angle: f32) -> Face {
73		let mut stack0 = crate::dora::CallStack::new();
74		let stack_raw0 = stack0.raw();
75		let func_id0 = crate::dora::push_function(Box::new(move || {
76			let result = create_func();
77			stack0.push_object(&result);
78		}));
79		unsafe { return Face { raw: platformer_face_with_func(func_id0, stack_raw0, point.into_i64(), scale, angle) }; }
80	}
81}