dora_ssr/dora/platformer/
target_allow.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_targetallow_release(raw: i64);
11	fn platformer_targetallow_set_terrain_allowed(slf: i64, val: i32);
12	fn platformer_targetallow_is_terrain_allowed(slf: i64) -> i32;
13	fn platformer_targetallow_allow(slf: i64, relation: i32, allow: i32);
14	fn platformer_targetallow_is_allow(slf: i64, relation: i32) -> i32;
15	fn platformer_targetallow_to_value(slf: i64) -> i32;
16	fn platformer_targetallow_new() -> i64;
17	fn platformer_targetallow_with_value(value: i32) -> i64;
18}
19/// A struct to specifies how a bullet object should interact with other game objects or units based on their relationship.
20pub struct TargetAllow { raw: i64 }
21impl Drop for TargetAllow {
22	fn drop(&mut self) { unsafe { platformer_targetallow_release(self.raw); } }
23}
24impl TargetAllow {
25	pub(crate) fn raw(&self) -> i64 {
26		self.raw
27	}
28	pub(crate) fn from(raw: i64) -> TargetAllow {
29		TargetAllow { raw: raw }
30	}
31	/// Sets whether the bullet object can collide with terrain.
32	pub fn set_terrain_allowed(&mut self, val: bool) {
33		unsafe { platformer_targetallow_set_terrain_allowed(self.raw(), if val { 1 } else { 0 }) };
34	}
35	/// Gets whether the bullet object can collide with terrain.
36	pub fn is_terrain_allowed(&self) -> bool {
37		return unsafe { platformer_targetallow_is_terrain_allowed(self.raw()) != 0 };
38	}
39	/// Allows or disallows the bullet object to interact with a game object or unit, based on their relationship.
40	///
41	/// # Arguments
42	///
43	/// * `relation` - The relationship between the bullet object and the other game object or unit.
44	/// * `allow` - Whether the bullet object should be allowed to interact.
45	pub fn allow(&mut self, relation: crate::dora::platformer::Relation, allow: bool) {
46		unsafe { platformer_targetallow_allow(self.raw(), relation as i32, if allow { 1 } else { 0 }); }
47	}
48	/// Determines whether the bullet object is allowed to interact with a game object or unit, based on their relationship.
49	///
50	/// # Arguments
51	///
52	/// * `relation` - The relationship between the bullet object and the other game object or unit.
53	///
54	/// # Returns
55	///
56	/// * `bool` - Whether the bullet object is allowed to interact.
57	pub fn is_allow(&mut self, relation: crate::dora::platformer::Relation) -> bool {
58		unsafe { return platformer_targetallow_is_allow(self.raw(), relation as i32) != 0; }
59	}
60	/// Converts the object to a value that can be used for interaction settings.
61	///
62	/// # Returns
63	///
64	/// * `usize` - The value that can be used for interaction settings.
65	pub fn to_value(&mut self) -> i32 {
66		unsafe { return platformer_targetallow_to_value(self.raw()); }
67	}
68	/// Creates a new TargetAllow object with default settings.
69	pub fn new() -> crate::dora::platformer::TargetAllow {
70		unsafe { return crate::dora::platformer::TargetAllow::from(platformer_targetallow_new()); }
71	}
72	/// Creates a new TargetAllow object with the specified value.
73	///
74	/// # Arguments
75	///
76	/// * `value` - The value to use for the new TargetAllow object.
77	pub fn with_value(value: i32) -> crate::dora::platformer::TargetAllow {
78		unsafe { return crate::dora::platformer::TargetAllow::from(platformer_targetallow_with_value(value)); }
79	}
80}