bump versions to bevy 0.11
This commit is contained in:
parent
03af02b4e6
commit
9a551573cb
2492
Cargo.lock
generated
2492
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
12
Cargo.toml
@ -7,12 +7,12 @@ default-run = "turtlers"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = { version = "0.9", features = ["dynamic", "wayland"] }
|
||||
bevy-inspector-egui = "0.14"
|
||||
bevy_egui = "0.17"
|
||||
egui = "0.19"
|
||||
bevy_prototype_lyon = {version="0.7"}
|
||||
bevy_tweening = {version="0.6"}
|
||||
bevy = { version = "0.11", features = ["dynamic_linking", "wayland"] }
|
||||
bevy-inspector-egui = "0.19"
|
||||
bevy_egui = "0.21"
|
||||
egui = "0.22"
|
||||
bevy_prototype_lyon = {version="0.9"}
|
||||
bevy_tweening = {version="0.8"}
|
||||
num-traits = "0.2"
|
||||
|
||||
# Enable a small amount of optimization in debug mode
|
||||
|
@ -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 crate::{
|
||||
@ -17,16 +18,20 @@ pub(crate) fn run_animation_step(
|
||||
turtle_animation: Some(turtle_animation),
|
||||
line_segment: Some(graph_element_to_draw),
|
||||
line_animation: Some(line_animation),
|
||||
fill,
|
||||
stroke,
|
||||
}) => {
|
||||
let mut turtle = turtle.single_mut();
|
||||
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 {
|
||||
TurtleGraphElement::TurtleLine(line) => {
|
||||
commands.spawn((line, line_animation));
|
||||
commands.spawn((line, line_animation, fill, stroke));
|
||||
}
|
||||
TurtleGraphElement::Noop => (),
|
||||
TurtleGraphElement::TurtleCircle(circle) => {
|
||||
commands.spawn((circle, line_animation));
|
||||
commands.spawn((circle, line_animation, fill, stroke));
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -36,6 +41,7 @@ pub(crate) fn run_animation_step(
|
||||
turtle_animation: Some(turtle_animation),
|
||||
line_segment: Some(_),
|
||||
line_animation: None,
|
||||
..
|
||||
}) => {
|
||||
let mut turtle = turtle.single_mut();
|
||||
turtle.set_tweenable(turtle_animation);
|
||||
|
@ -1,8 +1,6 @@
|
||||
use bevy::{app::AppExit, prelude::*};
|
||||
use bevy_egui::{egui, EguiContext, EguiPlugin};
|
||||
use bevy_prototype_lyon::prelude::{
|
||||
DrawMode, FillMode, FillOptions, GeometryBuilder, Path, PathBuilder, ShapePlugin, StrokeMode,
|
||||
};
|
||||
use bevy_egui::{egui, EguiContexts, EguiPlugin};
|
||||
use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, Path, PathBuilder, ShapePlugin, Stroke};
|
||||
|
||||
#[derive(Default, Resource)]
|
||||
struct OccupiedScreenSpace {
|
||||
@ -24,14 +22,13 @@ struct OriginalCameraTransform(Transform);
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
window: WindowDescriptor {
|
||||
width: 700.0,
|
||||
height: 500.0,
|
||||
primary_window: Some(Window {
|
||||
resolution: (800., 600.).into(),
|
||||
title: "Turtle Window".to_string(),
|
||||
present_mode: bevy::window::PresentMode::AutoVsync,
|
||||
//decorations: false,
|
||||
..default()
|
||||
},
|
||||
}),
|
||||
..default()
|
||||
}))
|
||||
.add_plugin(EguiPlugin)
|
||||
@ -53,18 +50,18 @@ fn update_path(line: Res<Line>, mut path: Query<&mut Path>) {
|
||||
}
|
||||
|
||||
fn ui(
|
||||
mut egui_context: ResMut<EguiContext>,
|
||||
mut egui_contexts: EguiContexts,
|
||||
mut occupied_screen_space: ResMut<OccupiedScreenSpace>,
|
||||
mut line: ResMut<Line>,
|
||||
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;
|
||||
egui_context.ctx_mut().set_style(style);
|
||||
egui_contexts.ctx_mut().set_style(style);
|
||||
occupied_screen_space.left = 0.0;
|
||||
occupied_screen_space.right = egui::SidePanel::right("right_panel")
|
||||
.resizable(false)
|
||||
.show(egui_context.ctx_mut(), |ui| {
|
||||
.show(egui_contexts.ctx_mut(), |ui| {
|
||||
ui.add_space(7.);
|
||||
ui.menu_button("Menu", |ui| {
|
||||
if ui
|
||||
@ -81,7 +78,7 @@ fn ui(
|
||||
occupied_screen_space.top = 0.0;
|
||||
occupied_screen_space.bottom = egui::TopBottomPanel::bottom("bottom_panel")
|
||||
.resizable(false)
|
||||
.show(egui_context.ctx_mut(), |ui| {
|
||||
.show(egui_contexts.ctx_mut(), |ui| {
|
||||
ui.add_sized(
|
||||
ui.available_size(),
|
||||
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.line_to(Vec2::new(100., 0.));
|
||||
let line = path_builder.build();
|
||||
let fill = Fill::color(Color::MIDNIGHT_BLUE);
|
||||
let stroke = Stroke::color(Color::BLACK);
|
||||
|
||||
commands.spawn(GeometryBuilder::build_as(
|
||||
&line,
|
||||
DrawMode::Outlined {
|
||||
fill_mode: FillMode {
|
||||
options: FillOptions::default(),
|
||||
color: Default::default(),
|
||||
},
|
||||
outline_mode: StrokeMode::new(Color::BLACK, 6.),
|
||||
},
|
||||
Transform::IDENTITY,
|
||||
));
|
||||
commands.spawn((GeometryBuilder::build_as(&line), fill, stroke));
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use bevy_tweening::{
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.insert_resource(Msaa { samples: 4 })
|
||||
.insert_resource(Msaa::Sample4)
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ShapePlugin)
|
||||
.add_plugin(TweeningPlugin)
|
||||
@ -64,18 +64,10 @@ fn setup_system(mut commands: Commands) {
|
||||
seq = seq.then(next);
|
||||
}
|
||||
let animator = Animator::new(seq);
|
||||
let fill = Fill::color(Color::MIDNIGHT_BLUE);
|
||||
let stroke = Stroke::color(Color::BLACK);
|
||||
commands
|
||||
.spawn(GeometryBuilder::build_as(
|
||||
&line,
|
||||
DrawMode::Outlined {
|
||||
fill_mode: FillMode {
|
||||
options: FillOptions::default(),
|
||||
color: Default::default(),
|
||||
},
|
||||
outline_mode: StrokeMode::new(Color::BLACK, 3.),
|
||||
},
|
||||
Transform::default(),
|
||||
))
|
||||
.spawn((GeometryBuilder::build_as(&line), fill, stroke))
|
||||
.insert(animator);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,14 @@
|
||||
use bevy_inspector_egui::Inspectable;
|
||||
|
||||
use std::{
|
||||
f32::consts::PI,
|
||||
ops::{Add, Div, Mul, Neg, Rem, Sub},
|
||||
};
|
||||
|
||||
use bevy::reflect::Reflect;
|
||||
|
||||
use crate::turtle::Precision;
|
||||
|
||||
#[derive(Inspectable, Copy, Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Reflect, Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum AngleUnit<T: Default> {
|
||||
Degrees(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> {
|
||||
value: AngleUnit<T>,
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use bevy_inspector_egui::Inspectable;
|
||||
use bevy::reflect::Reflect;
|
||||
|
||||
use crate::turtle::Precision;
|
||||
|
||||
#[derive(Inspectable, Default, Copy, Clone, Debug)]
|
||||
#[derive(Reflect, Default, Copy, Clone, Debug)]
|
||||
pub struct Length(pub Precision);
|
||||
|
@ -1,5 +1,5 @@
|
||||
use bevy::prelude::Plugin;
|
||||
use bevy_inspector_egui::WorldInspectorPlugin;
|
||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||
|
||||
pub struct DebugPlugin;
|
||||
|
||||
|
11
src/main.rs
11
src/main.rs
@ -14,16 +14,15 @@ use turtle::TurtlePlugin;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.insert_resource(Msaa { samples: 4 })
|
||||
.insert_resource(Msaa::Sample4)
|
||||
.insert_resource(ClearColor(Color::BEIGE))
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
window: WindowDescriptor {
|
||||
width: 500.0,
|
||||
height: 500.0,
|
||||
title: "Turtle Window".to_string(),
|
||||
primary_window: Some(Window {
|
||||
resolution: (800.,600.).into(),
|
||||
//title: "Turtle Window".to_string(),
|
||||
present_mode: bevy::window::PresentMode::AutoVsync,
|
||||
..default()
|
||||
},
|
||||
}),
|
||||
..default()
|
||||
}))
|
||||
.add_plugin(ShapePlugin)
|
||||
|
@ -1,8 +1,10 @@
|
||||
use bevy::prelude::{Bundle, Color, Component, Name, Transform, Vec2};
|
||||
use bevy_inspector_egui::Inspectable;
|
||||
use bevy::{
|
||||
prelude::{default, Bundle, Component, Name, Vec2},
|
||||
reflect::Reflect,
|
||||
};
|
||||
use bevy_prototype_lyon::{
|
||||
entity::ShapeBundle,
|
||||
prelude::{DrawMode, FillMode, GeometryBuilder, PathBuilder, StrokeMode},
|
||||
prelude::{Fill, GeometryBuilder, PathBuilder, Stroke},
|
||||
shapes::Line,
|
||||
};
|
||||
|
||||
@ -13,44 +15,41 @@ use crate::{
|
||||
|
||||
use super::turtle_shapes;
|
||||
|
||||
#[derive(Bundle, Inspectable, Default)]
|
||||
#[derive(Bundle, Reflect, Default)]
|
||||
pub struct TurtleDrawLine {
|
||||
#[inspectable(ignore)]
|
||||
#[reflect(ignore)]
|
||||
line: ShapeBundle,
|
||||
name: Name,
|
||||
marker: LineMarker,
|
||||
}
|
||||
|
||||
#[derive(Component, Default, Inspectable)]
|
||||
#[derive(Component, Default, Reflect)]
|
||||
struct LineMarker;
|
||||
|
||||
impl TurtleDrawLine {
|
||||
pub(crate) fn new(start: Vec2, _end: Vec2, index: u64) -> Self {
|
||||
let bundle = ShapeBundle {
|
||||
path: GeometryBuilder::build_as(&Line(start, start)),
|
||||
..default()
|
||||
};
|
||||
Self {
|
||||
line: GeometryBuilder::build_as(
|
||||
&Line(start, start),
|
||||
DrawMode::Outlined {
|
||||
fill_mode: FillMode::color(Color::MIDNIGHT_BLUE),
|
||||
outline_mode: StrokeMode::new(Color::BLACK, 1.0),
|
||||
},
|
||||
Transform::IDENTITY,
|
||||
),
|
||||
line: bundle,
|
||||
name: Name::new(format!("Line {}", index)),
|
||||
marker: LineMarker,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Bundle, Inspectable, Default)]
|
||||
#[derive(Bundle, Reflect, Default)]
|
||||
|
||||
pub struct TurtleDrawCircle {
|
||||
#[inspectable(ignore)]
|
||||
#[reflect(ignore)]
|
||||
line: ShapeBundle,
|
||||
name: Name,
|
||||
marker: CircleMarker,
|
||||
}
|
||||
|
||||
#[derive(Component, Default, Inspectable)]
|
||||
#[derive(Component, Default, Reflect)]
|
||||
struct CircleMarker;
|
||||
|
||||
impl TurtleDrawCircle {
|
||||
@ -72,15 +71,12 @@ impl TurtleDrawCircle {
|
||||
let line = path_builder.build();
|
||||
println!("Draw Circle: {} {} {:?}", center, radii, angle);
|
||||
|
||||
let bundle = ShapeBundle {
|
||||
path: GeometryBuilder::build_as(&line),
|
||||
..default()
|
||||
};
|
||||
Self {
|
||||
line: GeometryBuilder::build_as(
|
||||
&line,
|
||||
DrawMode::Outlined {
|
||||
fill_mode: FillMode::color(Color::rgba(0., 0., 0., 0.)),
|
||||
outline_mode: StrokeMode::new(Color::BLACK, 1.0),
|
||||
},
|
||||
Transform::IDENTITY,
|
||||
),
|
||||
line: bundle,
|
||||
name: Name::new(format!("Circle {}", index)),
|
||||
marker: CircleMarker,
|
||||
}
|
||||
@ -97,18 +93,15 @@ pub struct Turtle {
|
||||
|
||||
impl Default for Turtle {
|
||||
fn default() -> Self {
|
||||
let bundle = ShapeBundle {
|
||||
path: GeometryBuilder::build_as(&turtle_shapes::turtle()),
|
||||
..default()
|
||||
};
|
||||
Self {
|
||||
colors: Colors::default(),
|
||||
commands: TurtleCommands::new(vec![]),
|
||||
name: Name::new("Turtle"),
|
||||
shape: GeometryBuilder::build_as(
|
||||
&turtle_shapes::turtle(),
|
||||
DrawMode::Outlined {
|
||||
fill_mode: FillMode::color(Color::MIDNIGHT_BLUE),
|
||||
outline_mode: StrokeMode::new(Color::BLACK, 1.0),
|
||||
},
|
||||
Transform::IDENTITY,
|
||||
),
|
||||
shape: bundle,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use bevy_prototype_lyon::prelude::PathBuilder;
|
||||
|
||||
use crate::{
|
||||
datatypes::{
|
||||
angle::{Angle, AngleUnit},
|
||||
angle::Angle,
|
||||
length::Length,
|
||||
Coordinate,
|
||||
},
|
||||
|
@ -4,7 +4,6 @@ pub mod turtle;
|
||||
use std::time::Duration;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_inspector_egui::{Inspectable, RegisterInspectable};
|
||||
use bevy_prototype_lyon::prelude::*;
|
||||
use bevy_tweening::{
|
||||
component_animator_system, lens::TransformScaleLens, Animator, EaseFunction, RepeatCount,
|
||||
@ -29,19 +28,19 @@ impl Plugin for TurtlePlugin {
|
||||
.add_system(keypresses)
|
||||
.add_system(draw_lines)
|
||||
.add_system(component_animator_system::<Path>)
|
||||
.register_inspectable::<Colors>()
|
||||
.register_inspectable::<TurtleCommands>();
|
||||
.register_type::<Colors>()
|
||||
.register_type::<TurtleCommands>();
|
||||
}
|
||||
}
|
||||
pub type Precision = f32;
|
||||
|
||||
#[derive(Component, Inspectable)]
|
||||
#[derive(Component, Reflect)]
|
||||
pub struct TurtleCommands {
|
||||
commands: Vec<TurtleCommand>,
|
||||
lines: Vec<TurtleGraphElement>,
|
||||
state: TurtleState,
|
||||
}
|
||||
#[derive(Inspectable)]
|
||||
#[derive(Reflect)]
|
||||
pub struct TurtleState {
|
||||
pub start: Vec2,
|
||||
pub heading: Angle<f32>,
|
||||
@ -92,6 +91,8 @@ impl TurtleCommands {
|
||||
turtle_animation: None,
|
||||
line_segment: None,
|
||||
line_animation: None,
|
||||
fill: None,
|
||||
stroke: None,
|
||||
}
|
||||
}
|
||||
TurtleCommand::PenDown => {
|
||||
@ -101,6 +102,8 @@ impl TurtleCommands {
|
||||
turtle_animation: None,
|
||||
line_segment: None,
|
||||
line_animation: None,
|
||||
fill: None,
|
||||
stroke: None,
|
||||
}
|
||||
}
|
||||
TurtleCommand::Circle { radius, angle } => {
|
||||
@ -118,7 +121,7 @@ impl TurtleCommands {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Inspectable, Default)]
|
||||
#[derive(Reflect, Default)]
|
||||
pub enum TurtleGraphElement {
|
||||
TurtleLine(TurtleDrawLine),
|
||||
TurtleCircle(TurtleDrawCircle),
|
||||
@ -126,16 +129,16 @@ pub enum TurtleGraphElement {
|
||||
Noop,
|
||||
}
|
||||
|
||||
#[derive(Clone, Component, Inspectable)]
|
||||
#[derive(Clone, Component, Reflect)]
|
||||
pub struct TurtleShape;
|
||||
|
||||
#[derive(Clone, Component, Inspectable, Default)]
|
||||
#[derive(Clone, Component, Reflect, Default)]
|
||||
pub struct Colors {
|
||||
color: Color,
|
||||
fill_color: Color,
|
||||
}
|
||||
|
||||
#[derive(Component, Inspectable, Default)]
|
||||
#[derive(Component, Reflect, Default)]
|
||||
pub enum TurtleCommand {
|
||||
Forward(Length),
|
||||
Backward(Length),
|
||||
@ -169,12 +172,18 @@ fn setup(mut commands: Commands) {
|
||||
commands.spawn(Camera2dBundle::default());
|
||||
let mut turtle_bundle = Turtle::default();
|
||||
let mut tcommands = vec![];
|
||||
for _ in 0..100 {
|
||||
tcommands.append(&mut paths::geometry_task::geometry_task());
|
||||
tcommands.append(&mut paths::circle_star::circle_star());
|
||||
}
|
||||
//for _ in 0..100 {
|
||||
tcommands.append(&mut paths::geometry_task::geometry_task());
|
||||
//tcommands.append(&mut paths::circle_star::circle_star());
|
||||
//}
|
||||
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(
|
||||
@ -183,7 +192,7 @@ fn draw_lines(
|
||||
mut turtle: Query<&mut Animator<Transform>, With<TurtleShape>>,
|
||||
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();
|
||||
run_animation_step(&mut commands, &mut tcmd, &mut turtle)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use bevy::prelude::{Quat, Transform, Vec2, Vec3};
|
||||
use bevy_prototype_lyon::prelude::Path;
|
||||
use bevy::prelude::{default, Color, Quat, Transform, Vec2, Vec3};
|
||||
use bevy_prototype_lyon::prelude::{Fill, Path, Stroke};
|
||||
use bevy_tweening::{
|
||||
lens::{TransformPositionLens, TransformRotateZLens},
|
||||
Animator, EaseFunction, Tween,
|
||||
@ -20,6 +20,8 @@ pub struct TurtleStep {
|
||||
pub turtle_animation: Option<Tween<Transform>>,
|
||||
pub line_segment: Option<TurtleGraphElement>,
|
||||
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 {
|
||||
@ -42,6 +44,8 @@ pub fn turtle_turn(state: &mut TurtleState, angle_to_turn: Angle<Precision>) ->
|
||||
turtle_animation: Some(animation),
|
||||
line_segment: Some(line),
|
||||
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),
|
||||
line_segment: Some(line),
|
||||
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),
|
||||
line_segment: Some(line),
|
||||
line_animation: Some(line_animator),
|
||||
fill: Some(Fill::color(Color::MIDNIGHT_BLUE)),
|
||||
stroke: Some(Stroke::color(Color::BLACK)),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user