bump versions to bevy 0.11

This commit is contained in:
Franz Dietrich 2023-09-03 22:41:37 +02:00
parent 03af02b4e6
commit 9a551573cb
Signed by: dietrich
GPG Key ID: F0CE5A20AB5C4B27
13 changed files with 1546 additions and 1160 deletions

2492
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,12 +7,12 @@ default-run = "turtlers"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
bevy = { version = "0.9", features = ["dynamic", "wayland"] } bevy = { version = "0.11", features = ["dynamic_linking", "wayland"] }
bevy-inspector-egui = "0.14" bevy-inspector-egui = "0.19"
bevy_egui = "0.17" bevy_egui = "0.21"
egui = "0.19" egui = "0.22"
bevy_prototype_lyon = {version="0.7"} bevy_prototype_lyon = {version="0.9"}
bevy_tweening = {version="0.6"} bevy_tweening = {version="0.8"}
num-traits = "0.2" num-traits = "0.2"
# Enable a small amount of optimization in debug mode # Enable a small amount of optimization in debug mode

View File

@ -1,4 +1,5 @@
use bevy::prelude::{Commands, Query, Transform, With}; use bevy::prelude::{Color, Commands, Query, Transform, With};
use bevy_prototype_lyon::prelude::{Fill, Stroke};
use bevy_tweening::Animator; use bevy_tweening::Animator;
use crate::{ use crate::{
@ -17,16 +18,20 @@ pub(crate) fn run_animation_step(
turtle_animation: Some(turtle_animation), turtle_animation: Some(turtle_animation),
line_segment: Some(graph_element_to_draw), line_segment: Some(graph_element_to_draw),
line_animation: Some(line_animation), line_animation: Some(line_animation),
fill,
stroke,
}) => { }) => {
let mut turtle = turtle.single_mut(); let mut turtle = turtle.single_mut();
turtle.set_tweenable(turtle_animation); turtle.set_tweenable(turtle_animation);
let fill = fill.unwrap_or(Fill::color(Color::MIDNIGHT_BLUE));
let stroke = stroke.unwrap_or(Stroke::color(Color::BLACK));
match graph_element_to_draw { match graph_element_to_draw {
TurtleGraphElement::TurtleLine(line) => { TurtleGraphElement::TurtleLine(line) => {
commands.spawn((line, line_animation)); commands.spawn((line, line_animation, fill, stroke));
} }
TurtleGraphElement::Noop => (), TurtleGraphElement::Noop => (),
TurtleGraphElement::TurtleCircle(circle) => { TurtleGraphElement::TurtleCircle(circle) => {
commands.spawn((circle, line_animation)); commands.spawn((circle, line_animation, fill, stroke));
} }
} }
return; return;
@ -36,6 +41,7 @@ pub(crate) fn run_animation_step(
turtle_animation: Some(turtle_animation), turtle_animation: Some(turtle_animation),
line_segment: Some(_), line_segment: Some(_),
line_animation: None, line_animation: None,
..
}) => { }) => {
let mut turtle = turtle.single_mut(); let mut turtle = turtle.single_mut();
turtle.set_tweenable(turtle_animation); turtle.set_tweenable(turtle_animation);

View File

@ -1,8 +1,6 @@
use bevy::{app::AppExit, prelude::*}; use bevy::{app::AppExit, prelude::*};
use bevy_egui::{egui, EguiContext, EguiPlugin}; use bevy_egui::{egui, EguiContexts, EguiPlugin};
use bevy_prototype_lyon::prelude::{ use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, Path, PathBuilder, ShapePlugin, Stroke};
DrawMode, FillMode, FillOptions, GeometryBuilder, Path, PathBuilder, ShapePlugin, StrokeMode,
};
#[derive(Default, Resource)] #[derive(Default, Resource)]
struct OccupiedScreenSpace { struct OccupiedScreenSpace {
@ -24,14 +22,13 @@ struct OriginalCameraTransform(Transform);
fn main() { fn main() {
App::new() App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin { .add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor { primary_window: Some(Window {
width: 700.0, resolution: (800., 600.).into(),
height: 500.0,
title: "Turtle Window".to_string(), title: "Turtle Window".to_string(),
present_mode: bevy::window::PresentMode::AutoVsync, present_mode: bevy::window::PresentMode::AutoVsync,
//decorations: false, //decorations: false,
..default() ..default()
}, }),
..default() ..default()
})) }))
.add_plugin(EguiPlugin) .add_plugin(EguiPlugin)
@ -53,18 +50,18 @@ fn update_path(line: Res<Line>, mut path: Query<&mut Path>) {
} }
fn ui( fn ui(
mut egui_context: ResMut<EguiContext>, mut egui_contexts: EguiContexts,
mut occupied_screen_space: ResMut<OccupiedScreenSpace>, mut occupied_screen_space: ResMut<OccupiedScreenSpace>,
mut line: ResMut<Line>, mut line: ResMut<Line>,
mut exit: EventWriter<AppExit>, mut exit: EventWriter<AppExit>,
) { ) {
let mut style = (*egui_context.ctx_mut().style()).clone(); let mut style = (*egui_contexts.ctx_mut().style()).clone();
style.visuals.button_frame = false; style.visuals.button_frame = false;
egui_context.ctx_mut().set_style(style); egui_contexts.ctx_mut().set_style(style);
occupied_screen_space.left = 0.0; occupied_screen_space.left = 0.0;
occupied_screen_space.right = egui::SidePanel::right("right_panel") occupied_screen_space.right = egui::SidePanel::right("right_panel")
.resizable(false) .resizable(false)
.show(egui_context.ctx_mut(), |ui| { .show(egui_contexts.ctx_mut(), |ui| {
ui.add_space(7.); ui.add_space(7.);
ui.menu_button("Menu", |ui| { ui.menu_button("Menu", |ui| {
if ui if ui
@ -81,7 +78,7 @@ fn ui(
occupied_screen_space.top = 0.0; occupied_screen_space.top = 0.0;
occupied_screen_space.bottom = egui::TopBottomPanel::bottom("bottom_panel") occupied_screen_space.bottom = egui::TopBottomPanel::bottom("bottom_panel")
.resizable(false) .resizable(false)
.show(egui_context.ctx_mut(), |ui| { .show(egui_contexts.ctx_mut(), |ui| {
ui.add_sized( ui.add_sized(
ui.available_size(), ui.available_size(),
egui::Slider::new(&mut line.x, 0.0..=100.0), egui::Slider::new(&mut line.x, 0.0..=100.0),
@ -99,16 +96,8 @@ fn setup_system(mut commands: Commands) {
path_builder.move_to(Vec2::new(200., 200.)); path_builder.move_to(Vec2::new(200., 200.));
path_builder.line_to(Vec2::new(100., 0.)); path_builder.line_to(Vec2::new(100., 0.));
let line = path_builder.build(); let line = path_builder.build();
let fill = Fill::color(Color::MIDNIGHT_BLUE);
let stroke = Stroke::color(Color::BLACK);
commands.spawn(GeometryBuilder::build_as( commands.spawn((GeometryBuilder::build_as(&line), fill, stroke));
&line,
DrawMode::Outlined {
fill_mode: FillMode {
options: FillOptions::default(),
color: Default::default(),
},
outline_mode: StrokeMode::new(Color::BLACK, 6.),
},
Transform::IDENTITY,
));
} }

View File

@ -8,7 +8,7 @@ use bevy_tweening::{
fn main() { fn main() {
App::new() App::new()
.insert_resource(Msaa { samples: 4 }) .insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(ShapePlugin) .add_plugin(ShapePlugin)
.add_plugin(TweeningPlugin) .add_plugin(TweeningPlugin)
@ -64,18 +64,10 @@ fn setup_system(mut commands: Commands) {
seq = seq.then(next); seq = seq.then(next);
} }
let animator = Animator::new(seq); let animator = Animator::new(seq);
let fill = Fill::color(Color::MIDNIGHT_BLUE);
let stroke = Stroke::color(Color::BLACK);
commands commands
.spawn(GeometryBuilder::build_as( .spawn((GeometryBuilder::build_as(&line), fill, stroke))
&line,
DrawMode::Outlined {
fill_mode: FillMode {
options: FillOptions::default(),
color: Default::default(),
},
outline_mode: StrokeMode::new(Color::BLACK, 3.),
},
Transform::default(),
))
.insert(animator); .insert(animator);
} }

View File

@ -1,12 +1,14 @@
use bevy_inspector_egui::Inspectable;
use std::{ use std::{
f32::consts::PI, f32::consts::PI,
ops::{Add, Div, Mul, Neg, Rem, Sub}, ops::{Add, Div, Mul, Neg, Rem, Sub},
}; };
use bevy::reflect::Reflect;
use crate::turtle::Precision; use crate::turtle::Precision;
#[derive(Inspectable, Copy, Clone, Debug, PartialEq, Eq)] #[derive(Reflect, Copy, Clone, Debug, PartialEq, Eq)]
pub enum AngleUnit<T: Default> { pub enum AngleUnit<T: Default> {
Degrees(T), Degrees(T),
Radians(T), Radians(T),
@ -18,7 +20,7 @@ impl<T: Default> Default for AngleUnit<T> {
} }
} }
#[derive(Inspectable, Copy, Default, Clone, Debug, PartialEq, Eq)] #[derive(Reflect, Copy, Default, Clone, Debug, PartialEq, Eq)]
pub struct Angle<T: Default> { pub struct Angle<T: Default> {
value: AngleUnit<T>, value: AngleUnit<T>,
} }

View File

@ -1,6 +1,6 @@
use bevy_inspector_egui::Inspectable; use bevy::reflect::Reflect;
use crate::turtle::Precision; use crate::turtle::Precision;
#[derive(Inspectable, Default, Copy, Clone, Debug)] #[derive(Reflect, Default, Copy, Clone, Debug)]
pub struct Length(pub Precision); pub struct Length(pub Precision);

View File

@ -1,5 +1,5 @@
use bevy::prelude::Plugin; use bevy::prelude::Plugin;
use bevy_inspector_egui::WorldInspectorPlugin; use bevy_inspector_egui::quick::WorldInspectorPlugin;
pub struct DebugPlugin; pub struct DebugPlugin;

View File

@ -14,16 +14,15 @@ use turtle::TurtlePlugin;
fn main() { fn main() {
App::new() App::new()
.insert_resource(Msaa { samples: 4 }) .insert_resource(Msaa::Sample4)
.insert_resource(ClearColor(Color::BEIGE)) .insert_resource(ClearColor(Color::BEIGE))
.add_plugins(DefaultPlugins.set(WindowPlugin { .add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor { primary_window: Some(Window {
width: 500.0, resolution: (800.,600.).into(),
height: 500.0, //title: "Turtle Window".to_string(),
title: "Turtle Window".to_string(),
present_mode: bevy::window::PresentMode::AutoVsync, present_mode: bevy::window::PresentMode::AutoVsync,
..default() ..default()
}, }),
..default() ..default()
})) }))
.add_plugin(ShapePlugin) .add_plugin(ShapePlugin)

View File

@ -1,8 +1,10 @@
use bevy::prelude::{Bundle, Color, Component, Name, Transform, Vec2}; use bevy::{
use bevy_inspector_egui::Inspectable; prelude::{default, Bundle, Component, Name, Vec2},
reflect::Reflect,
};
use bevy_prototype_lyon::{ use bevy_prototype_lyon::{
entity::ShapeBundle, entity::ShapeBundle,
prelude::{DrawMode, FillMode, GeometryBuilder, PathBuilder, StrokeMode}, prelude::{Fill, GeometryBuilder, PathBuilder, Stroke},
shapes::Line, shapes::Line,
}; };
@ -13,44 +15,41 @@ use crate::{
use super::turtle_shapes; use super::turtle_shapes;
#[derive(Bundle, Inspectable, Default)] #[derive(Bundle, Reflect, Default)]
pub struct TurtleDrawLine { pub struct TurtleDrawLine {
#[inspectable(ignore)] #[reflect(ignore)]
line: ShapeBundle, line: ShapeBundle,
name: Name, name: Name,
marker: LineMarker, marker: LineMarker,
} }
#[derive(Component, Default, Inspectable)] #[derive(Component, Default, Reflect)]
struct LineMarker; struct LineMarker;
impl TurtleDrawLine { impl TurtleDrawLine {
pub(crate) fn new(start: Vec2, _end: Vec2, index: u64) -> Self { pub(crate) fn new(start: Vec2, _end: Vec2, index: u64) -> Self {
let bundle = ShapeBundle {
path: GeometryBuilder::build_as(&Line(start, start)),
..default()
};
Self { Self {
line: GeometryBuilder::build_as( line: bundle,
&Line(start, start),
DrawMode::Outlined {
fill_mode: FillMode::color(Color::MIDNIGHT_BLUE),
outline_mode: StrokeMode::new(Color::BLACK, 1.0),
},
Transform::IDENTITY,
),
name: Name::new(format!("Line {}", index)), name: Name::new(format!("Line {}", index)),
marker: LineMarker, marker: LineMarker,
} }
} }
} }
#[derive(Bundle, Inspectable, Default)] #[derive(Bundle, Reflect, Default)]
pub struct TurtleDrawCircle { pub struct TurtleDrawCircle {
#[inspectable(ignore)] #[reflect(ignore)]
line: ShapeBundle, line: ShapeBundle,
name: Name, name: Name,
marker: CircleMarker, marker: CircleMarker,
} }
#[derive(Component, Default, Inspectable)] #[derive(Component, Default, Reflect)]
struct CircleMarker; struct CircleMarker;
impl TurtleDrawCircle { impl TurtleDrawCircle {
@ -72,15 +71,12 @@ impl TurtleDrawCircle {
let line = path_builder.build(); let line = path_builder.build();
println!("Draw Circle: {} {} {:?}", center, radii, angle); println!("Draw Circle: {} {} {:?}", center, radii, angle);
let bundle = ShapeBundle {
path: GeometryBuilder::build_as(&line),
..default()
};
Self { Self {
line: GeometryBuilder::build_as( line: bundle,
&line,
DrawMode::Outlined {
fill_mode: FillMode::color(Color::rgba(0., 0., 0., 0.)),
outline_mode: StrokeMode::new(Color::BLACK, 1.0),
},
Transform::IDENTITY,
),
name: Name::new(format!("Circle {}", index)), name: Name::new(format!("Circle {}", index)),
marker: CircleMarker, marker: CircleMarker,
} }
@ -97,18 +93,15 @@ pub struct Turtle {
impl Default for Turtle { impl Default for Turtle {
fn default() -> Self { fn default() -> Self {
let bundle = ShapeBundle {
path: GeometryBuilder::build_as(&turtle_shapes::turtle()),
..default()
};
Self { Self {
colors: Colors::default(), colors: Colors::default(),
commands: TurtleCommands::new(vec![]), commands: TurtleCommands::new(vec![]),
name: Name::new("Turtle"), name: Name::new("Turtle"),
shape: GeometryBuilder::build_as( shape: bundle,
&turtle_shapes::turtle(),
DrawMode::Outlined {
fill_mode: FillMode::color(Color::MIDNIGHT_BLUE),
outline_mode: StrokeMode::new(Color::BLACK, 1.0),
},
Transform::IDENTITY,
),
} }
} }
} }

View File

@ -2,7 +2,7 @@ use bevy_prototype_lyon::prelude::PathBuilder;
use crate::{ use crate::{
datatypes::{ datatypes::{
angle::{Angle, AngleUnit}, angle::Angle,
length::Length, length::Length,
Coordinate, Coordinate,
}, },

View File

@ -4,7 +4,6 @@ pub mod turtle;
use std::time::Duration; use std::time::Duration;
use bevy::prelude::*; use bevy::prelude::*;
use bevy_inspector_egui::{Inspectable, RegisterInspectable};
use bevy_prototype_lyon::prelude::*; use bevy_prototype_lyon::prelude::*;
use bevy_tweening::{ use bevy_tweening::{
component_animator_system, lens::TransformScaleLens, Animator, EaseFunction, RepeatCount, component_animator_system, lens::TransformScaleLens, Animator, EaseFunction, RepeatCount,
@ -29,19 +28,19 @@ impl Plugin for TurtlePlugin {
.add_system(keypresses) .add_system(keypresses)
.add_system(draw_lines) .add_system(draw_lines)
.add_system(component_animator_system::<Path>) .add_system(component_animator_system::<Path>)
.register_inspectable::<Colors>() .register_type::<Colors>()
.register_inspectable::<TurtleCommands>(); .register_type::<TurtleCommands>();
} }
} }
pub type Precision = f32; pub type Precision = f32;
#[derive(Component, Inspectable)] #[derive(Component, Reflect)]
pub struct TurtleCommands { pub struct TurtleCommands {
commands: Vec<TurtleCommand>, commands: Vec<TurtleCommand>,
lines: Vec<TurtleGraphElement>, lines: Vec<TurtleGraphElement>,
state: TurtleState, state: TurtleState,
} }
#[derive(Inspectable)] #[derive(Reflect)]
pub struct TurtleState { pub struct TurtleState {
pub start: Vec2, pub start: Vec2,
pub heading: Angle<f32>, pub heading: Angle<f32>,
@ -92,6 +91,8 @@ impl TurtleCommands {
turtle_animation: None, turtle_animation: None,
line_segment: None, line_segment: None,
line_animation: None, line_animation: None,
fill: None,
stroke: None,
} }
} }
TurtleCommand::PenDown => { TurtleCommand::PenDown => {
@ -101,6 +102,8 @@ impl TurtleCommands {
turtle_animation: None, turtle_animation: None,
line_segment: None, line_segment: None,
line_animation: None, line_animation: None,
fill: None,
stroke: None,
} }
} }
TurtleCommand::Circle { radius, angle } => { TurtleCommand::Circle { radius, angle } => {
@ -118,7 +121,7 @@ impl TurtleCommands {
} }
} }
#[derive(Inspectable, Default)] #[derive(Reflect, Default)]
pub enum TurtleGraphElement { pub enum TurtleGraphElement {
TurtleLine(TurtleDrawLine), TurtleLine(TurtleDrawLine),
TurtleCircle(TurtleDrawCircle), TurtleCircle(TurtleDrawCircle),
@ -126,16 +129,16 @@ pub enum TurtleGraphElement {
Noop, Noop,
} }
#[derive(Clone, Component, Inspectable)] #[derive(Clone, Component, Reflect)]
pub struct TurtleShape; pub struct TurtleShape;
#[derive(Clone, Component, Inspectable, Default)] #[derive(Clone, Component, Reflect, Default)]
pub struct Colors { pub struct Colors {
color: Color, color: Color,
fill_color: Color, fill_color: Color,
} }
#[derive(Component, Inspectable, Default)] #[derive(Component, Reflect, Default)]
pub enum TurtleCommand { pub enum TurtleCommand {
Forward(Length), Forward(Length),
Backward(Length), Backward(Length),
@ -169,12 +172,18 @@ fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default()); commands.spawn(Camera2dBundle::default());
let mut turtle_bundle = Turtle::default(); let mut turtle_bundle = Turtle::default();
let mut tcommands = vec![]; let mut tcommands = vec![];
for _ in 0..100 { //for _ in 0..100 {
tcommands.append(&mut paths::geometry_task::geometry_task()); tcommands.append(&mut paths::geometry_task::geometry_task());
tcommands.append(&mut paths::circle_star::circle_star()); //tcommands.append(&mut paths::circle_star::circle_star());
} //}
turtle_bundle.set_commands(tcommands); turtle_bundle.set_commands(tcommands);
commands.spawn((turtle_bundle, animator, TurtleShape)); commands.spawn((
turtle_bundle,
animator,
TurtleShape,
Fill::color(Color::MIDNIGHT_BLUE),
Stroke::color(Color::BLACK),
));
} }
fn draw_lines( fn draw_lines(
@ -183,7 +192,7 @@ fn draw_lines(
mut turtle: Query<&mut Animator<Transform>, With<TurtleShape>>, mut turtle: Query<&mut Animator<Transform>, With<TurtleShape>>,
mut query_event: EventReader<TweenCompleted>, // TODO: howto attach only to the right event? mut query_event: EventReader<TweenCompleted>, // TODO: howto attach only to the right event?
) { ) {
for ev in query_event.iter() { for _ev in query_event.iter() {
let mut tcmd = tcmd.single_mut(); let mut tcmd = tcmd.single_mut();
run_animation_step(&mut commands, &mut tcmd, &mut turtle) run_animation_step(&mut commands, &mut tcmd, &mut turtle)
} }

View File

@ -1,7 +1,7 @@
use std::time::Duration; use std::time::Duration;
use bevy::prelude::{Quat, Transform, Vec2, Vec3}; use bevy::prelude::{default, Color, Quat, Transform, Vec2, Vec3};
use bevy_prototype_lyon::prelude::Path; use bevy_prototype_lyon::prelude::{Fill, Path, Stroke};
use bevy_tweening::{ use bevy_tweening::{
lens::{TransformPositionLens, TransformRotateZLens}, lens::{TransformPositionLens, TransformRotateZLens},
Animator, EaseFunction, Tween, Animator, EaseFunction, Tween,
@ -20,6 +20,8 @@ pub struct TurtleStep {
pub turtle_animation: Option<Tween<Transform>>, pub turtle_animation: Option<Tween<Transform>>,
pub line_segment: Option<TurtleGraphElement>, pub line_segment: Option<TurtleGraphElement>,
pub line_animation: Option<Animator<Path>>, pub line_animation: Option<Animator<Path>>,
pub fill: Option<Fill>,
pub stroke: Option<Stroke>,
} }
pub fn turtle_turn(state: &mut TurtleState, angle_to_turn: Angle<Precision>) -> TurtleStep { pub fn turtle_turn(state: &mut TurtleState, angle_to_turn: Angle<Precision>) -> TurtleStep {
@ -42,6 +44,8 @@ pub fn turtle_turn(state: &mut TurtleState, angle_to_turn: Angle<Precision>) ->
turtle_animation: Some(animation), turtle_animation: Some(animation),
line_segment: Some(line), line_segment: Some(line),
line_animation: None, line_animation: None,
fill: None,
stroke: None,
} }
} }
@ -72,6 +76,8 @@ pub fn turtle_move(state: &mut TurtleState, length: Precision) -> TurtleStep {
turtle_animation: Some(turtle_movement_animation), turtle_animation: Some(turtle_movement_animation),
line_segment: Some(line), line_segment: Some(line),
line_animation: Some(line_animator), line_animation: Some(line_animator),
fill: Some(Fill::color(Color::MIDNIGHT_BLUE)),
stroke: Some(Stroke::color(Color::BLACK)),
} }
} }
@ -134,5 +140,7 @@ pub fn turtle_circle(
turtle_animation: Some(turtle_movement_animation), turtle_animation: Some(turtle_movement_animation),
line_segment: Some(line), line_segment: Some(line),
line_animation: Some(line_animator), line_animation: Some(line_animator),
fill: Some(Fill::color(Color::MIDNIGHT_BLUE)),
stroke: Some(Stroke::color(Color::BLACK)),
} }
} }