dora_ssr/dora/platformer/
unit.rs1extern "C" {
10 fn platformer_unit_type() -> i32;
11 fn platformer_unit_set_playable(slf: i64, val: i64);
12 fn platformer_unit_get_playable(slf: i64) -> i64;
13 fn platformer_unit_set_detect_distance(slf: i64, val: f32);
14 fn platformer_unit_get_detect_distance(slf: i64) -> f32;
15 fn platformer_unit_set_attack_range(slf: i64, val: i64);
16 fn platformer_unit_get_attack_range(slf: i64) -> i64;
17 fn platformer_unit_set_face_right(slf: i64, val: i32);
18 fn platformer_unit_is_face_right(slf: i64) -> i32;
19 fn platformer_unit_set_receiving_decision_trace(slf: i64, val: i32);
20 fn platformer_unit_is_receiving_decision_trace(slf: i64) -> i32;
21 fn platformer_unit_set_decision_tree(slf: i64, val: i64);
22 fn platformer_unit_get_decision_tree(slf: i64) -> i64;
23 fn platformer_unit_is_on_surface(slf: i64) -> i32;
24 fn platformer_unit_get_ground_sensor(slf: i64) -> i64;
25 fn platformer_unit_get_detect_sensor(slf: i64) -> i64;
26 fn platformer_unit_get_attack_sensor(slf: i64) -> i64;
27 fn platformer_unit_get_unit_def(slf: i64) -> i64;
28 fn platformer_unit_get_current_action(slf: i64) -> i64;
29 fn platformer_unit_get_width(slf: i64) -> f32;
30 fn platformer_unit_get_height(slf: i64) -> f32;
31 fn platformer_unit_get_entity(slf: i64) -> i64;
32 fn platformer_unit_attach_action(slf: i64, name: i64) -> i64;
33 fn platformer_unit_remove_action(slf: i64, name: i64);
34 fn platformer_unit_remove_all_actions(slf: i64);
35 fn platformer_unit_get_action(slf: i64, name: i64) -> i64;
36 fn platformer_unit_each_action(slf: i64, func0: i32, stack0: i64);
37 fn platformer_unit_start(slf: i64, name: i64) -> i32;
38 fn platformer_unit_stop(slf: i64);
39 fn platformer_unit_is_doing(slf: i64, name: i64) -> i32;
40 fn platformer_unit_new(unit_def: i64, physics_world: i64, entity: i64, pos: i64, rot: f32) -> i64;
41 fn platformer_unit_with_store(unit_def_name: i64, physics_world_name: i64, entity: i64, pos: i64, rot: f32) -> i64;
42}
43use crate::dora::IObject;
44use crate::dora::IBody;
45impl IBody for Unit { }
46use crate::dora::INode;
47impl INode for Unit { }
48pub struct Unit { raw: i64 }
50crate::dora_object!(Unit);
51impl Unit {
52 pub(crate) fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
53 (unsafe { platformer_unit_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
54 match raw {
55 0 => None,
56 _ => Some(Box::new(Unit { raw: raw }))
57 }
58 })
59 }
60 pub fn set_playable(&mut self, val: &dyn crate::dora::IPlayable) {
62 unsafe { platformer_unit_set_playable(self.raw(), val.raw()) };
63 }
64 pub fn get_playable(&self) -> crate::dora::Playable {
66 return unsafe { crate::dora::Playable::from(platformer_unit_get_playable(self.raw())).unwrap() };
67 }
68 pub fn set_detect_distance(&mut self, val: f32) {
70 unsafe { platformer_unit_set_detect_distance(self.raw(), val) };
71 }
72 pub fn get_detect_distance(&self) -> f32 {
74 return unsafe { platformer_unit_get_detect_distance(self.raw()) };
75 }
76 pub fn set_attack_range(&mut self, val: &crate::dora::Size) {
78 unsafe { platformer_unit_set_attack_range(self.raw(), val.into_i64()) };
79 }
80 pub fn get_attack_range(&self) -> crate::dora::Size {
82 return unsafe { crate::dora::Size::from(platformer_unit_get_attack_range(self.raw())) };
83 }
84 pub fn set_face_right(&mut self, val: bool) {
86 unsafe { platformer_unit_set_face_right(self.raw(), if val { 1 } else { 0 }) };
87 }
88 pub fn is_face_right(&self) -> bool {
90 return unsafe { platformer_unit_is_face_right(self.raw()) != 0 };
91 }
92 pub fn set_receiving_decision_trace(&mut self, val: bool) {
94 unsafe { platformer_unit_set_receiving_decision_trace(self.raw(), if val { 1 } else { 0 }) };
95 }
96 pub fn is_receiving_decision_trace(&self) -> bool {
98 return unsafe { platformer_unit_is_receiving_decision_trace(self.raw()) != 0 };
99 }
100 pub fn set_decision_tree(&mut self, val: &str) {
103 unsafe { platformer_unit_set_decision_tree(self.raw(), crate::dora::from_string(val)) };
104 }
105 pub fn get_decision_tree(&self) -> String {
108 return unsafe { crate::dora::to_string(platformer_unit_get_decision_tree(self.raw())) };
109 }
110 pub fn is_on_surface(&self) -> bool {
112 return unsafe { platformer_unit_is_on_surface(self.raw()) != 0 };
113 }
114 pub fn get_ground_sensor(&self) -> crate::dora::Sensor {
116 return unsafe { crate::dora::Sensor::from(platformer_unit_get_ground_sensor(self.raw())).unwrap() };
117 }
118 pub fn get_detect_sensor(&self) -> crate::dora::Sensor {
120 return unsafe { crate::dora::Sensor::from(platformer_unit_get_detect_sensor(self.raw())).unwrap() };
121 }
122 pub fn get_attack_sensor(&self) -> crate::dora::Sensor {
124 return unsafe { crate::dora::Sensor::from(platformer_unit_get_attack_sensor(self.raw())).unwrap() };
125 }
126 pub fn get_unit_def(&self) -> crate::dora::Dictionary {
128 return unsafe { crate::dora::Dictionary::from(platformer_unit_get_unit_def(self.raw())).unwrap() };
129 }
130 pub fn get_current_action(&self) -> crate::dora::platformer::UnitAction {
132 return unsafe { crate::dora::platformer::UnitAction::from(platformer_unit_get_current_action(self.raw())).unwrap() };
133 }
134 pub fn get_width(&self) -> f32 {
136 return unsafe { platformer_unit_get_width(self.raw()) };
137 }
138 pub fn get_height(&self) -> f32 {
140 return unsafe { platformer_unit_get_height(self.raw()) };
141 }
142 pub fn get_entity(&self) -> crate::dora::Entity {
144 return unsafe { crate::dora::Entity::from(platformer_unit_get_entity(self.raw())).unwrap() };
145 }
146 pub fn attach_action(&mut self, name: &str) -> crate::dora::platformer::UnitAction {
156 unsafe { return crate::dora::platformer::UnitAction::from(platformer_unit_attach_action(self.raw(), crate::dora::from_string(name))).unwrap(); }
157 }
158 pub fn remove_action(&mut self, name: &str) {
164 unsafe { platformer_unit_remove_action(self.raw(), crate::dora::from_string(name)); }
165 }
166 pub fn remove_all_actions(&mut self) {
168 unsafe { platformer_unit_remove_all_actions(self.raw()); }
169 }
170 pub fn get_action(&mut self, name: &str) -> Option<crate::dora::platformer::UnitAction> {
180 unsafe { return crate::dora::platformer::UnitAction::from(platformer_unit_get_action(self.raw(), crate::dora::from_string(name))); }
181 }
182 pub fn each_action(&mut self, mut visitor_func: Box<dyn FnMut(&crate::dora::platformer::UnitAction)>) {
188 let mut stack0 = crate::dora::CallStack::new();
189 let stack_raw0 = stack0.raw();
190 let func_id0 = crate::dora::push_function(Box::new(move || {
191 visitor_func(&crate::dora::platformer::UnitAction::from(stack0.pop_i64().unwrap()).unwrap())
192 }));
193 unsafe { platformer_unit_each_action(self.raw(), func_id0, stack_raw0); }
194 }
195 pub fn start(&mut self, name: &str) -> bool {
205 unsafe { return platformer_unit_start(self.raw(), crate::dora::from_string(name)) != 0; }
206 }
207 pub fn stop(&mut self) {
209 unsafe { platformer_unit_stop(self.raw()); }
210 }
211 pub fn is_doing(&mut self, name: &str) -> bool {
221 unsafe { return platformer_unit_is_doing(self.raw(), crate::dora::from_string(name)) != 0; }
222 }
223 pub fn new(unit_def: &crate::dora::Dictionary, physics_world: &dyn crate::dora::IPhysicsWorld, entity: &crate::dora::Entity, pos: &crate::dora::Vec2, rot: f32) -> Unit {
237 unsafe { return Unit { raw: platformer_unit_new(unit_def.raw(), physics_world.raw(), entity.raw(), pos.into_i64(), rot) }; }
238 }
239 pub fn with_store(unit_def_name: &str, physics_world_name: &str, entity: &crate::dora::Entity, pos: &crate::dora::Vec2, rot: f32) -> Unit {
253 unsafe { return Unit { raw: platformer_unit_with_store(crate::dora::from_string(unit_def_name), crate::dora::from_string(physics_world_name), entity.raw(), pos.into_i64(), rot) }; }
254 }
255}