Add teanet-rust
This commit is contained in:
parent
ecaa5537a2
commit
edc23b3e8c
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ godot/.godot/
|
||||
godot/android/
|
||||
|
||||
rust/target
|
||||
target
|
||||
5
rust/Cargo.lock → Cargo.lock
generated
5
rust/Cargo.lock → Cargo.lock
generated
@ -129,6 +129,7 @@ name = "quakeball"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"godot",
|
||||
"teanet",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -140,6 +141,10 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "teanet"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
5
Cargo.toml
Normal file
5
Cargo.toml
Normal file
@ -0,0 +1,5 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"rust",
|
||||
"teanet-rust"
|
||||
]
|
||||
@ -8,4 +8,4 @@ crate-type = ["cdylib"] # Compile this crate to a dynamic C library.
|
||||
|
||||
[dependencies]
|
||||
godot = "0.5.4"
|
||||
|
||||
teanet = { path = "../teanet-rust" }
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use godot::{prelude::*, tools::get_autoload_by_name};
|
||||
use teanet::Peer;
|
||||
|
||||
use crate::ui::cli::{CLI_GLOBAL_NAME, CliColor, CommandLinePanel};
|
||||
|
||||
#[derive(GodotClass)]
|
||||
#[class(base=Node)]
|
||||
pub struct NetworkManager {
|
||||
peer: Option<PeerKind>,
|
||||
|
||||
base: Base<Node>,
|
||||
}
|
||||
|
||||
@ -15,7 +18,7 @@ pub const NETWORK_SINGLETON_NAME: &str = "NetworkManagerGlob";
|
||||
#[godot_api]
|
||||
impl INode for NetworkManager {
|
||||
fn init(base: Base<Node>) -> Self {
|
||||
NetworkManager { base }
|
||||
NetworkManager { peer: None, base }
|
||||
}
|
||||
|
||||
fn ready(&mut self) {
|
||||
@ -34,14 +37,25 @@ impl INode for NetworkManager {
|
||||
|
||||
impl NetworkManager {
|
||||
pub fn host(&mut self, port: u32) {
|
||||
if self.peer.is_none() {
|
||||
get_autoload_by_name::<CommandLinePanel>(CLI_GLOBAL_NAME)
|
||||
.bind_mut()
|
||||
.publish_message(format!("Hosting server at {}", port), CliColor::Info);
|
||||
self.peer = Some(PeerKind::Server(Peer::default(), port));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn join(&mut self, addr: SocketAddr) {
|
||||
if self.peer.is_none() {
|
||||
get_autoload_by_name::<CommandLinePanel>(CLI_GLOBAL_NAME)
|
||||
.bind_mut()
|
||||
.publish_message(format!("Joining server at {}", addr), CliColor::Info);
|
||||
self.peer = Some(PeerKind::Client(Peer::default(), addr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum PeerKind {
|
||||
Client(Peer, SocketAddr),
|
||||
Server(Peer, u32),
|
||||
}
|
||||
|
||||
1
teanet-rust
Submodule
1
teanet-rust
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit e2960002a23ee61dccaafd6951de16fc17c0ee19
|
||||
Loading…
Reference in New Issue
Block a user