dora_ssr/dora/platformer/visual.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_visual_type() -> i32;
11 fn platformer_visual_is_playing(slf: i64) -> i32;
12 fn platformer_visual_start(slf: i64);
13 fn platformer_visual_stop(slf: i64);
14 fn platformer_visual_auto_remove(slf: i64) -> i64;
15 fn platformer_visual_new(name: i64) -> i64;
16}
17use crate::dora::IObject;
18use crate::dora::INode;
19impl INode for Visual { }
20/// A struct represents a visual effect object like Particle, Frame Animation or just a Sprite.
21pub struct Visual { raw: i64 }
22crate::dora_object!(Visual);
23impl Visual {
24 pub(crate) fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
25 (unsafe { platformer_visual_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
26 match raw {
27 0 => None,
28 _ => Some(Box::new(Visual { raw: raw }))
29 }
30 })
31 }
32 /// Gets whether the visual effect is currently playing or not.
33 pub fn is_playing(&self) -> bool {
34 return unsafe { platformer_visual_is_playing(self.raw()) != 0 };
35 }
36 /// Starts playing the visual effect.
37 pub fn start(&mut self) {
38 unsafe { platformer_visual_start(self.raw()); }
39 }
40 /// Stops playing the visual effect.
41 pub fn stop(&mut self) {
42 unsafe { platformer_visual_stop(self.raw()); }
43 }
44 /// Automatically removes the visual effect from the game world when it finishes playing.
45 ///
46 /// # Returns
47 ///
48 /// * `Visual` - The same `Visual` object that was passed in as a parameter.
49 pub fn auto_remove(&mut self) -> crate::dora::platformer::Visual {
50 unsafe { return crate::dora::platformer::Visual::from(platformer_visual_auto_remove(self.raw())).unwrap(); }
51 }
52 /// Creates a new `Visual` object with the specified name.
53 ///
54 /// # Arguments
55 ///
56 /// * `name` - The name of the new `Visual` object. Could be a particle file, a frame animation file or an image file.
57 ///
58 /// # Returns
59 ///
60 /// * `Visual` - The new `Visual` object.
61 pub fn new(name: &str) -> Visual {
62 unsafe { return Visual { raw: platformer_visual_new(crate::dora::from_string(name)) }; }
63 }
64}