ask for tiletype

This commit is contained in:
zoe 2022-05-04 16:46:58 +02:00
parent 9d9348faca
commit 539727ca3f
11 changed files with 68 additions and 64 deletions

View file

@ -9,10 +9,11 @@ edition = "2021"
crate-type = ["cdylib"]
[dependencies]
gdnative = "0.10"
tokio = {version = "1.18.0", features = ["sync"]}
lazy_static = "1.4.0"
pathfinding = "3.0.12"
gdnative = {version = "0.10", features = ["async"]}
strum = { version = "0.24", features = ["derive"] }
# tokio = {version = "1.18.0", features = ["sync"]}
# lazy_static = "1.4.0"
# pathfinding = "3.0.12"
toml = "0.5.9"
[profile.dev.package."*"]

View file

@ -1,26 +1,21 @@
use gdnative::prelude::*;
use lazy_static::lazy_static;
use tokio::sync::RwLock;
mod saves;
mod world;
lazy_static! {
static ref WORLD: RwLock<Vec<Vec<Vec<u8>>>> = RwLock::new(vec![vec![vec![]]]);
}
#[derive(NativeClass)]
#[inherit(Node)]
#[register_with(Self::register)]
pub struct StateServer {
#[property]
a: u64,
world: world::World,
}
#[methods]
impl StateServer {
fn new(_owner: &Node) -> Self {
StateServer { a: 14 }
StateServer {
world: world::World::new(0, 0, 0),
}
}
#[export]
@ -39,9 +34,15 @@ impl StateServer {
}
#[export]
fn generate_world(&self, _owner: &Node, xsize: usize, ysize: usize, zsize: usize) {
let mut new_world = world::World::new(xsize, ysize, zsize);
new_world.generate();
fn generate_world(&mut self, _owner: &Node, xsize: usize, ysize: usize, zsize: usize) {
self.world = world::World::new(xsize, ysize, zsize);
self.world.generate();
_owner.emit_signal("request_full_reload", &[]);
}
#[export]
fn get_tile_at(&mut self, _owner: &Node, x: usize, y: usize, z: usize) -> &str {
self.world.get_tile_at(x, y, z).kind_to_string()
}
}
@ -53,5 +54,6 @@ impl StateServer {
.with_param("position", VariantType::Vector3)
.with_param("new_type", VariantType::GodotString)
.done();
builder.signal("request_full_reload").done();
}
}

View file

@ -1,5 +1,3 @@
use gdnative::prelude::*;
mod tiles;
pub struct World {
@ -10,6 +8,9 @@ pub struct World {
}
impl World {
pub fn get_tile_at(&self, x: usize, y: usize, z: usize) -> &tiles::Tile{
&self.tiles[x][y][z]
}
pub fn generate(&mut self) {
self.tiles = get_vec3(self.xsize, self.ysize, self.zsize);
for x in 0..self.xsize {

View file

@ -1,4 +1,6 @@
#[derive(Debug, Clone)]
use strum::AsRefStr;
#[derive(Debug, Clone, AsRefStr)]
pub enum Tiletypes {
Air,
Water,
@ -16,4 +18,7 @@ impl Tile {
pub fn new(kind: Tiletypes) -> Tile {
Tile { kind }
}
pub fn kind_to_string(&self) -> &str {
self.kind.as_ref()
}
}