mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-22 11:05:56 +00:00
Remove or guard unwrap
calls in rate getter/setter so they don't fail on unsupported synthesizers.
This commit is contained in:
parent
e233b97fff
commit
4429e5fb46
17
src/lib.rs
17
src/lib.rs
|
@ -28,8 +28,10 @@ impl NativeClass for TTS {
|
||||||
slider: true,
|
slider: true,
|
||||||
},
|
},
|
||||||
getter: |this: &TTS| {
|
getter: |this: &TTS| {
|
||||||
let rate = this.0.get_rate().unwrap();
|
match this.0.get_rate() {
|
||||||
rate / u8::MAX * 100
|
Ok(rate) => rate / u8::MAX * 100,
|
||||||
|
_ => 0,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setter: |this: &mut TTS, mut v: u8| {
|
setter: |this: &mut TTS, mut v: u8| {
|
||||||
if v > 100 {
|
if v > 100 {
|
||||||
|
@ -37,7 +39,12 @@ impl NativeClass for TTS {
|
||||||
}
|
}
|
||||||
let mut v = v as f32;
|
let mut v = v as f32;
|
||||||
v = v * u8::MAX as f32 / 100.;
|
v = v * u8::MAX as f32 / 100.;
|
||||||
this.0.set_rate(v as u8).unwrap();
|
let Features {
|
||||||
|
rate: rate_supported, ..
|
||||||
|
} = this.0.supported_features();
|
||||||
|
if rate_supported {
|
||||||
|
this.0.set_rate(v as u8).unwrap();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
usage: PropertyUsage::DEFAULT,
|
usage: PropertyUsage::DEFAULT,
|
||||||
});
|
});
|
||||||
|
@ -65,9 +72,9 @@ impl TTS {
|
||||||
#[export]
|
#[export]
|
||||||
fn is_rate_supported(&mut self, _owner: Node) -> bool {
|
fn is_rate_supported(&mut self, _owner: Node) -> bool {
|
||||||
let Features {
|
let Features {
|
||||||
rate: rate_feature, ..
|
rate: rate_supported, ..
|
||||||
} = self.0.supported_features();
|
} = self.0.supported_features();
|
||||||
rate_feature
|
rate_supported
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user