-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
cargo-features = ["edition2024", "profile-rustflags"] | ||
[package] | ||
name = "gdrust" | ||
version = "0.1.0" | ||
edition = "2021" | ||
edition = "2024" | ||
|
||
[dependencies] | ||
godot = { git = "https://github.com/godot-rust/gdext", branch = "master" } | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[profile.release] | ||
lto = true | ||
codegen-units = 1 | ||
strip = true | ||
rustflags = ["-D", "warnings"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mod block; | ||
mod block_drawer; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use godot::engine::{INode2D, Node2D}; | ||
use godot::obj::WithBaseField; | ||
use godot::prelude::*; | ||
|
||
#[derive(GodotClass)] | ||
#[class(base = Node2D)] | ||
struct BlockDrawer { | ||
base: Base<Node2D>, | ||
#[var] | ||
// x方向上的block数量 | ||
x: i32, | ||
#[var] | ||
// y方向上的block数量 | ||
y: i32, | ||
} | ||
|
||
#[godot_api] | ||
impl INode2D for BlockDrawer { | ||
fn init(base: Base<Node2D>) -> BlockDrawer { | ||
// godot_print!("BlockDrawer created from Godot Rust"); | ||
Self { | ||
x: Self::X_BLOCKS, | ||
y: Self::Y_BLOCKS, | ||
base, | ||
} | ||
} | ||
|
||
fn process(&mut self, delta: f64) {} | ||
|
||
fn draw(&mut self) {} | ||
} | ||
|
||
#[godot_api] | ||
impl BlockDrawer { | ||
#[constant] | ||
const X_BLOCKS: i32 = 10; | ||
#[constant] | ||
const Y_BLOCKS: i32 = 10; | ||
|
||
#[func] | ||
fn change_block_immediate(&mut self, x: i32, y: i32) { | ||
self.x = x; | ||
self.y = y; | ||
} | ||
|
||
#[func] | ||
fn change_block_gently(&mut self, x: i32, y: i32) {} | ||
|
||
#[func] | ||
fn get_y_min(&mut self) -> i32 { | ||
// self.base(). | ||
(self.base().get_viewport_rect().size.y - self.y as f32) as i32 | ||
} | ||
|
||
#[func] | ||
fn get_x_min(&mut self) -> i32 { | ||
// self.base(). | ||
(self.base().get_viewport_rect().size.x - self.x as f32) as i32 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters