fix threshold arrow alignment

This commit is contained in:
Emerald 2023-07-12 01:18:44 -04:00
parent 4449bacaa1
commit 92b9d8f752
Signed by: emerald
GPG Key ID: 420C9E1863CCB30F
6 changed files with 87 additions and 36 deletions

54
Cargo.lock generated
View File

@ -529,6 +529,37 @@ dependencies = [
"bevy",
]
[[package]]
name = "bevy_eventlistener"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef97c7e47f53b4ba7b20602154543c477b8185ff81063b726928a57bda554c7"
dependencies = [
"bevy_eventlistener_core",
"bevy_eventlistener_derive",
]
[[package]]
name = "bevy_eventlistener_core"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf23d3270e337b2b080d489b9a7dce181a4cb402809788bcbc155ef155903e2c"
dependencies = [
"bevy",
]
[[package]]
name = "bevy_eventlistener_derive"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5933d39e4aa1b151ecc174f83a4485f2589c641571bca3e8e57d69b73ac18258"
dependencies = [
"bevy_eventlistener_core",
"proc-macro2",
"quote",
"syn 2.0.18",
]
[[package]]
name = "bevy_framepace"
version = "0.12.1"
@ -696,10 +727,12 @@ dependencies = [
[[package]]
name = "bevy_mod_picking"
version = "0.13.0"
source = "git+https://github.com/aevyrie/bevy_mod_picking/?branch=ui-fix#084250b545094c6c7426249f893f9f10a44581f7"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0ed68aa654340ea966eef4c7442248be051bfe1fc058ccad8c28bc3fd8dfb36"
dependencies = [
"bevy",
"bevy_eventlistener",
"bevy_picking_core",
"bevy_picking_input",
"bevy_picking_ui",
@ -773,16 +806,19 @@ dependencies = [
[[package]]
name = "bevy_picking_core"
version = "0.1.0"
source = "git+https://github.com/aevyrie/bevy_mod_picking/?branch=ui-fix#084250b545094c6c7426249f893f9f10a44581f7"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a1fbf71e1063af644053ced66f8e2916d919f5845d20a2f52af051078253b91"
dependencies = [
"bevy",
"bevy_eventlistener",
]
[[package]]
name = "bevy_picking_input"
version = "0.1.0"
source = "git+https://github.com/aevyrie/bevy_mod_picking/?branch=ui-fix#084250b545094c6c7426249f893f9f10a44581f7"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1143a44db535ff4a7ece0a7050d50ef1e05a0360804b44c6c2cb3becbc7c8757"
dependencies = [
"bevy",
"bevy_picking_core",
@ -790,8 +826,9 @@ dependencies = [
[[package]]
name = "bevy_picking_ui"
version = "0.1.0"
source = "git+https://github.com/aevyrie/bevy_mod_picking/?branch=ui-fix#084250b545094c6c7426249f893f9f10a44581f7"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b59f7d65fb8d84d9fda7297cd9334148d3e09bbbbd5df04dc8d78ab1155972ec"
dependencies = [
"bevy",
"bevy_picking_core",
@ -1274,6 +1311,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bevy",
"bevy_eventlistener",
"bevy_framepace",
"bevy_mod_picking",
"bevy_mod_scripting",

View File

@ -2,32 +2,32 @@ set export
alias d := debug
watch := "cargo watch -q -c -x run"
dev:
-cargo tauri dev
{{watch}}
debug:
RUST_LOG=debug cargo tauri dev
RUST_LOG=debug {{watch}}
log RUST_LOG:
cargo tauri dev
log RUST_LOG: dev
build:
cargo tauri build
cd src-tauri && cargo generate-rpm
cp -r src-tauri/target/release/bundle bundle
cp -r src-tauri/target/generate-rpm bundle
cargo build
install:
@cargo tauri build -b none
build-release:
cargo build --release
install: build-release
@echo Copying binary to /usr/bin/cathode...
@sudo cp src-tauri/target/release/cathode /usr/bin/cathode
@sudo install target/release/cathode /usr/bin/cathode
@echo Installing desktop file...
@sudo cp src-tauri/cathode-tube.desktop /usr/share/applications/cathode-tube.desktop
@sudo cp src-tauri/application-cathode.xml /usr/share/mime/packages/application-cathode.xml
@sudo install desktop/cathode-tube.desktop /usr/share/applications/cathode-tube.desktop
@sudo install desktop/application-cathode.xml /usr/share/mime/packages/application-cathode.xml
@echo Installing icons...
@sudo cp src-tauri/icons/128x128.png /usr/share/icons/hicolor/128x128/apps/cathode-tube.png
@sudo cp src-tauri/icons/32x32.png /usr/share/icons/hicolor/32x32/apps/cathode-tube.png
@sudo cp src-tauri/icons/128x128@2x.png /usr/share/icons/hicolor/256x256/apps/cathode-tube.png
@sudo install desktop/icons/128x128.png /usr/share/icons/hicolor/128x128/apps/cathode-tube.png
@sudo install desktop/icons/32x32.png /usr/share/icons/hicolor/32x32/apps/cathode-tube.png
@sudo install desktop/icons/128x128@2x.png /usr/share/icons/hicolor/256x256/apps/cathode-tube.png
@sudo update-desktop-database
uninstall:

View File

@ -39,11 +39,14 @@ pub fn monitor(world: &mut World) {
.build_input_stream(
&config.config(),
move |data: &[f32], _: &InputCallbackInfo| {
*level.lock().unwrap() = data
let cur_level = { *level.lock().unwrap() };
*level.lock().unwrap() = (data
.iter()
.map(|e| e.abs() * *sens.lock().unwrap())
.max_by(|a, b| a.total_cmp(b))
.unwrap();
.unwrap()
* 0.5)
+ cur_level * 0.5;
},
move |err| {
error!("Audio error: {:?}", err);
@ -65,6 +68,15 @@ fn initialize() -> Result<Device> {
.for_each(|h| info!("> {:<10}", h.name()));
let host = cpal::default_host();
info!("Using audio host: {}", host.id().name());
info!("Available devices: ");
if let Ok(devices) = host.input_devices() {
devices.for_each(|d| {
info!(
"> {:<10}",
d.name().unwrap_or_else(|_| "Error getting name".into())
)
});
}
host.default_input_device()
.ok_or_else(|| anyhow!("No default input device"))
}

View File

@ -9,7 +9,7 @@ use bevy_mod_picking::prelude::*;
use bevy_tweening::TweeningPlugin;
use ray::RayPlugin;
use scripting::ScriptingPlugin;
use tube::TubePlugin;
use tube::{TriggerThreshold, TubePlugin};
use ui::{UiMessage, UiPlugin};
mod audio;
@ -56,8 +56,9 @@ fn main() {
.run();
}
fn logging(level: Res<MicLevel>) {
fn logging(level: Res<MicLevel>, threshold: Res<TriggerThreshold>) {
info!("Audio in: {}", level.lock().unwrap());
info!("Mic thresh: {}", **threshold);
}
fn setup(mut commands: Commands, sens: ResMut<MicSens>) {

View File

@ -84,7 +84,7 @@ fn setup(mut commands: Commands, ass: Res<AssetServer>) {
// }
}
const MAX_THRESHOLD: f32 = 5.0;
const MAX_THRESHOLD: f32 = 10.0;
fn audio_trigger(
mut mouth_state: ResMut<MouthState>,
mic_level: Res<MicLevel>,
@ -94,7 +94,7 @@ fn audio_trigger(
time: Res<Time>,
) {
let level = mic_level.lock().expect("Poisoned mutex");
// info!("{level}");
// info!("{}", ((**threshold / 100.) * MAX_THRESHOLD));
if *level > ((**threshold / 100.) * MAX_THRESHOLD) {
if buffer.finished() {
info!("Open mouth");

View File

@ -246,9 +246,9 @@ fn set_max_size<B: Component, C: Component>(
) {
let Ok(bar) = bar_q.get_single() else { return };
let Ok(other) = other.get_single() else { return };
commands.insert_resource(MaxPercent::<B>::new(
((bar.size().y - (other.size().y / 2.)) / bar.size().y) * 100.,
));
let size = ((bar.size().y - (other.size().y / 2.)) / bar.size().y) * 100.;
info!("{size}");
commands.insert_resource(MaxPercent::<B>::new(size));
}
pub(super) fn animate_mic_level(
@ -321,15 +321,15 @@ pub(super) fn react_mic_level_color(
fn handle_mic_thresh_set(
mut threshold: ResMut<TriggerThreshold>,
mut events: EventReader<ArrowDrag<MicLevelArrow>>,
mut styles: Query<&mut Style, With<MicLevelArrow>>,
mut styles: Query<(&mut Style, &Node), With<MicLevelArrow>>,
bar_q: Query<&Node, With<MicLevelContainer>>,
max_size: Res<MaxPercent<MicLevelContainer>>,
) {
for event in events.iter() {
let Ok(mut style) = styles.get_mut(event.target) else { continue };
let Ok((mut style, arrow)) = styles.get_mut(event.target) else { continue };
let Ok(bar) = bar_q.get_single() else { continue };
if let Val::Percent(pos) = style.position.bottom {
let delta = (event.delta.y / (bar.size().y + 16.)).clamp(-1., 1.) * 100.;
let delta = (event.delta.y / bar.size().y) * 100.;
let new_percent = (delta + pos).clamp(0., **max_size);
**threshold = new_percent;