From 81df0cd02fa9d6eeac72ea97e169219e9522276b Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Mon, 19 Sep 2022 10:54:10 +0200 Subject: [PATCH] Add rustfmt config --- planet/rustfmt.toml | 11 ++++ planet/src/biome.rs | 116 +++++++++++++++++------------------ planet/src/math_util.rs | 17 ++--- planet/src/saving.rs | 44 ++++++------- planet/src/world.rs | 108 ++++++++++++++++---------------- planet/src/world_manager.rs | 45 +++++++------- rustfmt.toml | 11 ++++ src/main.rs | 81 ++++++++++++++---------- src/plugins/world_plugins.rs | 20 ++++-- src/ui_helpers.rs | 13 ++-- 10 files changed, 259 insertions(+), 207 deletions(-) create mode 100644 planet/rustfmt.toml create mode 100644 rustfmt.toml diff --git a/planet/rustfmt.toml b/planet/rustfmt.toml new file mode 100644 index 0000000..c1f5bf5 --- /dev/null +++ b/planet/rustfmt.toml @@ -0,0 +1,11 @@ +imports_granularity = "One" +group_imports = "One" +enum_discrim_align_threshold = 15 +imports_layout = "HorizontalVertical" +match_block_trailing_comma = true +newline_style = "Native" +reorder_impl_items = true +struct_field_align_threshold = 20 +use_field_init_shorthand = true +use_try_shorthand = true +wrap_comments = true \ No newline at end of file diff --git a/planet/src/biome.rs b/planet/src/biome.rs index bfa4643..1e93906 100644 --- a/planet/src/biome.rs +++ b/planet/src/biome.rs @@ -1,19 +1,19 @@ -use serde::{Deserialize, Serialize}; - #[cfg(feature = "render")] use bevy::render::color::Color; - -use crate::World; +use { + crate::World, + serde::{Deserialize, Serialize}, +}; #[derive(Debug, Clone, Default)] pub struct Biome { - pub name: String, + pub name: String, #[cfg(feature = "render")] - pub color: Color, - pub min_altitude: f32, - pub max_altitude: f32, - pub min_rainfall: f32, - pub max_rainfall: f32, + pub color: Color, + pub min_altitude: f32, + pub max_altitude: f32, + pub min_rainfall: f32, + pub max_rainfall: f32, pub min_temperature: f32, pub max_temperature: f32, } @@ -37,82 +37,82 @@ impl From for Biome { fn from(biome_type: BiomeType) -> Biome { match biome_type { BiomeType::IceCap => Biome { - name: "Ice Cap".into(), - color: Color::rgb_u8(253, 244, 235), - min_altitude: World::MIN_ALTITUDE, - max_altitude: World::MAX_ALTITUDE, - min_rainfall: World::MIN_RAINFALL, - max_rainfall: World::MAX_RAINFALL, + name: "Ice Cap".into(), + color: Color::rgb_u8(253, 244, 235), + min_altitude: World::MIN_ALTITUDE, + max_altitude: World::MAX_ALTITUDE, + min_rainfall: World::MIN_RAINFALL, + max_rainfall: World::MAX_RAINFALL, min_temperature: World::MIN_TEMPERATURE, max_temperature: -15.0, }, BiomeType::Ocean => Biome { - name: "Ocean".into(), - color: Color::rgb_u8(28, 66, 84), - min_altitude: World::MIN_ALTITUDE, - max_altitude: 0.0, - min_rainfall: World::MIN_RAINFALL, - max_rainfall: World::MAX_RAINFALL, + name: "Ocean".into(), + color: Color::rgb_u8(28, 66, 84), + min_altitude: World::MIN_ALTITUDE, + max_altitude: 0.0, + min_rainfall: World::MIN_RAINFALL, + max_rainfall: World::MAX_RAINFALL, min_temperature: -15.0, max_temperature: World::MAX_TEMPERATURE, }, BiomeType::Grassland => Biome { - name: "Grassland".into(), - color: Color::rgb_u8(167, 177, 84), - min_altitude: 0.0, - max_altitude: World::MAX_ALTITUDE, - min_rainfall: 25.0, - max_rainfall: 1475.0, + name: "Grassland".into(), + color: Color::rgb_u8(167, 177, 84), + min_altitude: 0.0, + max_altitude: World::MAX_ALTITUDE, + min_rainfall: 25.0, + max_rainfall: 1475.0, min_temperature: -5.0, max_temperature: World::MAX_TEMPERATURE, }, BiomeType::Forest => Biome { - name: "Forest".into(), - color: Color::rgb_u8(76, 132, 55), - min_altitude: 0.0, - max_altitude: World::MAX_ALTITUDE, - min_rainfall: 975.0, - max_rainfall: 2475.0, + name: "Forest".into(), + color: Color::rgb_u8(76, 132, 55), + min_altitude: 0.0, + max_altitude: World::MAX_ALTITUDE, + min_rainfall: 975.0, + max_rainfall: 2475.0, min_temperature: -5.0, max_temperature: World::MAX_TEMPERATURE, }, BiomeType::Taiga => Biome { - name: "Taiga".into(), - color: Color::rgb_u8(43, 63, 40), - min_altitude: 0.0, - max_altitude: World::MAX_ALTITUDE, - min_rainfall: 475.0, - max_rainfall: World::MAX_RAINFALL, + name: "Taiga".into(), + color: Color::rgb_u8(43, 63, 40), + min_altitude: 0.0, + max_altitude: World::MAX_ALTITUDE, + min_rainfall: 475.0, + max_rainfall: World::MAX_RAINFALL, min_temperature: -15.0, max_temperature: -0.0, }, BiomeType::Tundra => Biome { - name: "Tundra ".into(), - color: Color::rgb_u8(139, 139, 128), - min_altitude: 0.0, - max_altitude: World::MAX_ALTITUDE, - min_rainfall: World::MIN_RAINFALL, - max_rainfall: 725.0, + name: "Tundra ".into(), + color: Color::rgb_u8(139, 139, 128), + min_altitude: 0.0, + max_altitude: World::MAX_ALTITUDE, + min_rainfall: World::MIN_RAINFALL, + max_rainfall: 725.0, min_temperature: -20.0, max_temperature: -0.0, }, BiomeType::Desert => Biome { - name: "Desert ".into(), - color: Color::rgb_u8(253, 225, 171), - min_altitude: 0.0, - max_altitude: World::MAX_ALTITUDE, - min_rainfall: World::MIN_RAINFALL, - max_rainfall: 125.0, + name: "Desert ".into(), + color: Color::rgb_u8(253, 225, 171), + min_altitude: 0.0, + max_altitude: World::MAX_ALTITUDE, + min_rainfall: World::MIN_RAINFALL, + max_rainfall: 125.0, min_temperature: -5.0, max_temperature: World::MAX_TEMPERATURE, }, BiomeType::Rainforest => Biome { - name: "Rainforest".into(), - color: Color::rgb_u8(59, 103, 43), - min_altitude: 0.0, - max_altitude: World::MAX_ALTITUDE, - min_rainfall: 1975.0, - max_rainfall: World::MAX_RAINFALL, + name: "Rainforest".into(), + color: Color::rgb_u8(59, 103, 43), + min_altitude: 0.0, + max_altitude: World::MAX_ALTITUDE, + min_rainfall: 1975.0, + max_rainfall: World::MAX_RAINFALL, min_temperature: -5.0, max_temperature: World::MAX_TEMPERATURE, }, diff --git a/planet/src/math_util.rs b/planet/src/math_util.rs index 910a966..d41c680 100644 --- a/planet/src/math_util.rs +++ b/planet/src/math_util.rs @@ -1,12 +1,13 @@ -use std::{ - error::Error, - f32::consts::{PI, TAU}, - fmt::{Debug, Display}, +use { + bevy::math::Vec3A, + rand::{rngs::StdRng, Rng}, + std::{ + error::Error, + f32::consts::{PI, TAU}, + fmt::{Debug, Display}, + }, }; -use bevy::math::Vec3A; -use rand::{rngs::StdRng, Rng}; - #[derive(Debug, Copy, Clone)] pub enum CartesianError { InvalidAlpha(f32), @@ -29,7 +30,7 @@ impl Display for CartesianError { match self { CartesianError::InvalidAlpha(alpha) => { f.write_fmt(format_args!("Alpha value must be [0..PI], was {}", alpha)) - } + }, } } } diff --git a/planet/src/saving.rs b/planet/src/saving.rs index 5c00611..589b62b 100644 --- a/planet/src/saving.rs +++ b/planet/src/saving.rs @@ -1,28 +1,28 @@ -use std::fmt::{self, Formatter}; - -use rand::{rngs::StdRng, SeedableRng}; -use serde::{ - de::{Error, MapAccess, SeqAccess, Visitor}, - Deserialize, +use { + crate::{TerrainCell, World}, + rand::{rngs::StdRng, SeedableRng}, + serde::{ + de::{Error, MapAccess, SeqAccess, Visitor}, + Deserialize, + }, + std::fmt::{self, Formatter}, }; -use crate::{TerrainCell, World}; - struct WorldTerrainAttributes { - max_altitude: f32, - min_altitude: f32, - max_rainfall: f32, - min_rainfall: f32, + max_altitude: f32, + min_altitude: f32, + max_rainfall: f32, + min_rainfall: f32, max_temperature: f32, min_temperature: f32, } impl Default for WorldTerrainAttributes { fn default() -> Self { Self { - max_altitude: World::MIN_ALTITUDE, - min_altitude: World::MAX_ALTITUDE, - max_rainfall: World::MIN_RAINFALL, - min_rainfall: World::MAX_RAINFALL, + max_altitude: World::MIN_ALTITUDE, + min_altitude: World::MAX_ALTITUDE, + max_rainfall: World::MIN_RAINFALL, + min_rainfall: World::MAX_RAINFALL, max_temperature: World::MIN_TEMPERATURE, min_temperature: World::MAX_TEMPERATURE, } @@ -148,37 +148,37 @@ impl<'de> Deserialize<'de> for World { return Err(Error::duplicate_field("width")); } width = Some(map.next_value()?); - } + }, Field::Height => { if height.is_some() { return Err(Error::duplicate_field("height")); } height = Some(map.next_value()?); - } + }, Field::Seed => { if seed.is_some() { return Err(Error::duplicate_field("seed")); } seed = Some(map.next_value()?); - } + }, Field::Terrain => { if terrain.is_some() { return Err(Error::duplicate_field("terrain")); } terrain = Some(map.next_value()?); - } + }, Field::ContinentOffsets => { if continent_offsets.is_some() { return Err(Error::duplicate_field("continent_offsets")); } continent_offsets = Some(map.next_value()?); - } + }, Field::ContinentWidths => { if continent_widths.is_some() { return Err(Error::duplicate_field("continent_widths")); } continent_widths = Some(map.next_value()?); - } + }, } } diff --git a/planet/src/world.rs b/planet/src/world.rs index f2ae2df..4031f2a 100644 --- a/planet/src/world.rs +++ b/planet/src/world.rs @@ -1,17 +1,24 @@ -use serde::{Deserialize, Serialize}; -use std::{ - error::Error, - f32::consts::{PI, TAU}, - fmt::{Debug, Display}, -}; - // TODO: Logging doesn't seem to work here? Figure out why and fix - -use crate::{biome::BiomeType, perlin, Biome}; -use bevy::{log::info, math::Vec3A, prelude::Vec2, utils::default}; -use rand::{rngs::StdRng, Rng, SeedableRng}; - -use crate::{cartesian_coordinates, mix_values, random_point_in_sphere, CartesianError, RepeatNum}; +use { + crate::{ + biome::BiomeType, + cartesian_coordinates, + mix_values, + perlin, + random_point_in_sphere, + Biome, + CartesianError, + RepeatNum, + }, + bevy::{log::info, math::Vec3A, prelude::Vec2, utils::default}, + rand::{rngs::StdRng, Rng, SeedableRng}, + serde::{Deserialize, Serialize}, + std::{ + error::Error, + f32::consts::{PI, TAU}, + fmt::{Debug, Display}, + }, +}; #[derive(Debug, Clone, Copy)] pub enum WorldGenError { @@ -42,39 +49,61 @@ impl Display for WorldGenError { #[derive(Debug, Serialize)] pub struct World { - pub width: u32, + pub width: u32, pub height: u32, - pub seed: u32, + pub seed: u32, - pub terrain: Vec>, + pub terrain: Vec>, pub continent_offsets: [Vec2; World::NUM_CONTINENTS as usize], - pub continent_widths: [f32; World::NUM_CONTINENTS as usize], + pub continent_widths: [f32; World::NUM_CONTINENTS as usize], #[serde(skip)] - pub max_altitude: f32, + pub max_altitude: f32, #[serde(skip)] - pub min_altitude: f32, + pub min_altitude: f32, #[serde(skip)] - pub max_rainfall: f32, + pub max_rainfall: f32, #[serde(skip)] - pub min_rainfall: f32, + pub min_rainfall: f32, #[serde(skip)] - pub max_temperature: f32, + pub max_temperature: f32, #[serde(skip)] - pub min_temperature: f32, + pub min_temperature: f32, #[serde(skip)] - pub rng: StdRng, + pub rng: StdRng, } #[derive(Debug, Clone, Default, Deserialize, Serialize)] pub struct TerrainCell { - pub altitude: f32, - pub rainfall: f32, + pub altitude: f32, + pub rainfall: f32, pub temperature: f32, pub biome_presences: Vec<(BiomeType, f32)>, } impl World { + const ALTITUDE_SPAN: f32 = World::MAX_ALTITUDE - World::MIN_ALTITUDE; + const CONTINENT_MAX_WIDTH_FACTOR: f32 = 7.0; + const CONTINENT_MIN_WIDTH_FACTOR: f32 = 3.0; + pub(crate) const MAX_ALTITUDE: f32 = 15000.0; + pub(crate) const MAX_RAINFALL: f32 = 7500.0; + pub(crate) const MAX_TEMPERATURE: f32 = 30.0; + pub(crate) const MIN_ALTITUDE: f32 = -15000.0; + pub(crate) const MIN_RAINFALL: f32 = 0.0; + pub(crate) const MIN_TEMPERATURE: f32 = -60.0; + const MOUNTAIN_RANGE_MIX_FACTOR: f32 = 0.075; + const MOUNTAIN_RANGE_WIDTH_FACTOR: f32 = 25.0; + const NUM_CONTINENTS: u8 = 7; + const RAINFALL_DRYNESS_FACTOR: f32 = 0.005; + const RAINFALL_DRYNESS_OFFSET: f32 = World::RAINFALL_DRYNESS_FACTOR * World::MAX_RAINFALL; + const RAINFALL_SPAN: f32 = World::MAX_RAINFALL - World::MIN_RAINFALL; + const TEMPERATURE_ALTITUDE_FACTOR: f32 = 1.0; + const TEMPERATURE_SPAN: f32 = World::MAX_TEMPERATURE - World::MIN_TEMPERATURE; + const TERRAIN_NOISE_FACTOR_1: f32 = 0.15; + const TERRAIN_NOISE_FACTOR_2: f32 = 0.15; + const TERRAIN_NOISE_FACTOR_3: f32 = 0.1; + const TERRAIN_NOISE_FACTOR_4: f32 = 2.5; + pub fn new(width: u32, height: u32, seed: u32) -> World { World { width, @@ -96,33 +125,6 @@ impl World { } } - const NUM_CONTINENTS: u8 = 7; - const CONTINENT_MIN_WIDTH_FACTOR: f32 = 3.0; - const CONTINENT_MAX_WIDTH_FACTOR: f32 = 7.0; - - pub(crate) const MIN_ALTITUDE: f32 = -15000.0; - pub(crate) const MAX_ALTITUDE: f32 = 15000.0; - const ALTITUDE_SPAN: f32 = World::MAX_ALTITUDE - World::MIN_ALTITUDE; - - const MOUNTAIN_RANGE_MIX_FACTOR: f32 = 0.075; - const MOUNTAIN_RANGE_WIDTH_FACTOR: f32 = 25.0; - - const TERRAIN_NOISE_FACTOR_1: f32 = 0.15; - const TERRAIN_NOISE_FACTOR_2: f32 = 0.15; - const TERRAIN_NOISE_FACTOR_3: f32 = 0.1; - const TERRAIN_NOISE_FACTOR_4: f32 = 2.5; - - pub(crate) const MIN_RAINFALL: f32 = 0.0; - pub(crate) const MAX_RAINFALL: f32 = 7500.0; - const RAINFALL_SPAN: f32 = World::MAX_RAINFALL - World::MIN_RAINFALL; - const RAINFALL_DRYNESS_FACTOR: f32 = 0.005; - const RAINFALL_DRYNESS_OFFSET: f32 = World::RAINFALL_DRYNESS_FACTOR * World::MAX_RAINFALL; - - pub(crate) const MIN_TEMPERATURE: f32 = -60.0; - pub(crate) const MAX_TEMPERATURE: f32 = 30.0; - const TEMPERATURE_SPAN: f32 = World::MAX_TEMPERATURE - World::MIN_TEMPERATURE; - const TEMPERATURE_ALTITUDE_FACTOR: f32 = 1.0; - pub fn generate(&mut self) -> Result<(), WorldGenError> { if let Err(err) = self.generate_altitude() { return Err(WorldGenError::CartesianError(err)); diff --git a/planet/src/world_manager.rs b/planet/src/world_manager.rs index 85e7def..0e75033 100644 --- a/planet/src/world_manager.rs +++ b/planet/src/world_manager.rs @@ -1,9 +1,7 @@ #[cfg(feature = "render")] use crate::TerrainCell; -use crate::{Biome, World, WorldGenError}; #[cfg(all(feature = "debug", feature = "render"))] use bevy::log::debug; -use bevy::log::warn; #[cfg(feature = "debug")] use bevy::utils::default; #[cfg(feature = "render")] @@ -12,13 +10,17 @@ use bevy::{ render::render_resource::Extent3d, render::{color::Color, texture::Image}, }; -use rand::random; -use std::{ - error::Error, - fmt::Display, - fs::File, - io::{self, Read, Write}, - path::Path, +use { + crate::{Biome, World, WorldGenError}, + bevy::log::warn, + rand::random, + std::{ + error::Error, + fmt::Display, + fs::File, + io::{self, Read, Write}, + path::Path, + }, }; #[derive(Debug)] @@ -86,17 +88,17 @@ impl Display for SaveError { #[derive(Debug)] pub struct WorldManager { + world: Option, #[cfg(feature = "render")] pub image_handle_id: Option, - world: Option, #[cfg(feature = "render")] - rainfall_visible: bool, + rainfall_visible: bool, #[cfg(feature = "render")] temperature_visible: bool, #[cfg(feature = "render")] - biomes_visible: bool, + biomes_visible: bool, #[cfg(feature = "render")] - contours: bool, + contours: bool, } impl WorldManager { @@ -122,14 +124,14 @@ impl WorldManager { None => { warn!("No world to save"); return Err(SaveError::MissingWorld); - } + }, }; #[cfg(feature = "debug")] let serialized = match ron::ser::to_string_pretty(world, default()) { Ok(serialized) => serialized, Err(err) => { return Err(SaveError::SerializationError(err)); - } + }, }; #[cfg(not(feature = "debug"))] @@ -137,7 +139,7 @@ impl WorldManager { Ok(serialized) => serialized, Err(err) => { return Err(SaveError::SerializationError(err)); - } + }, }; match File::create(path).unwrap().write_all(serialized.as_bytes()) { @@ -155,14 +157,14 @@ impl WorldManager { Ok(file) => file, Err(err) => { return Err(LoadError::MissingSave(err)); - } + }, }; let mut buf = String::new(); match file.read_to_string(&mut buf) { - Ok(_) => {} + Ok(_) => {}, Err(err) => { return Err(LoadError::MissingSave(err)); - } + }, }; match ron::from_str(buf.as_str()) { Ok(world) => { @@ -185,7 +187,7 @@ impl WorldManager { }); } Ok(()) - } + }, Err(err) => Err(LoadError::InvalidSave(err)), } } @@ -237,6 +239,7 @@ impl WorldManager { pub fn get_world(&self) -> Option<&World> { self.world.as_ref() } + pub fn world(&self) -> &World { assert!(self.world.is_some(), "No world."); self.get_world().unwrap() @@ -377,7 +380,7 @@ impl WorldManager { .iter() .map(|cell| self.generate_color(cell)) .collect() - } + }, } } diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..c1f5bf5 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,11 @@ +imports_granularity = "One" +group_imports = "One" +enum_discrim_align_threshold = 15 +imports_layout = "HorizontalVertical" +match_block_trailing_comma = true +newline_style = "Native" +reorder_impl_items = true +struct_field_align_threshold = 20 +use_field_init_shorthand = true +use_try_shorthand = true +wrap_comments = true \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 12228c0..a20b7ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,11 +37,6 @@ mod plugins; mod resources; mod ui_helpers; -use bevy::{ - app::App, - log::LogSettings, - utils::{default, tracing::Level}, -}; #[cfg(all(feature = "render", feature = "planet_view"))] use bevy::{ asset::Handle, @@ -67,7 +62,11 @@ use bevy::{ camera::{Camera, RenderTarget}, color::Color, render_resource::{ - Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages, + Extent3d, + TextureDescriptor, + TextureDimension, + TextureFormat, + TextureUsages, }, texture::{Image, ImageSettings}, }, @@ -76,14 +75,20 @@ use bevy::{ transform::components::GlobalTransform, ui::{ entity::{NodeBundle, TextBundle}, - AlignSelf, FocusPolicy, Interaction, JustifyContent, PositionType, Size, Style, UiColor, - UiRect, Val, + AlignSelf, + FocusPolicy, + Interaction, + JustifyContent, + PositionType, + Size, + Style, + UiColor, + UiRect, + Val, }, window::{CursorIcon, WindowDescriptor, Windows}, winit::WinitSettings, }; -use planet::Biome; - #[cfg(all(feature = "debug", feature = "render"))] use bevy::{ diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin}, @@ -94,12 +99,19 @@ use components::{ markers::{InfoPanel, ToolbarButton}, third_party::PanCam, }; -use planet::WorldManager; -use plugins::WorldPlugins; #[cfg(feature = "render")] use resources::CursorMapPosition; #[cfg(feature = "render")] use ui_helpers::{toolbar_button, toolbar_button_text}; +use { + bevy::{ + app::App, + log::LogSettings, + utils::{default, tracing::Level}, + }, + planet::{Biome, WorldManager}, + plugins::WorldPlugins, +}; #[cfg(feature = "render")] fn refresh_world_texture(images: &mut Assets, world_manager: &WorldManager) { @@ -110,13 +122,14 @@ fn refresh_world_texture(images: &mut Assets, world_manager: &WorldManage .get_mut(&image_handle) .expect("Image handle pointing to non-existing texture"); world_image.resize(Extent3d { - width: world_manager.world().width, - height: world_manager.world().height, + width: world_manager.world().width, + height: world_manager.world().height, depth_or_array_layers: 1, }); world_image.data = world_manager.world_color_bytes(); - // TODO: Update Icosphere material... try to find out why it doesn't automatically= + // TODO: Update Icosphere material. Try to find out why it doesn't + // automatically } #[cfg(feature = "render")] @@ -148,25 +161,25 @@ fn handle_toolbar_button( debug!("Toggling rainfall"); world_manager.toggle_rainfall(); refresh_world_texture(&mut images, &world_manager); - } + }, ToolbarButton::Temperature => { #[cfg(feature = "debug")] debug!("Toggling temperature"); world_manager.toggle_temperature(); refresh_world_texture(&mut images, &world_manager); - } + }, ToolbarButton::Biomes => { #[cfg(feature = "debug")] debug!("Toggling biomes"); world_manager.toggle_biomes(); refresh_world_texture(&mut images, &world_manager); - } + }, ToolbarButton::Contours => { #[cfg(feature = "debug")] debug!("Toggling contours"); world_manager.toggle_contours(); refresh_world_texture(&mut images, &world_manager); - } + }, ToolbarButton::GenerateWorld => { #[cfg(feature = "debug")] debug!("Generating new world"); @@ -174,28 +187,28 @@ fn handle_toolbar_button( .new_world() .expect("Failed to generate new world"); refresh_world_texture(&mut images, &world_manager); - } + }, ToolbarButton::SaveWorld => { #[cfg(feature = "debug")] debug!("Saving world"); _ = world_manager.save_world("planet.ron"); - } + }, ToolbarButton::LoadWorld => { #[cfg(feature = "debug")] debug!("Loading world"); _ = world_manager.load_world("planet.ron", &mut images); refresh_world_texture(&mut images, &world_manager); - } + }, } - } + }, Interaction::Hovered => { windows.primary_mut().set_cursor_icon(CursorIcon::Hand); *color = HOVERED_BUTTON.into(); - } + }, Interaction::None => { windows.primary_mut().set_cursor_icon(CursorIcon::Default); *color = NORMAL_BUTTON.into(); - } + }, } } } @@ -339,17 +352,17 @@ fn generate_graphics( let image_handle = images.add(Image { data: world_manager.world_color_bytes(), texture_descriptor: TextureDescriptor { - label: None, - size: Extent3d { + label: None, + size: Extent3d { width: world.width, height: world.height, ..default() }, - dimension: TextureDimension::D2, - format: TextureFormat::Rgba32Float, + dimension: TextureDimension::D2, + format: TextureFormat::Rgba32Float, mip_level_count: 1, - sample_count: 1, - usage: TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING, + sample_count: 1, + usage: TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING, }, ..default() }); @@ -372,7 +385,7 @@ fn generate_graphics( }); _ = commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(Icosphere { - radius: 2.0, + radius: 2.0, subdivisions: 9, })), material: materials.add(images.get_handle(world_manager.image_handle_id).into()), @@ -431,9 +444,9 @@ fn generate_graphics( text: Text::from_section( "Info Panel", bevy::text::TextStyle { - font: asset_server.load("JuliaMono.ttf"), + font: asset_server.load("JuliaMono.ttf"), font_size: 15.0, - color: Color::WHITE, + color: Color::WHITE, }, ), ..default() diff --git a/src/plugins/world_plugins.rs b/src/plugins/world_plugins.rs index 9763b5b..3bf8b2d 100644 --- a/src/plugins/world_plugins.rs +++ b/src/plugins/world_plugins.rs @@ -17,12 +17,22 @@ impl PluginGroup for WorldPlugins { #[cfg(feature = "render")] { - use bevy::{ - asset::AssetPlugin, core_pipeline::CorePipelinePlugin, hierarchy::HierarchyPlugin, - input::InputPlugin, render::RenderPlugin, sprite::SpritePlugin, text::TextPlugin, - transform::TransformPlugin, ui::UiPlugin, window::WindowPlugin, winit::WinitPlugin, + use { + bevy::{ + asset::AssetPlugin, + core_pipeline::CorePipelinePlugin, + hierarchy::HierarchyPlugin, + input::InputPlugin, + render::RenderPlugin, + sprite::SpritePlugin, + text::TextPlugin, + transform::TransformPlugin, + ui::UiPlugin, + window::WindowPlugin, + winit::WinitPlugin, + }, + bevy_pancam::PanCamPlugin, }; - use bevy_pancam::PanCamPlugin; _ = group .add(TransformPlugin::default()) diff --git a/src/ui_helpers.rs b/src/ui_helpers.rs index eb2e043..8bec912 100644 --- a/src/ui_helpers.rs +++ b/src/ui_helpers.rs @@ -1,4 +1,6 @@ #[cfg(feature = "render")] +use crate::{components::markers::ToolbarButton, NORMAL_BUTTON}; +#[cfg(feature = "render")] use bevy::{ asset::AssetServer, ecs::system::Res, @@ -7,14 +9,13 @@ use bevy::{ ui::{ entity::{ButtonBundle, TextBundle}, widget::Button, - AlignItems, JustifyContent, Style, + AlignItems, + JustifyContent, + Style, }, utils::default, }; -#[cfg(feature = "render")] -use crate::{components::markers::ToolbarButton, NORMAL_BUTTON}; - #[cfg(feature = "render")] pub(crate) fn toolbar_button() -> ButtonBundle { ButtonBundle { @@ -38,9 +39,9 @@ pub(crate) fn toolbar_button_text( text: Text::from_section( which, TextStyle { - font: asset_server.load("JuliaMono.ttf"), + font: asset_server.load("JuliaMono.ttf"), font_size: 20.0, - color: Color::WHITE, + color: Color::WHITE, }, ), ..default()