From 8000d0a048ed401a783bcde6f454989dd9310681 Mon Sep 17 00:00:00 2001 From: Kubat <maelle.martin@proton.me> Date: Sun, 20 Apr 2025 10:44:33 +0200 Subject: [PATCH] Add a dummy struct to see if it works on the godot side --- src/dummy.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 9 ++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/dummy.rs diff --git a/src/dummy.rs b/src/dummy.rs new file mode 100644 index 0000000..8dae158 --- /dev/null +++ b/src/dummy.rs @@ -0,0 +1,59 @@ +use godot::{ + classes::{ISprite2D, Sprite2D}, + prelude::*, +}; + +#[derive(GodotClass)] +#[class(base=Sprite2D)] +struct Player { + speed: f64, + angular_speed: f64, + + base: Base<Sprite2D>, +} + +#[godot_api] +impl ISprite2D for Player { + fn init(base: Base<Sprite2D>) -> Self { + godot_print!("Hello, world!"); // Prints to the Godot console + + Self { + speed: 400.0, + angular_speed: std::f64::consts::PI, + base, + } + } + + fn physics_process(&mut self, delta: f64) { + // GDScript code: + // + // rotation += angular_speed * delta + // var velocity = Vector2.UP.rotated(rotation) * speed + // position += velocity * delta + + let radians = (self.angular_speed * delta) as f32; + self.base_mut().rotate(radians); + + let rotation = self.base().get_rotation(); + let velocity = Vector2::UP.rotated(rotation) * self.speed as f32; + self.base_mut().translate(velocity * delta as f32); + + // or verbose: + // let this = self.base_mut(); + // this.set_position( + // this.position() + velocity * delta as f32 + // ); + } +} + +#[godot_api] +impl Player { + #[func] + fn increase_speed(&mut self, amount: f64) { + self.speed += amount; + self.base_mut().emit_signal("speed_increased", &[]); + } + + #[signal] + fn speed_increased(); +} diff --git a/src/lib.rs b/src/lib.rs index 61907f0..61bc0a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,3 +2,12 @@ pub mod spell; pub mod expr; pub mod state; pub mod error; + +pub mod dummy; + +use godot::prelude::*; + +struct GrimoireExtension; + +#[gdextension] +unsafe impl ExtensionLibrary for GrimoireExtension {} -- GitLab