From fdbba87b346c6020d7349d0c2cb3793fcdab25f3 Mon Sep 17 00:00:00 2001 From: cel Date: Sat, 16 Jul 2022 22:42:19 +0100 Subject: add menu and switch die code from rust to gdscript --- rust/src/game.rs | 44 ----------------------------------- rust/src/lib.rs | 6 ----- rust/src/spinning_cube.rs | 58 ----------------------------------------------- rust/src/test.rs | 58 ----------------------------------------------- 4 files changed, 166 deletions(-) delete mode 100644 rust/src/game.rs delete mode 100644 rust/src/spinning_cube.rs delete mode 100644 rust/src/test.rs (limited to 'rust/src') diff --git a/rust/src/game.rs b/rust/src/game.rs deleted file mode 100644 index 61b23ed..0000000 --- a/rust/src/game.rs +++ /dev/null @@ -1,44 +0,0 @@ -use gdnative::api::*; -use gdnative::prelude::*; - -/// The Game "class" -#[derive(NativeClass)] -#[inherit(Spatial)] -#[register_with(Self::register_builder)] -pub struct Game { - name: String, -} - -// __One__ `impl` block can have the `#[methods]` attribute, which will generate -// code to automatically bind any exported methods to Godot. -#[methods] -impl Game { - // Register the builder for methods, properties and/or signals. - fn register_builder(_builder: &ClassBuilder) { - godot_print!("Game builder is registered!"); - } - - /// The "constructor" of the class. - fn new(_owner: &Spatial) -> Self { - godot_print!("Game is created!"); - Game { - name: "".to_string(), - } - } - - // In order to make a method known to Godot, the #[export] attribute has to be used. - // In Godot script-classes do not actually inherit the parent class. - // Instead they are "attached" to the parent object, called the "owner". - // The owner is passed to every single exposed method. - #[export] - unsafe fn _ready(&mut self, _owner: &Spatial) { - // The `godot_print!` macro works like `println!` but prints to the Godot-editor - // output tab as well. - self.name = "Game".to_string(); - godot_print!("{} is ready!", self.name); - } - - // This function will be called in every frame - #[export] - unsafe fn _process(&self, _owner: &Spatial, _delta: f64) { } -} diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 30f4f2a..f683d35 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1,20 +1,14 @@ -mod game; -mod spinning_cube; mod buff_bounce; mod buff_phase; mod buff_trait; mod buff_ball; mod buff_extra; -mod test; mod basic_die; use gdnative::prelude::{godot_init, InitHandle}; // Function that registers all exposed classes to Godot fn init(handle: InitHandle) { - handle.add_class::(); - handle.add_class::(); - handle.add_class::(); handle.add_class::(); } diff --git a/rust/src/spinning_cube.rs b/rust/src/spinning_cube.rs deleted file mode 100644 index 41b429f..0000000 --- a/rust/src/spinning_cube.rs +++ /dev/null @@ -1,58 +0,0 @@ -use gdnative::api::*; -use gdnative::prelude::*; - -/// The SpinningCube "class" -#[derive(NativeClass)] -#[inherit(MeshInstance)] -#[register_with(Self::register_builder)] -pub struct SpinningCube { - start: Vector3, - time: f32, - #[property(path = "base/rotate_speed")] - rotate_speed: f64, -} - -// __One__ `impl` block can have the `#[methods]` attribute, which will generate -// code to automatically bind any exported methods to Godot. -#[methods] -impl SpinningCube { - // Register the builder for methods, properties and/or signals. - fn register_builder(_builder: &ClassBuilder) { - godot_print!("SpinningCube builder is registered!"); - } - - /// The "constructor" of the class. - fn new(_owner: &MeshInstance) -> Self { - SpinningCube { - start: Vector3::new(0.0, 0.0, 0.0), - time: 0.0, - rotate_speed: 0.05, - } - } - - // In order to make a method known to Godot, the #[export] attribute has to be used. - // In Godot script-classes do not actually inherit the parent class. - // Instead they are "attached" to the parent object, called the "owner". - // The owner is passed to every single exposed method. - #[export] - unsafe fn _ready(&mut self, owner: &MeshInstance) { - owner.set_physics_process(true); - } - - #[export] - unsafe fn _physics_process(&mut self, owner: &MeshInstance, delta: f64) { - use gdnative::api::SpatialMaterial; - - self.time += delta as f32; - owner.rotate_y(self.rotate_speed * delta); - - let offset = Vector3::new(0.0, 1.0, 0.0) * self.time.cos() * 0.5; - owner.set_translation(self.start + offset); - - if let Some(mat) = owner.get_surface_material(0) { - let mat = mat.assume_safe(); - let mat = mat.cast::().expect("Incorrect material"); - mat.set_albedo(Color::from_rgba(self.time.cos().abs(), 0.0, 0.0, 1.0)); - } - } -} diff --git a/rust/src/test.rs b/rust/src/test.rs deleted file mode 100644 index 6c0774f..0000000 --- a/rust/src/test.rs +++ /dev/null @@ -1,58 +0,0 @@ -use gdnative::api::*; -use gdnative::prelude::*; - -/// The SpinningCube "class" -#[derive(NativeClass)] -#[inherit(MeshInstance)] -#[register_with(Self::register_builder)] -pub struct SpinningCubeReverse { - start: Vector3, - time: f32, - #[property(path = "base/rotate_speed")] - rotate_speed: f64, -} - -// __One__ `impl` block can have the `#[methods]` attribute, which will generate -// code to automatically bind any exported methods to Godot. -#[methods] -impl SpinningCubeReverse { - // Register the builder for methods, properties and/or signals. - fn register_builder(_builder: &ClassBuilder) { - godot_print!("SpinningCube builder is registered!"); - } - - /// The "constructor" of the class. - fn new(_owner: &MeshInstance) -> Self { - SpinningCubeReverse { - start: Vector3::new(0.0, 0.0, 0.0), - time: 0.0, - rotate_speed: 0.05, - } - } - - // In order to make a method known to Godot, the #[export] attribute has to be used. - // In Godot script-classes do not actually inherit the parent class. - // Instead they are "attached" to the parent object, called the "owner". - // The owner is passed to every single exposed method. - #[export] - unsafe fn _ready(&mut self, owner: &MeshInstance) { - owner.set_physics_process(true); - } - - #[export] - unsafe fn _physics_process(&mut self, owner: &MeshInstance, delta: f64) { - use gdnative::api::SpatialMaterial; - - self.time += delta as f32; - owner.rotate_y(self.rotate_speed * delta * -1.0); - - let offset = Vector3::new(0.0, 1.0, 0.0) * self.time.cos() * 0.5; - owner.set_translation(self.start + offset); - - if let Some(mat) = owner.get_surface_material(0) { - let mat = mat.assume_safe(); - let mat = mat.cast::().expect("Incorrect material"); - mat.set_albedo(Color::from_rgba(self.time.cos().abs(), 0.0, 0.0, 1.0)); - } - } -} -- cgit