dora_ssr/dora/action_def.rs
1/* Copyright (c) 2016-2026 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 actiondef_release(raw: i64);
11 fn actiondef_prop(duration: f32, start: f32, stop: f32, prop: i32, easing: i32) -> i64;
12 fn actiondef_tint(duration: f32, start: i32, stop: i32, easing: i32) -> i64;
13 fn actiondef_roll(duration: f32, start: f32, stop: f32, easing: i32) -> i64;
14 fn actiondef_spawn(defs: i64) -> i64;
15 fn actiondef_sequence(defs: i64) -> i64;
16 fn actiondef_delay(duration: f32) -> i64;
17 fn actiondef_show() -> i64;
18 fn actiondef_hide() -> i64;
19 fn actiondef_event(event_name: i64, msg: i64) -> i64;
20 fn actiondef_move_to(duration: f32, start: i64, stop: i64, easing: i32) -> i64;
21 fn actiondef_scale(duration: f32, start: f32, stop: f32, easing: i32) -> i64;
22 fn actiondef_frame(clip_str: i64, duration: f32) -> i64;
23 fn actiondef_frame_with_frames(clip_str: i64, duration: f32, frames: i64) -> i64;
24}
25pub struct ActionDef { raw: i64 }
26impl Drop for ActionDef {
27 fn drop(&mut self) { unsafe { actiondef_release(self.raw); } }
28}
29impl ActionDef {
30 pub(crate) fn raw(&self) -> i64 {
31 self.raw
32 }
33 pub(crate) fn from(raw: i64) -> ActionDef {
34 ActionDef { raw: raw }
35 }
36 /// Creates a new action definition object to change a property of a node.
37 ///
38 /// # Arguments
39 ///
40 /// * `duration` - The duration of the action.
41 /// * `start` - The starting value of the property.
42 /// * `stop` - The ending value of the property.
43 /// * `prop` - The property to change.
44 /// * `easing` - The easing function to use.
45 ///
46 /// # Returns
47 ///
48 /// * `ActionDef` - A new ActionDef object.
49 pub fn prop(duration: f32, start: f32, stop: f32, prop: crate::dora::Property, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
50 unsafe { return crate::dora::ActionDef::from(actiondef_prop(duration, start, stop, prop as i32, easing as i32)); }
51 }
52 /// Creates a new action definition object to change the color of a node.
53 ///
54 /// # Arguments
55 ///
56 /// * `duration` - The duration of the action.
57 /// * `start` - The starting color.
58 /// * `stop` - The ending color.
59 /// * `easing` - The easing function to use.
60 ///
61 /// # Returns
62 ///
63 /// * `ActionDef` - A new ActionDef object.
64 pub fn tint(duration: f32, start: &crate::dora::Color3, stop: &crate::dora::Color3, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
65 unsafe { return crate::dora::ActionDef::from(actiondef_tint(duration, start.to_rgb() as i32, stop.to_rgb() as i32, easing as i32)); }
66 }
67 /// Creates a new action definition object to rotate a node by smallest angle.
68 ///
69 /// # Arguments
70 ///
71 /// * `duration` - The duration of the action.
72 /// * `start` - The starting angle.
73 /// * `stop` - The ending angle.
74 /// * `easing` - The easing function to use.
75 ///
76 /// # Returns
77 ///
78 /// * `ActionDef` - A new ActionDef object.
79 pub fn roll(duration: f32, start: f32, stop: f32, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
80 unsafe { return crate::dora::ActionDef::from(actiondef_roll(duration, start, stop, easing as i32)); }
81 }
82 /// Creates a new action definition object to run a group of actions in parallel.
83 ///
84 /// # Arguments
85 ///
86 /// * `defs` - The actions to run in parallel.
87 ///
88 /// # Returns
89 ///
90 /// * `ActionDef` - A new ActionDef object.
91 pub fn spawn(defs: &Vec<crate::dora::ActionDef>) -> crate::dora::ActionDef {
92 unsafe { return crate::dora::ActionDef::from(actiondef_spawn(crate::dora::Vector::from_action_def(defs))); }
93 }
94 /// Creates a new action definition object to run a group of actions in sequence.
95 ///
96 /// # Arguments
97 ///
98 /// * `defs` - The actions to run in sequence.
99 ///
100 /// # Returns
101 ///
102 /// * `ActionDef` - A new ActionDef object.
103 pub fn sequence(defs: &Vec<crate::dora::ActionDef>) -> crate::dora::ActionDef {
104 unsafe { return crate::dora::ActionDef::from(actiondef_sequence(crate::dora::Vector::from_action_def(defs))); }
105 }
106 /// Creates a new action definition object to delay the execution of following action.
107 ///
108 /// # Arguments
109 ///
110 /// * `duration` - The duration of the delay.
111 ///
112 /// # Returns
113 ///
114 /// * `ActionDef` - A new ActionDef object.
115 pub fn delay(duration: f32) -> crate::dora::ActionDef {
116 unsafe { return crate::dora::ActionDef::from(actiondef_delay(duration)); }
117 }
118 /// Creates a new action definition object to show a node.
119 pub fn show() -> crate::dora::ActionDef {
120 unsafe { return crate::dora::ActionDef::from(actiondef_show()); }
121 }
122 /// Creates a new action definition object to hide a node.
123 pub fn hide() -> crate::dora::ActionDef {
124 unsafe { return crate::dora::ActionDef::from(actiondef_hide()); }
125 }
126 /// Creates a new action definition object to emit an event.
127 ///
128 /// # Arguments
129 ///
130 /// * `eventName` - The name of the event to emit.
131 /// * `msg` - The message to send with the event.
132 ///
133 /// # Returns
134 ///
135 /// * `ActionDef` - A new ActionDef object.
136 pub fn event(event_name: &str, msg: &str) -> crate::dora::ActionDef {
137 unsafe { return crate::dora::ActionDef::from(actiondef_event(crate::dora::from_string(event_name), crate::dora::from_string(msg))); }
138 }
139 /// Creates a new action definition object to move a node.
140 ///
141 /// # Arguments
142 ///
143 /// * `duration` - The duration of the action.
144 /// * `start` - The starting position.
145 /// * `stop` - The ending position.
146 /// * `easing` - The easing function to use.
147 ///
148 /// # Returns
149 ///
150 /// * `ActionDef` - A new ActionDef object.
151 pub fn move_to(duration: f32, start: &crate::dora::Vec2, stop: &crate::dora::Vec2, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
152 unsafe { return crate::dora::ActionDef::from(actiondef_move_to(duration, start.into_i64(), stop.into_i64(), easing as i32)); }
153 }
154 /// Creates a new action definition object to scale a node.
155 ///
156 /// # Arguments
157 ///
158 /// * `duration` - The duration of the action.
159 /// * `start` - The starting scale.
160 /// * `stop` - The ending scale.
161 /// * `easing` - The easing function to use.
162 ///
163 /// # Returns
164 ///
165 /// * `ActionDef` - A new ActionDef object.
166 pub fn scale(duration: f32, start: f32, stop: f32, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
167 unsafe { return crate::dora::ActionDef::from(actiondef_scale(duration, start, stop, easing as i32)); }
168 }
169 /// Creates a new action definition object to do a frame animation. Can only be performed on a Sprite node.
170 ///
171 /// # Arguments
172 ///
173 /// * `clipStr` - The name of the image clip, which is a sprite sheet. Can be "Image/file.png" and "Image/items.clip|itemA". Supports image file format: jpg, png, dds, pvr, ktx.
174 /// * `duration` - The duration of the action.
175 ///
176 /// # Returns
177 ///
178 /// * `ActionDef` - A new ActionDef object.
179 pub fn frame(clip_str: &str, duration: f32) -> crate::dora::ActionDef {
180 unsafe { return crate::dora::ActionDef::from(actiondef_frame(crate::dora::from_string(clip_str), duration)); }
181 }
182 /// Creates a new action definition object to do a frame animation with frames count for each frame. Can only be performed on a Sprite node.
183 ///
184 /// # Arguments
185 ///
186 /// * `clipStr` - The name of the image clip, which is a sprite sheet. Can be "Image/file.png" and "Image/items.clip|itemA". Supports image file format: jpg, png, dds, pvr, ktx.
187 /// * `duration` - The duration of the action.
188 /// * `frames` - The number of frames for each frame.
189 ///
190 /// # Returns
191 ///
192 /// * `Action` - A new Action object.
193 pub fn frame_with_frames(clip_str: &str, duration: f32, frames: &Vec<i32>) -> crate::dora::ActionDef {
194 unsafe { return crate::dora::ActionDef::from(actiondef_frame_with_frames(crate::dora::from_string(clip_str), duration, crate::dora::Vector::from_num(frames))); }
195 }
196}