diff --git a/Cargo.toml b/Cargo.toml index a854b03..3dabe60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,9 @@ serde = "1.0.195" serde_json = "1.0.111" wasm-bindgen = "0.2.89" +[dev-dependencies] +bevy = "0.14.0" + # Enable max optimizations for dependencies, but not for our code: [profile.dev.package."*"] opt-level = 3 diff --git a/README.md b/README.md index 9914a6d..7039a19 100644 --- a/README.md +++ b/README.md @@ -31,81 +31,10 @@ cargo add bevy_generative ## Examples -### Maps and Textures - -```rust -use bevy::prelude::*; -use bevy_generative::map::{MapBundle, MapPlugin}; - -fn main() { - App::new() - .add_plugins(DefaultPlugins) - .add_plugins(MapPlugin) - .add_systems(Startup, setup) - .run(); -} - -fn setup(mut commands: Commands) { - commands.spawn(Camera2dBundle::default()); - commands.spawn(MapBundle::default()); -} - -``` - -### Terrain - -```rust -use bevy::prelude::*; -use bevy_generative::terrain::{TerrainBundle, TerrainPlugin}; - -fn main() { - App::new() - .add_plugins(DefaultPlugins) - .add_plugins(TerrainPlugin) - .add_systems(Startup, setup) - .run(); -} - -fn setup(mut commands: Commands) { - commands.spawn(PointLightBundle { - transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); - commands.spawn(TerrainBundle::default()); -} - -``` - -### Planets - -```rust -use bevy::prelude::*; -use bevy_generative::planet::{PlanetBundle, PlanetPlugin}; - -fn main() { - App::new() - .add_plugins(DefaultPlugins) - .add_plugins(PlanetPlugin) - .add_systems(Startup, setup) - .run(); -} - -fn setup(mut commands: Commands) { - commands.spawn(PointLightBundle { - transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); - commands.spawn(PlanetBundle::default()); -} +Examples are provided in the [examples](./examples) directory. To run an example, clone this repository and invoke cargo like this: +```sh +cargo run --example map ``` ## Bevy Compatibility diff --git a/examples/export.rs b/examples/export.rs new file mode 100644 index 0000000..aacc6da --- /dev/null +++ b/examples/export.rs @@ -0,0 +1,78 @@ +use bevy::prelude::*; +use bevy_generative::terrain::{Terrain, TerrainBundle, TerrainPlugin}; + +fn main() { + App::new() + .add_plugins(DefaultPlugins) + .add_plugins(TerrainPlugin) + .add_systems(Startup, setup) + .add_systems(Update, (button_appearance, export_button)) + .run(); +} + +fn setup(mut commands: Commands) { + commands.spawn(PointLightBundle { + transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + ..default() + }); + commands.spawn(Camera3dBundle { + transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + ..default() + }); + commands.spawn(TerrainBundle::default()); + + commands + .spawn(ButtonBundle { + style: Style { + padding: UiRect::all(Val::Px(12.)), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, + margin: UiRect::all(Val::Px(12.)), + ..default() + }, + border_radius: BorderRadius::all(Val::Px(5.)), + background_color: NORMAL_BUTTON.into(), + ..default() + }) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "Export", + TextStyle { + font_size: 30.0, + color: BUTTON_TEXT.into(), + ..default() + }, + )); + }); +} + +fn export_button( + interaction_query: Query<&Interaction, (Changed, With