diff --git a/godot/native/StateServer.tscn b/godot/native/StateServer.tscn new file mode 100644 index 0000000..d063c0e --- /dev/null +++ b/godot/native/StateServer.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://world/state_server.gdns" type="Script" id=1] + +[node name="StateServer" type="Node"] +script = ExtResource( 1 ) diff --git a/godot/native/libroutes_native.so b/godot/native/libroutes_native.so index b915661..1900fde 100755 Binary files a/godot/native/libroutes_native.so and b/godot/native/libroutes_native.so differ diff --git a/godot/world/StateApi.gd b/godot/world/StateApi.gd new file mode 100644 index 0000000..00331e5 --- /dev/null +++ b/godot/world/StateApi.gd @@ -0,0 +1,8 @@ +extends Node + +var server = preload("res://native/StateServer.tscn").instance() +# Called when the node enters the scene tree for the first time. +func _ready(): + add_child(server) + print(server.a) + server.foo() diff --git a/godot/world/state_server.gd b/godot/world/state_server.gd new file mode 100644 index 0000000..bf4a50c --- /dev/null +++ b/godot/world/state_server.gd @@ -0,0 +1,16 @@ +extends Node + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/godot/world/world.tscn b/godot/world/world.tscn index 3a0a9a3..ccf68fd 100644 --- a/godot/world/world.tscn +++ b/godot/world/world.tscn @@ -3,10 +3,13 @@ [ext_resource path="res://world/terrain/terrain.tres" type="TileSet" id=1] [ext_resource path="res://world/terrain.gd" type="Script" id=2] [ext_resource path="res://world/worldcam.gd" type="Script" id=3] -[ext_resource path="res://world/state_server.gdns" type="Script" id=4] +[ext_resource path="res://world/StateApi.gd" type="Script" id=5] [node name="World" type="Node2D"] +[node name="StateApi" type="Node" parent="."] +script = ExtResource( 5 ) + [node name="terrain" type="TileMap" parent="."] position = Vector2( -2, 0 ) mode = 1 @@ -27,6 +30,3 @@ format = 1 current = true zoom = Vector2( 0.4, 0.4 ) script = ExtResource( 3 ) - -[node name="state_server" type="Node" parent="."] -script = ExtResource( 4 ) diff --git a/routes-native/Cargo.toml b/routes-native/Cargo.toml index b125df0..ed9db05 100644 --- a/routes-native/Cargo.toml +++ b/routes-native/Cargo.toml @@ -10,3 +10,7 @@ crate-type = ["cdylib"] [dependencies] gdnative = "0.10" +tokio = {version = "1.18.0", features = ["sync"]} +lazy_static = "1.4.0" +strum = "0.24.0" +strum_macros = "0.24" diff --git "a/routes-native/\\" "b/routes-native/\\" new file mode 100644 index 0000000..d3de4a1 --- /dev/null +++ "b/routes-native/\\" @@ -0,0 +1,44 @@ +use gdnative::{export::hint::EnumHint, prelude::*}; +use lazy_static::lazy_static; +use std::{string::ToString, vec}; +use strum::IntoEnumIterator; +use strum_macros::{Display, EnumIter}; +use tokio::sync::RwLock; + +lazy_static! { + // static ref STATE: RwLock = RwLock::new(Vector3::new(1.0, 2.0, 3.0)); +} + +#[derive(Debug, EnumIter, Display, FromVariant, ToVariant)] +enum Terrain { + Earth, + Rock, + Sand, + Water, + Air, +} + +#[derive(NativeClass)] +#[inherit(Node)] +pub struct StateServer; + +#[methods] +impl StateServer { + fn new(_owner: &Node) -> Self { + StateServer + } + + #[export] + fn _ready(&self, _owner: &Node) { + // godot_print!("hello, state") + } + + #[export] + fn terrain_types(&self, _owner: &Node) -> EnumHint{ + let mut hints = vec![]; + for terrain in Terrain::iter() { + hints.push(terrain.to_string()); + } + EnumHint::new(hints) + } +} diff --git a/routes-native/src/stateserver.rs b/routes-native/src/stateserver.rs index 07ce5cf..90a1603 100644 --- a/routes-native/src/stateserver.rs +++ b/routes-native/src/stateserver.rs @@ -1,18 +1,46 @@ -use gdnative::prelude::*; +use gdnative::{export::hint::EnumHint, prelude::*}; +use lazy_static::lazy_static; +use std::{string::ToString, vec}; +use strum::IntoEnumIterator; +use strum_macros::{Display, EnumIter}; +use tokio::sync::RwLock; + +lazy_static! { + // static ref STATE: RwLock = RwLock::new(Vector3::new(1.0, 2.0, 3.0)); +} + +#[derive(Debug, EnumIter, Display, FromVariant, ToVariant)] +enum Terrain { + Earth, + Rock, + Sand, + Water, + Air, +} #[derive(NativeClass)] #[inherit(Node)] -pub struct StateServer; +pub struct StateServer { + #[property] + a: u8, +} #[methods] impl StateServer { fn new(_owner: &Node) -> Self { - StateServer + StateServer { + a: 9, + } } #[export] fn _ready(&self, _owner: &Node) { - godot_print!("hello, state") + godot_print!("hello, uwu") + } + + + #[export] + fn foo(&self, _owner: &Node) { + godot_print!("bar") } } -