commit 8aca79dfab39919333d2313364e5fd53708dbf5c Author: Nolan Darilek Date: Wed May 18 13:04:58 2022 -0500 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..be8064a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +*.dll +Cargo.lock \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..0e996a2 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "bevy_synthizer" +version = "0.1.0" +authors = ["Nolan Darilek "] +license = "MIT OR Apache-2.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1" +bevy = { version = "0.7", default-features = false } +derive_more = "0.99" +synthizer = { git = "https://github.com/synthizer/synthizer-rs" } \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c74962d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Nolan Darilek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/assets/footstep.wav b/assets/footstep.wav new file mode 100644 index 0000000..7861287 Binary files /dev/null and b/assets/footstep.wav differ diff --git a/examples/game.rs b/examples/game.rs new file mode 100644 index 0000000..66bea1e --- /dev/null +++ b/examples/game.rs @@ -0,0 +1,72 @@ +use std::f32; + +use bevy::{asset::LoadState, prelude::*}; +use bevy_synthizer::*; + +#[derive(Component, Deref, DerefMut)] +struct RotationTimer(Timer); + +impl Default for RotationTimer { + fn default() -> Self { + Self(Timer::from_seconds(30., true)) + } +} + +#[derive(Default)] +struct AssetHandles { + sounds: Vec, + loaded: bool, +} + +fn setup(asset_server: Res, mut handles: ResMut) { + handles.sounds = asset_server.load_folder(".").expect("Failed to load sfx"); +} + +fn load_and_create( + mut commands: Commands, + asset_server: Res, + mut handles: ResMut, +) { + if handles.loaded { + return; + } + handles.loaded = asset_server + .get_group_load_state(handles.sounds.iter().map(|handle| handle.id)) + == LoadState::Loaded; + if handles.loaded { + commands + .spawn() + .insert(Listener) + .insert(Transform::default()) + .insert(RotationTimer::default()); + let handle = handles.sounds[0].clone(); + let buffer = asset_server.get_handle(handle); + commands + .spawn() + .insert(Transform::from_translation(Vec3::new(15., 0., 0.))) + .insert(Sound { + buffer, + looping: true, + ..default() + }); + } +} + +fn rotate_listener(time: Res