sorta fixed loading cells, but now limited cellpitch is not respected...

main
Elijah Voigt 2 weeks ago
parent ee8a70cc16
commit bd1cb17c36

@ -1,3 +1,7 @@
#![allow(clippy::complexity)]
// Only because of FromTemplat macros unfortunately...
#![allow(dead_code)]
use bevy::{ use bevy::{
feathers::{containers::*, theme::ThemeProps}, feathers::{containers::*, theme::ThemeProps},
ui::{Checked, InteractionDisabled}, ui::{Checked, InteractionDisabled},
@ -590,6 +594,7 @@ fn new_cell(
sinks: &Query<Entity, With<AudioSink>>, sinks: &Query<Entity, With<AudioSink>>,
sim_state: &Res<State<SimulationPlayback>>, sim_state: &Res<State<SimulationPlayback>>,
audio_state: &Res<State<AudioPlayback>>, audio_state: &Res<State<AudioPlayback>>,
pitch_map: &Res<PitchMap>,
) -> impl Scene { ) -> impl Scene {
let c = Coordinates { x, y }; let c = Coordinates { x, y };
@ -605,14 +610,19 @@ fn new_cell(
let playback_settings = PlaybackSettings::ONCE.with_volume(volume); let playback_settings = PlaybackSettings::ONCE.with_volume(volume);
info!("using coordinates {:?}", c);
info!("cell_pitch: {:?}", pitch_map.coordinates_cell_pitch(&c));
info!("pitch map {:?}", pitch_map);
info!("cell assets materials: {:#?}", cell_assets.materials);
bsn! { bsn! {
Cell Cell
Coordinates { x, y } Coordinates { x, y }
template_value(playback_settings) template_value(playback_settings)
template_value(Transform::from_translation(c.as_translation() + Vec3::new(0.0, 0.0, 1.0))) template_value(Transform::from_translation(c.as_translation() + Vec3::new(0.0, 0.0, 1.0)))
template_value(Mesh2dTemplate(cell_assets.mesh.clone().into())) template_value(Mesh2dTemplate(cell_assets.mesh.clone().into()))
// TODO: template_value(AudioPlayerTemplate(cell_assets.pitches.get(&pitch_map.coordinates_cell_pitch(c)).unwrap().clone().into())) template_value(AudioPlayerTemplate(cell_assets.pitches.get(&pitch_map.coordinates_cell_pitch(&c)).unwrap().clone().into()))
// TODO: template_value(MeshMaterial2dTemplate(cell_assets.materials.get(&pitch_map.coordinates_cell_pitch(c)).unwrap().clone().into())) template_value(MeshMaterial2dTemplate(cell_assets.materials.get(&pitch_map.coordinates_cell_pitch(&c)).unwrap().clone().into()))
} }
} }
@ -623,6 +633,7 @@ fn cell_lifecycle(
query: Query<Entity, With<AudioSink>>, query: Query<Entity, With<AudioSink>>,
sim_state: Res<State<SimulationPlayback>>, sim_state: Res<State<SimulationPlayback>>,
audio_state: Res<State<AudioPlayback>>, audio_state: Res<State<AudioPlayback>>,
pitch_map: Res<PitchMap>,
) { ) {
reader.read().for_each(|msg| match msg { reader.read().for_each(|msg| match msg {
Lifecycle::Alive(c) => { Lifecycle::Alive(c) => {
@ -634,6 +645,7 @@ fn cell_lifecycle(
&query, &query,
&sim_state, &sim_state,
&audio_state, &audio_state,
&pitch_map,
)); ));
} }
Lifecycle::Dead(e) => { Lifecycle::Dead(e) => {
@ -657,7 +669,7 @@ fn cooldown_secs(input: f32) -> impl FnMut(Local<Timer>, Res<Time>) -> bool + Cl
// Scale grid with background? // Scale grid with background?
// Pan camera: click and drag // Pan camera: click and drag
#[derive(Resource, Default)] #[derive(Resource, Default, Debug)]
struct CellAssets { struct CellAssets {
pitches: HashMap<CellPitch, Handle<Pitch>>, pitches: HashMap<CellPitch, Handle<Pitch>>,
materials: HashMap<CellPitch, Handle<ColorMaterial>>, materials: HashMap<CellPitch, Handle<ColorMaterial>>,
@ -759,10 +771,9 @@ impl CellPitch {
..default() ..default()
}) })
} }
}
fn load_audio_tones(mut pitches: ResMut<Assets<Pitch>>, mut cell_assets: ResMut<CellAssets>) { fn iter_all() -> impl Iterator<Item = Self> {
let notes = [ [
Note::A, Note::A,
Note::ASharp, Note::ASharp,
Note::B, Note::B,
@ -775,15 +786,19 @@ fn load_audio_tones(mut pitches: ResMut<Assets<Pitch>>, mut cell_assets: ResMut<
Note::FSharp, Note::FSharp,
Note::G, Note::G,
Note::GSharp, Note::GSharp,
]; ].into_iter().flat_map(|note| {
let octaves = -5..6; (-5..6).map(move |octave| {
CellPitch {
octaves.for_each(|octave| {
notes.iter().for_each(|note| {
let cell_pitch = CellPitch {
note: note.clone(), note: note.clone(),
octave, octave,
}; }
})
})
}
}
fn load_audio_tones(mut pitches: ResMut<Assets<Pitch>>, mut cell_assets: ResMut<CellAssets>) {
CellPitch::iter_all().for_each(|cell_pitch| {
let frequency = cell_pitch.to_frequency(); let frequency = cell_pitch.to_frequency();
let duration = Duration::from_secs(100); let duration = Duration::from_secs(100);
debug!( debug!(
@ -796,7 +811,6 @@ fn load_audio_tones(mut pitches: ResMut<Assets<Pitch>>, mut cell_assets: ResMut<
}); });
cell_assets.pitches.insert(cell_pitch, handle); cell_assets.pitches.insert(cell_pitch, handle);
}); });
});
debug_assert_eq!(cell_assets.pitches.iter().len(), 132); debug_assert_eq!(cell_assets.pitches.iter().len(), 132);
} }
@ -831,22 +845,11 @@ fn load_materials(
mut cell_assets: ResMut<CellAssets>, mut cell_assets: ResMut<CellAssets>,
mut materials: ResMut<Assets<ColorMaterial>>, mut materials: ResMut<Assets<ColorMaterial>>,
) { ) {
// Up to 11 octaves total
let vertical = -5..6;
debug_assert_eq!(vertical.len(), 11);
// 12 total colors supported
let horizontal = -6..6;
debug_assert_eq!(horizontal.len(), 12);
let tile_handle = server.load(TILE); let tile_handle = server.load(TILE);
vertical.for_each(|x| { CellPitch::iter_all().for_each(|cell_pitch| {
horizontal.clone().for_each(|y| {
let c = Coordinates { x, y };
let pitch = c.to_cell_pitch();
let handle = { let handle = {
let color = pitch.to_color(); let color = cell_pitch.to_color();
let texture = Some(tile_handle.clone()); let texture = Some(tile_handle.clone());
let color_material = ColorMaterial { let color_material = ColorMaterial {
color, color,
@ -855,8 +858,7 @@ fn load_materials(
}; };
materials.add(color_material) materials.add(color_material)
}; };
cell_assets.materials.insert(pitch, handle); cell_assets.materials.insert(cell_pitch, handle);
});
}); });
debug_assert_eq!(cell_assets.materials.iter().len(), 132); debug_assert_eq!(cell_assets.materials.iter().len(), 132);
} }
@ -945,7 +947,7 @@ fn toggle_interactive<T: Component + States + PartialEq>(
}) })
} }
#[derive(Resource)] #[derive(Resource, Debug)]
struct PitchMap { struct PitchMap {
notes: Vec<Note>, notes: Vec<Note>,
octaves_up: usize, octaves_up: usize,

Loading…
Cancel
Save