subplate works
This commit is contained in:
+36
-8
@@ -3,12 +3,14 @@ use crate::basic::{IntoImage, Table};
|
||||
use bevy::asset::{Assets, RenderAssetUsages};
|
||||
use bevy::image::{BevyDefault, Image};
|
||||
use bevy::input::ButtonInput;
|
||||
use bevy::prelude::{Component, KeyCode, Query, Res, ResMut, Sprite};
|
||||
use bevy::prelude::{Color, Commands, Component, Entity, KeyCode, Query, Res, ResMut, Sprite};
|
||||
use bevy::render::render_resource::{Extent3d, TextureDimension, TextureFormat};
|
||||
use rand::RngExt;
|
||||
use rand_chacha::ChaCha8Rng;
|
||||
use crate::seed_automation::SeedAutomation;
|
||||
use crate::subplate_automation::SubPlateAutomation;
|
||||
|
||||
pub fn update_automation_view_plate(
|
||||
pub fn update_automation_view(
|
||||
query: Query<(&Sprite, &PlateAutomation)>,
|
||||
mut images: ResMut<Assets<Image>>,
|
||||
) {
|
||||
@@ -34,17 +36,18 @@ pub fn update_automation_view_plate(
|
||||
images.insert(sprite.image.id(), image).unwrap();
|
||||
}
|
||||
|
||||
pub fn update_automation_plate(
|
||||
mut query: Query<&mut PlateAutomation>,
|
||||
pub fn update_automation(
|
||||
mut query: Query<(&mut PlateAutomation, Entity)>,
|
||||
mut seeded_rng: ResMut<SeededRng>,
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
if query.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut automation = query.iter_mut().next().unwrap();
|
||||
if keys.just_pressed(KeyCode::Space) {
|
||||
|
||||
let (mut automation, entity) = query.iter_mut().next().unwrap();
|
||||
if keys.just_pressed(KeyCode::Space) || keys.all_pressed([KeyCode::Space, KeyCode::ShiftLeft]) {
|
||||
let random = &mut seeded_rng.0;
|
||||
|
||||
automation.next(random)
|
||||
@@ -53,6 +56,15 @@ pub fn update_automation_plate(
|
||||
if keys.just_pressed(KeyCode::AltLeft) {
|
||||
automation.world.grow()
|
||||
}
|
||||
|
||||
if keys.just_pressed(KeyCode::Tab) {
|
||||
println!("Switching to SubPlateAutomation");
|
||||
let mut new_table = Table::<Color>::new(Color::BLACK, automation.world.side);
|
||||
automation.world.convert_copy(&mut new_table, |value| { if value { Color::WHITE } else { Color::BLACK } });
|
||||
commands.entity(entity).remove::<PlateAutomation>().insert(SubPlateAutomation{
|
||||
world: new_table
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
@@ -62,6 +74,22 @@ pub struct PlateAutomation {
|
||||
|
||||
impl PlateAutomation {
|
||||
fn next(&mut self, rng: &mut ChaCha8Rng) {
|
||||
println!("Next for plate automation");
|
||||
for index in 0..self.world.side * self.world.side {
|
||||
if *self.world.get(index) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let around = self.world.around_line(index).iter().filter(|v| ***v).count();
|
||||
|
||||
if around == 0 {
|
||||
continue;
|
||||
}
|
||||
let chance = (around as f32 * 0.2).powi(2);
|
||||
if rng.random::<f32>() > chance {
|
||||
continue;
|
||||
}
|
||||
|
||||
self.world.set(index, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user