From dba2d061ac88cd106ca88100f209f5582e70846b Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 6 Dec 2022 09:57:47 -0600 Subject: [PATCH 1/6] Bump dependencies and upgrade to gdnative-rust 0.11. --- Cargo.toml | 8 ++--- src/lib.rs | 87 ++++++++++++++++++++++++++---------------------------- 2 files changed, 46 insertions(+), 49 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a4eb004..8127f9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,9 +8,9 @@ edition = "2018" crate-type = ["staticlib", "cdylib"] [dependencies] -env_logger = "0.8" -gdnative = "0.9" -tts = "0.15" +env_logger = "0.10" +gdnative = "0.11" +tts = "0.25" [target.'cfg(windows)'.dependencies] -tolk = { version = "0.3", optional = true } +tolk = { version = "0.5", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 8e193e8..59800b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,9 @@ use std::sync::mpsc::{channel, Receiver}; use gdnative::prelude::*; -use tts::{Features, UtteranceId, TTS as Tts}; +use tts::{Features, Tts, UtteranceId}; #[derive(NativeClass)] -#[inherit(Reference)] struct Utterance(pub(crate) Option); #[methods] @@ -21,6 +20,7 @@ enum Msg { UtteranceStop(UtteranceId), } +#[allow(clippy::upper_case_acronyms)] #[derive(NativeClass)] #[inherit(Node)] #[register_with(Self::register)] @@ -62,7 +62,7 @@ impl TTS { fn register(builder: &ClassBuilder) { builder - .add_property("rate") + .property("rate") .with_getter(|this: &TTS, _| match this.0.get_rate() { Ok(rate) => rate, _ => 0., @@ -84,7 +84,7 @@ impl TTS { }) .done(); builder - .add_property("min_rate") + .property("min_rate") .with_getter(|this: &TTS, _| { let Features { rate: rate_supported, @@ -98,7 +98,7 @@ impl TTS { }) .done(); builder - .add_property("max_rate") + .property("max_rate") .with_getter(|this: &TTS, _| { let Features { rate: rate_supported, @@ -112,7 +112,7 @@ impl TTS { }) .done(); builder - .add_property("normal_rate") + .property("normal_rate") .with_getter(|this: &TTS, _| { let Features { rate: rate_supported, @@ -126,12 +126,12 @@ impl TTS { }) .done(); builder - .add_property("can_detect_screen_reader") + .property("can_detect_screen_reader") .with_getter(|_: &TTS, _| cfg!(all(windows, features = "tolk"))) .done(); #[allow(unreachable_code)] builder - .add_property("has_screen_reader") + .property("has_screen_reader") .with_getter(|_: &TTS, _| { #[cfg(all(windows, features = "tolk"))] { @@ -142,7 +142,7 @@ impl TTS { }) .done(); builder - .add_property("can_detect_is_speaking") + .property("can_detect_is_speaking") .with_getter(|this: &TTS, _| { let Features { is_speaking: is_speaking_supported, @@ -152,7 +152,7 @@ impl TTS { }) .done(); builder - .add_property("is_speaking") + .property("is_speaking") .with_getter(|this: &TTS, _| { let Features { is_speaking: is_speaking_supported, @@ -167,38 +167,37 @@ impl TTS { } }) .done(); - builder.add_signal(Signal { - name: "utterance_begin", - args: &[SignalArgument { - name: "utterance", + builder + .signal("utterance_begin") + .with_param_custom(SignalParam { + name: "utterance".into(), default: Variant::default(), export_info: ExportInfo::new(VariantType::Object), usage: PropertyUsage::DEFAULT, - }], - }); - builder.add_signal(Signal { - name: "utterance_end", - args: &[SignalArgument { - name: "utterance", + }) + .done(); + builder + .signal("utterance_end") + .with_param_custom(SignalParam { + name: "utterance".into(), default: Variant::default(), export_info: ExportInfo::new(VariantType::Object), usage: PropertyUsage::DEFAULT, - }], - }); - builder.add_signal(Signal { - name: "utterance_stop", - args: &[SignalArgument { - name: "utterance", + }) + .done(); + builder + .signal("utterance_stop") + .with_param_custom(SignalParam { + name: "utterance".into(), default: Variant::default(), export_info: ExportInfo::new(VariantType::Object), usage: PropertyUsage::DEFAULT, - }], - }); + }) + .done(); } - #[export] - fn speak(&mut self, _owner: &Node, message: GodotString, interrupt: bool) -> Variant { - let message = message.to_string(); + #[method] + fn speak(&mut self, message: String, interrupt: bool) -> Variant { if let Ok(id) = self.0.speak(message, interrupt) { let utterance: Instance = Instance::new(); if id.is_some() { @@ -212,13 +211,13 @@ impl TTS { } } - #[export] - fn stop(&mut self, _owner: &Node) { + #[method] + fn stop(&mut self) { self.0.stop().expect("Failed to stop"); } - #[export] - fn is_rate_supported(&mut self, _owner: &Node) -> bool { + #[method] + fn is_rate_supported(&mut self) -> bool { let Features { rate: rate_supported, .. @@ -226,8 +225,8 @@ impl TTS { rate_supported } - #[export] - fn are_utterance_callbacks_supported(&mut self, _owner: &Node) -> bool { + #[method] + fn are_utterance_callbacks_supported(&mut self) -> bool { let Features { utterance_callbacks: supported, .. @@ -235,8 +234,8 @@ impl TTS { supported } - #[export] - fn _process(&mut self, owner: &Node, _delta: f32) { + #[method] + fn _process(&mut self, #[base] base: &Node, _delta: f32) { if let Ok(msg) = self.1.try_recv() { match msg { Msg::UtteranceBegin(utterance_id) => { @@ -244,21 +243,21 @@ impl TTS { utterance .map_mut(|u, _| u.0 = Some(utterance_id)) .expect("Failed to set utterance ID"); - owner.emit_signal("utterance_begin", &[utterance.owned_to_variant()]); + base.emit_signal("utterance_begin", &[utterance.owned_to_variant()]); } Msg::UtteranceEnd(utterance_id) => { let utterance: Instance = Instance::new(); utterance .map_mut(|u, _| u.0 = Some(utterance_id)) .expect("Failed to set utterance ID"); - owner.emit_signal("utterance_end", &[utterance.owned_to_variant()]); + base.emit_signal("utterance_end", &[utterance.owned_to_variant()]); } Msg::UtteranceStop(utterance_id) => { let utterance: Instance = Instance::new(); utterance .map_mut(|u, _| u.0 = Some(utterance_id)) .expect("Failed to set utterance ID"); - owner.emit_signal("utterance_stop", &[utterance.owned_to_variant()]); + base.emit_signal("utterance_stop", &[utterance.owned_to_variant()]); } } } @@ -271,6 +270,4 @@ fn init(handle: InitHandle) { handle.add_class::(); } -godot_gdnative_init!(); -godot_nativescript_init!(init); -godot_gdnative_terminate!(); +godot_init!(init); From f21d3357e98fe5564b62db59f899d7c21d8bec75 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 7 Dec 2022 09:39:52 -0600 Subject: [PATCH 2/6] Update dependencies from most recent work. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8127f9b..f655490 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["staticlib", "cdylib"] [dependencies] env_logger = "0.10" gdnative = "0.11" -tts = "0.25" +tts = { version = "0.25", features = ["tolk"] } [target.'cfg(windows)'.dependencies] tolk = { version = "0.5", optional = true } From 6d48c23e3e05811157514b3077646510b7629495 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 12 Dec 2022 07:45:08 -0600 Subject: [PATCH 3/6] Test on ubuntu-20.04 for older libc releases. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b8b4850..d31271c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ jobs: name: Check strategy: matrix: - os: [windows-latest, ubuntu-latest, macos-latest] + os: [windows-latest, ubuntu-20.04, macos-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 From 2dba6d0a5521fd8736a178dade29e2df346b28aa Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 12 Dec 2022 08:18:06 -0600 Subject: [PATCH 4/6] Revert "Test on ubuntu-20.04 for older libc releases." Ubuntu 20.04 doesn't appear to be supported by the Godot Rust bindings due to only shipping glibc 2.31 when 2.32 is the minimum required version. This reverts commit 6d48c23e3e05811157514b3077646510b7629495. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d31271c..b8b4850 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ jobs: name: Check strategy: matrix: - os: [windows-latest, ubuntu-20.04, macos-latest] + os: [windows-latest, ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 From d83b3689f5313d83923a6e59888d7a4094950f30 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Fri, 16 Dec 2022 10:24:32 -0600 Subject: [PATCH 5/6] Simplify screen reader detection code to use `Tts` APIs. --- Cargo.toml | 5 +---- src/lib.rs | 12 ++---------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f655490..3670773 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,4 @@ crate-type = ["staticlib", "cdylib"] [dependencies] env_logger = "0.10" gdnative = "0.11" -tts = { version = "0.25", features = ["tolk"] } - -[target.'cfg(windows)'.dependencies] -tolk = { version = "0.5", optional = true } +tts = { version = "0.25", features = ["tolk"] } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 59800b1..992d584 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,19 +127,11 @@ impl TTS { .done(); builder .property("can_detect_screen_reader") - .with_getter(|_: &TTS, _| cfg!(all(windows, features = "tolk"))) + .with_getter(|_: &TTS, _| cfg!(windows)) .done(); - #[allow(unreachable_code)] builder .property("has_screen_reader") - .with_getter(|_: &TTS, _| { - #[cfg(all(windows, features = "tolk"))] - { - let tolk = tolk::Tolk::new(); - return tolk.detect_screen_reader().is_some(); - } - false - }) + .with_getter(|_, _| Tts::screen_reader_available()) .done(); builder .property("can_detect_is_speaking") From 5abf6317ef0af14be9881a195b11d9b3dafe97c7 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Fri, 16 Dec 2022 10:46:29 -0600 Subject: [PATCH 6/6] Remove missing features. --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 91d3013..3321176 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,7 +32,7 @@ jobs: - uses: Swatinem/rust-cache@v1 - run: | choco install -qy llvm - cargo build --features tolk --features tts/tolk --release + cargo build --release move target windows - uses: actions/upload-artifact@v1 with: