Remove hex view
This commit is contained in:
@@ -14,3 +14,7 @@ pub struct CollisionAutomation {
|
|||||||
pub border: HexTable<u8>,
|
pub border: HexTable<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct EdgePoint{
|
||||||
|
|
||||||
|
}
|
||||||
+8
-9
@@ -44,7 +44,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
|
fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
|
||||||
commands.spawn(Camera2d);
|
commands.spawn((Camera2d, Transform::default(), Moving));
|
||||||
|
|
||||||
let handle = images.add(Image::default());
|
let handle = images.add(Image::default());
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
|
|||||||
world: Table::new(false, 64),
|
world: Table::new(false, 64),
|
||||||
};
|
};
|
||||||
|
|
||||||
commands.spawn((shape, automation, Moving));
|
commands.spawn((shape, automation));
|
||||||
|
|
||||||
let seeded_rng = ChaCha8Rng::seed_from_u64(0);
|
let seeded_rng = ChaCha8Rng::seed_from_u64(0);
|
||||||
commands.insert_resource(SeededRng(seeded_rng));
|
commands.insert_resource(SeededRng(seeded_rng));
|
||||||
@@ -78,25 +78,24 @@ fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
|
|||||||
shape,
|
shape,
|
||||||
HexMatrixView,
|
HexMatrixView,
|
||||||
Transform::from_xyz(0.0, 0.0, 1.0),
|
Transform::from_xyz(0.0, 0.0, 1.0),
|
||||||
Moving,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn moving_system(hex: Query<&mut Transform, With<Moving>>, keys: Res<ButtonInput<KeyCode>>) {
|
fn moving_system(hex: Query<&mut Transform, With<Moving>>, keys: Res<ButtonInput<KeyCode>>) {
|
||||||
for mut transform in hex {
|
for mut transform in hex {
|
||||||
if keys.pressed(KeyCode::ArrowDown) {
|
if keys.pressed(KeyCode::ArrowDown) {
|
||||||
transform.translation.y += 3.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if keys.pressed(KeyCode::ArrowUp) {
|
|
||||||
transform.translation.y -= 3.0;
|
transform.translation.y -= 3.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if keys.pressed(KeyCode::ArrowUp) {
|
||||||
|
transform.translation.y += 3.0;
|
||||||
|
}
|
||||||
|
|
||||||
if keys.pressed(KeyCode::ArrowLeft) {
|
if keys.pressed(KeyCode::ArrowLeft) {
|
||||||
transform.translation.x += 3.0;
|
transform.translation.x -= 3.0;
|
||||||
}
|
}
|
||||||
if keys.pressed(KeyCode::ArrowRight) {
|
if keys.pressed(KeyCode::ArrowRight) {
|
||||||
transform.translation.x -= 3.0;
|
transform.translation.x += 3.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if keys.pressed(KeyCode::PageUp) {
|
if keys.pressed(KeyCode::PageUp) {
|
||||||
|
|||||||
+25
-12
@@ -27,13 +27,15 @@ pub fn update_automation_view(
|
|||||||
|
|
||||||
pub fn update_automation(
|
pub fn update_automation(
|
||||||
query: Single<(&mut SubPlateAutomation, Entity)>,
|
query: Single<(&mut SubPlateAutomation, Entity)>,
|
||||||
mut hex_query: Single<&mut HexMatrixBuild>,
|
mut hex_query: Single<(&mut HexMatrixBuild, Entity)>,
|
||||||
mut seeded_rng: ResMut<SeededRng>,
|
mut seeded_rng: ResMut<SeededRng>,
|
||||||
keys: Res<ButtonInput<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut images: ResMut<Assets<Image>>,
|
mut images: ResMut<Assets<Image>>,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
|
hex_view: Single<Entity, With<HexMatrixView>>,
|
||||||
|
|
||||||
) {
|
) {
|
||||||
let (mut automation, entity) = query.into_inner();
|
let (mut automation, entity) = query.into_inner();
|
||||||
if keys.just_pressed(KeyCode::Space) || keys.all_pressed([KeyCode::Space, KeyCode::ShiftLeft]) {
|
if keys.just_pressed(KeyCode::Space) || keys.all_pressed([KeyCode::Space, KeyCode::ShiftLeft]) {
|
||||||
@@ -68,17 +70,19 @@ pub fn update_automation(
|
|||||||
|
|
||||||
if keys.just_pressed(KeyCode::Enter) {
|
if keys.just_pressed(KeyCode::Enter) {
|
||||||
commands.entity(entity).despawn();
|
commands.entity(entity).despawn();
|
||||||
create_collision_world(commands, &automation, &hex_query, images, meshes, materials);
|
create_collision_world(commands, &automation, &hex_query, images, meshes, materials, hex_view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_collision_world(
|
fn create_collision_world(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
query: &Mut<SubPlateAutomation>,
|
query: &Mut<SubPlateAutomation>,
|
||||||
hex_query: &Single<&mut HexMatrixBuild>,
|
hex_query: &Single<(&mut HexMatrixBuild, Entity)>,
|
||||||
mut images: ResMut<Assets<Image>>,
|
mut images: ResMut<Assets<Image>>,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
|
hex_view: Single<Entity, With<HexMatrixView>>,
|
||||||
|
|
||||||
) {
|
) {
|
||||||
println!("Switching to CollisionAutomation");
|
println!("Switching to CollisionAutomation");
|
||||||
let mut colors = query.world.data.clone();
|
let mut colors = query.world.data.clone();
|
||||||
@@ -99,15 +103,17 @@ fn create_collision_world(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for x in 0..hex_query.hex_matrix.dimensions.0 {
|
let hex_matrix = &hex_query.0.hex_matrix;
|
||||||
for y in 0..hex_query.hex_matrix.dimensions.1 {
|
|
||||||
|
for x in 0..hex_matrix.dimensions.0 {
|
||||||
|
for y in 0..hex_matrix.dimensions.1 {
|
||||||
let color = *query.world.get_dim(x, y);
|
let color = *query.world.get_dim(x, y);
|
||||||
if color == 0 {
|
if color == 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let index = colors.iter().position(|v| *v == color).unwrap();
|
let index = colors.iter().position(|v| *v == color).unwrap();
|
||||||
let coordinates = hex_query.hex_matrix.get_offset_of(x, y);
|
let coordinates = hex_matrix.get_offset_of(x, y);
|
||||||
borders[index].push(Vec2::new(coordinates.0, coordinates.1));
|
borders[index].push(Vec2::new(coordinates.0, coordinates.1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,6 +167,9 @@ fn create_collision_world(
|
|||||||
|
|
||||||
let mut world = CollisionWorld { bodies: vec![] };
|
let mut world = CollisionWorld { bodies: vec![] };
|
||||||
|
|
||||||
|
let border_color = materials.add(Color::srgb_u8(255,255,1));
|
||||||
|
let border_shape = meshes.add(Circle::new(1.0));
|
||||||
|
|
||||||
let center_color = materials.add(Color::srgb_u8(63,0,255));
|
let center_color = materials.add(Color::srgb_u8(63,0,255));
|
||||||
let center_shape = meshes.add(Circle::new(5.0));
|
let center_shape = meshes.add(Circle::new(5.0));
|
||||||
let mut parts = Vec::with_capacity(plates_data.len());
|
let mut parts = Vec::with_capacity(plates_data.len());
|
||||||
@@ -183,6 +192,7 @@ fn create_collision_world(
|
|||||||
.id();
|
.id();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut entity = commands.spawn((Transform::from_xyz(center.x, center.y, 0.0),));
|
let mut entity = commands.spawn((Transform::from_xyz(center.x, center.y, 0.0),));
|
||||||
entity.add_child(view_id);
|
entity.add_child(view_id);
|
||||||
entity.add_child(mass_id);
|
entity.add_child(mass_id);
|
||||||
@@ -190,6 +200,8 @@ fn create_collision_world(
|
|||||||
|
|
||||||
parts.push(entity_id);
|
parts.push(entity_id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let col_body = CollisionBody {
|
let col_body = CollisionBody {
|
||||||
value: colors[index],
|
value: colors[index],
|
||||||
position: *center,
|
position: *center,
|
||||||
@@ -201,12 +213,13 @@ fn create_collision_world(
|
|||||||
world.bodies.push(col_body);
|
world.bodies.push(col_body);
|
||||||
}
|
}
|
||||||
let scale = RECTANGLE_SIDE / query.world.side as f32;
|
let scale = RECTANGLE_SIDE / query.world.side as f32;
|
||||||
let presentation = commands.spawn((Transform{
|
commands.spawn((Transform{
|
||||||
translation: Vec3::ZERO,
|
translation: Vec3::ZERO,
|
||||||
rotation: Quat::default(),
|
rotation: Quat::default(),
|
||||||
scale: vec3(scale, scale, 1.0),
|
scale: vec3(scale, scale, 1.0),
|
||||||
})).add_children(parts.as_slice()).id();
|
})).add_children(parts.as_slice());
|
||||||
commands.spawn((Transform::default(), Moving)).add_child(presentation);
|
|
||||||
|
commands.entity(*hex_view).despawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@@ -281,10 +294,10 @@ impl SubPlateAutomation {
|
|||||||
fn calculate_front_lines(
|
fn calculate_front_lines(
|
||||||
&self,
|
&self,
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
mut hex_query: &mut Single<&mut HexMatrixBuild>,
|
mut hex_query: &mut Single<(&mut HexMatrixBuild, Entity)>,
|
||||||
automation: &SubPlateAutomation,
|
automation: &SubPlateAutomation,
|
||||||
) {
|
) {
|
||||||
let table = &mut hex_query.hex_matrix;
|
let table = &mut hex_query.0.hex_matrix;
|
||||||
let mut table_copy = table.clone();
|
let mut table_copy = table.clone();
|
||||||
|
|
||||||
for x in 0..table.dimensions.0 {
|
for x in 0..table.dimensions.0 {
|
||||||
@@ -308,7 +321,7 @@ impl SubPlateAutomation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hex_query.hex_matrix = table_copy;
|
hex_query.0.hex_matrix = table_copy;
|
||||||
|
|
||||||
commands.spawn(HexMatrixRedrawRequest);
|
commands.spawn(HexMatrixRedrawRequest);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user