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

View File

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