Update Rust dependencies and get this thing actually working.

This commit is contained in:
Nolan Darilek 2019-09-03 08:54:36 -05:00
parent 36278ca6ae
commit b7b32e16a7
2 changed files with 41 additions and 32 deletions

View File

@ -2,15 +2,16 @@
name = "godot-tts" name = "godot-tts"
version = "0.1.0" version = "0.1.0"
authors = ["Nolan Darilek <nolan@thewordnerd.info>"] authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
edition = "2018"
[lib] [lib]
crate-type = ["cdylib"] crate-type = ["cdylib"]
[dependencies] [dependencies]
gdnative = {git = "https://github.com/GodotNativeTools/godot-rust"} gdnative = { path = "../godot-rust/gdnative" }
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
speech-dispatcher = "0.2" speech-dispatcher = "0.3"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
tolk = "0.1" tolk = "0.1"

View File

@ -1,49 +1,57 @@
#[macro_use] use gdnative::*;
extern crate gdnative as godot;
#[cfg(unix)]
extern crate speech_dispatcher;
#[cfg(windows)]
extern crate tolk;
#[cfg(unix)] #[cfg(unix)]
use speech_dispatcher::{Connection, Mode, Priority}; use speech_dispatcher::{Connection, Mode, Priority};
#[cfg(windows)] #[cfg(windows)]
use tolk::Tolk; use tolk::Tolk;
godot_class! { #[derive(gdnative::NativeClass)]
class TTS: godot::Object { #[inherit(gdnative::Node)]
fields { struct TTS(
#[cfg(unix)] #[cfg(unix)]
connection: Connection, Connection,
#[cfg(windows)] #[cfg(windows)]
tolk: Tolk, Tolk,
} );
setup(_builder) { #[methods]
impl TTS {
fn _init(_owner: gdnative::Node) -> Self {
#[cfg(unix)]
{
let connection = Connection::open("godot", "godot", "godot", Mode::Single);
Self(connection)
} }
#[cfg(windows)]
Self(Tolk::new())
}
constructor(header) { #[export]
TTS { fn speak(&mut self, _owner: Node, message: GodotString, interrupt: bool) {
header, let message = message.to_string();
#[cfg(unix)] println!("{}: {}", message, interrupt);
connection: Connection::open("godot", "godot", "godot", Mode::Single), #[cfg(unix)]
#[cfg(windows)] {
tolk: Tolk::new(), if interrupt {
self.0.cancel();
}
if message != "" {
self.0.say(Priority::Important, message);
} }
} }
}
export fn speak(&mut self) { #[export]
#[cfg(unix)] fn stop(&mut self, _owner: Node) {
{ #[cfg(unix)]
self.connection.say(Priority::Important, "Hello, world.".to_string()); {
} self.0.cancel();
} }
} }
} }
fn init(handle: godot::init::InitHandle) { fn init(handle: gdnative::init::InitHandle) {
TTS::register_class(handle); handle.add_class::<TTS>();
} }
godot_gdnative_init!(); godot_gdnative_init!();