Migration works
This commit is contained in:
+23
-1
@@ -18,7 +18,7 @@ fn main() {
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_systems(Startup, setup)
|
||||
.insert_resource(Time::<Fixed>::from_hz(1024.0))
|
||||
.add_systems(Update, keyboard_input_system)
|
||||
// .add_systems(Update, automation_keyboard_input_system)
|
||||
.add_systems(Update, seed_automation::update_automation_seed)
|
||||
.add_systems(Update, seed_automation::update_automation_view_seed)
|
||||
.add_systems(Update, plate_automation::update_automation_plate)
|
||||
@@ -44,5 +44,27 @@ fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
|
||||
commands.insert_resource(SeededRng(seeded_rng));
|
||||
}
|
||||
|
||||
// fn automation_keyboard_input_system(keys: Res<ButtonInput<KeyCode>>, mut commands: Commands) {
|
||||
// if keys.just_pressed(KeyCode::Space) {
|
||||
// commands.spawn((AutomationNext,));
|
||||
// }
|
||||
//
|
||||
// if keys.just_pressed(KeyCode::Tab) {
|
||||
// commands.spawn((AutomationMigrate,));
|
||||
// }
|
||||
//
|
||||
// if keys.just_pressed(KeyCode::AltLeft) {
|
||||
// commands.spawn((AutomationScale,));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// #[derive(Component)]
|
||||
// struct AutomationNext;
|
||||
//
|
||||
// #[derive(Component)]
|
||||
// struct AutomationScale;
|
||||
//
|
||||
// #[derive(Component)]
|
||||
// struct AutomationMigrate;
|
||||
#[derive(Resource)]
|
||||
struct SeededRng(ChaCha8Rng);
|
||||
|
||||
+10
-11
@@ -3,7 +3,7 @@ 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, ResMut, Sprite};
|
||||
use bevy::prelude::{Component, KeyCode, Query, Res, ResMut, Sprite};
|
||||
use bevy::render::render_resource::{Extent3d, TextureDimension, TextureFormat};
|
||||
use rand::RngExt;
|
||||
use rand_chacha::ChaCha8Rng;
|
||||
@@ -12,6 +12,9 @@ pub fn update_automation_view_plate(
|
||||
query: Query<(&Sprite, &PlateAutomation)>,
|
||||
mut images: ResMut<Assets<Image>>,
|
||||
) {
|
||||
if query.is_empty() {
|
||||
return;
|
||||
}
|
||||
let (sprite, automation) = query.iter().next().unwrap();
|
||||
let size = automation.world.side as u32;
|
||||
let data = automation.world.get_image_data();
|
||||
@@ -34,8 +37,12 @@ pub fn update_automation_view_plate(
|
||||
pub fn update_automation_plate(
|
||||
mut query: Query<&mut PlateAutomation>,
|
||||
mut seeded_rng: ResMut<SeededRng>,
|
||||
keys: ResMut<ButtonInput<KeyCode>>,
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
if query.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut automation = query.iter_mut().next().unwrap();
|
||||
if keys.just_pressed(KeyCode::Space) {
|
||||
let random = &mut seeded_rng.0;
|
||||
@@ -55,14 +62,6 @@ pub struct PlateAutomation {
|
||||
|
||||
impl PlateAutomation {
|
||||
fn next(&mut self, rng: &mut ChaCha8Rng) {
|
||||
let len = (self.world.side * self.world.side) as f32;
|
||||
loop {
|
||||
let index = (rng.random::<f32>() * len) as usize;
|
||||
if *self.world.get(index) {
|
||||
continue;
|
||||
}
|
||||
self.world.set(index, true);
|
||||
break;
|
||||
}
|
||||
println!("Next for plate automation");
|
||||
}
|
||||
}
|
||||
|
||||
+17
-3
@@ -3,15 +3,20 @@ use crate::basic::{IntoImage, Table};
|
||||
use bevy::asset::{Assets, RenderAssetUsages};
|
||||
use bevy::image::{BevyDefault, Image};
|
||||
use bevy::input::ButtonInput;
|
||||
use bevy::prelude::{Commands, Component, Entity, KeyCode, Query, ResMut, Sprite};
|
||||
use bevy::prelude::{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::plate_automation::PlateAutomation;
|
||||
|
||||
pub fn update_automation_view_seed(
|
||||
query: Query<(&Sprite, &SeedAutomation)>,
|
||||
mut images: ResMut<Assets<Image>>,
|
||||
) {
|
||||
if query.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let (sprite, automation) = query.iter().next().unwrap();
|
||||
let size = automation.world.side as u32;
|
||||
let data = automation.world.get_image_data();
|
||||
@@ -34,15 +39,24 @@ pub fn update_automation_view_seed(
|
||||
pub fn update_automation_seed(
|
||||
mut query: Query<(&mut SeedAutomation, Entity)>,
|
||||
mut seeded_rng: ResMut<SeededRng>,
|
||||
keys: ResMut<ButtonInput<KeyCode>>,
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
mut commands: Commands) {
|
||||
|
||||
if query.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let (mut automation, entity) = query.iter_mut().next().unwrap();
|
||||
|
||||
if keys.just_pressed(KeyCode::Space){
|
||||
let random = &mut seeded_rng.0;
|
||||
automation.next(random)
|
||||
}
|
||||
if keys.just_pressed(KeyCode::Tab){
|
||||
commands.entity(entity).;
|
||||
println!("Switching to PlateAutomation");
|
||||
commands.entity(entity).remove::<SeedAutomation>().insert(PlateAutomation{
|
||||
world: automation.world.clone()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user