Reorder use statements

This commit is contained in:
Timothy Warren 2021-12-10 20:16:48 -05:00
parent ce3d92bfe2
commit 9ff645066b
30 changed files with 140 additions and 78 deletions

View File

@ -14,7 +14,7 @@ lint:
cargo clippy cargo clippy
fmt: fmt:
cargo fmt cargo +nightly fmt
fix: fmt fix: fmt
cargo fix --allow-dirty --allow-staged cargo fix --allow-dirty --allow-staged

7
rustfmt.toml Normal file
View File

@ -0,0 +1,7 @@
unstable_features = true
format_code_in_doc_comments = true
format_macro_matchers = true
format_strings = true
imports_granularity = "Module"
group_imports = "StdExternalCrate"
use_field_init_shorthand = true

View File

@ -1,7 +1,9 @@
use crate::components::{CombatStats, Name, Player, SufferDamage};
use crate::{game_log::GameLog, Map, Position, RunState};
use specs::prelude::*; use specs::prelude::*;
use crate::components::{CombatStats, Name, Player, SufferDamage};
use crate::game_log::GameLog;
use crate::{Map, Position, RunState};
pub struct DamageSystem {} pub struct DamageSystem {}
impl<'a> System<'a> for DamageSystem { impl<'a> System<'a> for DamageSystem {

View File

@ -1,9 +1,12 @@
use rltk::{Point, Rltk, VirtualKeyCode, RGB};
use specs::prelude::*;
use crate::components::{ use crate::components::{
CombatStats, HungerClock, HungerState, InBackpack, Name, Player, Position, Viewshed, CombatStats, HungerClock, HungerState, InBackpack, Name, Player, Position, Viewshed,
}; };
use crate::{game_log::GameLog, rex_assets::RexAssets, Equipped, Hidden, Map, RunState, State}; use crate::game_log::GameLog;
use rltk::{Point, Rltk, VirtualKeyCode, RGB}; use crate::rex_assets::RexAssets;
use specs::prelude::*; use crate::{Equipped, Hidden, Map, RunState, State};
pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
ctx.draw_box( ctx.draw_box(

View File

@ -1,7 +1,9 @@
use crate::components::{HungerClock, HungerState, SufferDamage};
use crate::{game_log::GameLog, RunState};
use specs::prelude::*; use specs::prelude::*;
use crate::components::{HungerClock, HungerState, SufferDamage};
use crate::game_log::GameLog;
use crate::RunState;
pub struct HungerSystem {} pub struct HungerSystem {}
impl<'a> System<'a> for HungerSystem { impl<'a> System<'a> for HungerSystem {

View File

@ -1,8 +1,11 @@
use crate::components::*;
use crate::{game_log::GameLog, particle_system::ParticleBuilder, Map, RunState};
use rltk::RGB; use rltk::RGB;
use specs::prelude::*; use specs::prelude::*;
use crate::components::*;
use crate::game_log::GameLog;
use crate::particle_system::ParticleBuilder;
use crate::{Map, RunState};
pub struct ItemCollectionSystem {} pub struct ItemCollectionSystem {}
impl<'a> System<'a> for ItemCollectionSystem { impl<'a> System<'a> for ItemCollectionSystem {

View File

@ -1,7 +1,8 @@
use std::collections::HashSet;
use rltk::{Algorithm2D, BaseMap, Point, Rltk, SmallVec, RGB}; use rltk::{Algorithm2D, BaseMap, Point, Rltk, SmallVec, RGB};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use specs::prelude::*; use specs::prelude::*;
use std::collections::HashSet;
pub const MAP_WIDTH: usize = 80; pub const MAP_WIDTH: usize = 80;
pub const MAP_HEIGHT: usize = 43; pub const MAP_HEIGHT: usize = 43;

View File

@ -10,7 +10,6 @@ mod simple_map;
mod voronoi; mod voronoi;
mod waveform_collapse; mod waveform_collapse;
use crate::{spawner, Map, Position};
use bsp_dungeon::BspDungeonBuilder; use bsp_dungeon::BspDungeonBuilder;
use bsp_interior::BspInteriorBuilder; use bsp_interior::BspInteriorBuilder;
use cellular_automata::CellularAutomataBuilder; use cellular_automata::CellularAutomataBuilder;
@ -24,6 +23,8 @@ use specs::prelude::*;
use voronoi::VoronoiCellBuilder; use voronoi::VoronoiCellBuilder;
use waveform_collapse::WaveformCollapseBuilder; use waveform_collapse::WaveformCollapseBuilder;
use crate::{spawner, Map, Position};
pub trait MapBuilder { pub trait MapBuilder {
fn get_map(&self) -> Map; fn get_map(&self) -> Map;
fn get_starting_position(&self) -> Position; fn get_starting_position(&self) -> Position;

View File

@ -1,10 +1,11 @@
use super::MapBuilder;
use crate::map_builders::common::apply_room_to_map;
use crate::spawner;
use crate::{components::Position, Map, Rect, TileType, SHOW_MAPGEN_VISUALIZER};
use rltk::RandomNumberGenerator; use rltk::RandomNumberGenerator;
use specs::prelude::*; use specs::prelude::*;
use super::MapBuilder;
use crate::components::Position;
use crate::map_builders::common::apply_room_to_map;
use crate::{spawner, Map, Rect, TileType, SHOW_MAPGEN_VISUALIZER};
pub struct BspDungeonBuilder { pub struct BspDungeonBuilder {
map: Map, map: Map,
starting_position: Position, starting_position: Position,

View File

@ -1,9 +1,10 @@
use super::MapBuilder;
use crate::spawner;
use crate::{components::Position, Map, Rect, TileType, SHOW_MAPGEN_VISUALIZER};
use rltk::RandomNumberGenerator; use rltk::RandomNumberGenerator;
use specs::prelude::*; use specs::prelude::*;
use super::MapBuilder;
use crate::components::Position;
use crate::{spawner, Map, Rect, TileType, SHOW_MAPGEN_VISUALIZER};
const MIN_ROOM_SIZE: i32 = 8; const MIN_ROOM_SIZE: i32 = 8;
pub struct BspInteriorBuilder { pub struct BspInteriorBuilder {

View File

@ -1,11 +1,14 @@
use std::collections::HashMap;
use rltk::RandomNumberGenerator;
use specs::prelude::*;
use super::common::{ use super::common::{
generate_voronoi_spawn_regions, remove_unreachable_areas_returning_most_distant, generate_voronoi_spawn_regions, remove_unreachable_areas_returning_most_distant,
}; };
use super::MapBuilder; use super::MapBuilder;
use crate::{components::Position, spawner, Map, TileType, SHOW_MAPGEN_VISUALIZER}; use crate::components::Position;
use rltk::RandomNumberGenerator; use crate::{spawner, Map, TileType, SHOW_MAPGEN_VISUALIZER};
use specs::prelude::*;
use std::collections::HashMap;
pub struct CellularAutomataBuilder { pub struct CellularAutomataBuilder {
map: Map, map: Map,

View File

@ -1,7 +1,8 @@
use crate::{Map, Rect, TileType};
use std::cmp::{max, min}; use std::cmp::{max, min};
use std::collections::HashMap; use std::collections::HashMap;
use crate::{Map, Rect, TileType};
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Copy, Clone)]
#[allow(dead_code)] #[allow(dead_code)]
pub enum Symmetry { pub enum Symmetry {

View File

@ -1,12 +1,15 @@
use std::collections::HashMap;
use rltk::RandomNumberGenerator;
use specs::prelude::*;
use super::common::{ use super::common::{
generate_voronoi_spawn_regions, paint, remove_unreachable_areas_returning_most_distant, generate_voronoi_spawn_regions, paint, remove_unreachable_areas_returning_most_distant,
Symmetry, Symmetry,
}; };
use super::MapBuilder; use super::MapBuilder;
use crate::{components::Position, spawner, Map, TileType, SHOW_MAPGEN_VISUALIZER}; use crate::components::Position;
use rltk::RandomNumberGenerator; use crate::{spawner, Map, TileType, SHOW_MAPGEN_VISUALIZER};
use specs::prelude::*;
use std::collections::HashMap;
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Copy, Clone)]
pub enum DLAAlgorithm { pub enum DLAAlgorithm {

View File

@ -1,12 +1,15 @@
use std::collections::HashMap;
use rltk::RandomNumberGenerator;
use specs::prelude::*;
use super::common::{ use super::common::{
generate_voronoi_spawn_regions, paint, remove_unreachable_areas_returning_most_distant, generate_voronoi_spawn_regions, paint, remove_unreachable_areas_returning_most_distant,
Symmetry, Symmetry,
}; };
use super::MapBuilder; use super::MapBuilder;
use crate::{components::Position, spawner, Map, TileType, SHOW_MAPGEN_VISUALIZER}; use crate::components::Position;
use rltk::RandomNumberGenerator; use crate::{spawner, Map, TileType, SHOW_MAPGEN_VISUALIZER};
use specs::prelude::*;
use std::collections::HashMap;
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Copy, Clone)]
pub enum DrunkSpawnMode { pub enum DrunkSpawnMode {

View File

@ -1,11 +1,14 @@
use super::MapBuilder;
use super::{generate_voronoi_spawn_regions, remove_unreachable_areas_returning_most_distant};
use crate::{spawner, Map, Position, TileType, SHOW_MAPGEN_VISUALIZER};
use rltk::RandomNumberGenerator;
use specs::prelude::*;
use std::cmp::{max, min}; use std::cmp::{max, min};
use std::collections::HashMap; use std::collections::HashMap;
use rltk::RandomNumberGenerator;
use specs::prelude::*;
use super::{
generate_voronoi_spawn_regions, remove_unreachable_areas_returning_most_distant, MapBuilder,
};
use crate::{spawner, Map, Position, TileType, SHOW_MAPGEN_VISUALIZER};
pub struct MazeBuilder { pub struct MazeBuilder {
map: Map, map: Map,
starting_position: Position, starting_position: Position,

View File

@ -1,11 +1,12 @@
mod prefab_levels; mod prefab_levels;
mod prefab_sections; mod prefab_sections;
use super::{remove_unreachable_areas_returning_most_distant, MapBuilder};
use crate::{spawner, Map, Position, TileType, SHOW_MAPGEN_VISUALIZER};
use rltk::RandomNumberGenerator; use rltk::RandomNumberGenerator;
use specs::prelude::*; use specs::prelude::*;
use super::{remove_unreachable_areas_returning_most_distant, MapBuilder};
use crate::{spawner, Map, Position, TileType, SHOW_MAPGEN_VISUALIZER};
#[derive(PartialEq, Clone)] #[derive(PartialEq, Clone)]
#[allow(dead_code)] #[allow(dead_code)]
pub enum PrefabMode { pub enum PrefabMode {

View File

@ -1,9 +1,9 @@
use super::{apply_horizontal_tunnel, apply_room_to_map, apply_vertical_tunnel, MapBuilder};
use crate::{spawner, SHOW_MAPGEN_VISUALIZER};
use crate::{Map, Position, Rect, TileType};
use rltk::RandomNumberGenerator; use rltk::RandomNumberGenerator;
use specs::prelude::*; use specs::prelude::*;
use super::{apply_horizontal_tunnel, apply_room_to_map, apply_vertical_tunnel, MapBuilder};
use crate::{spawner, Map, Position, Rect, TileType, SHOW_MAPGEN_VISUALIZER};
pub struct SimpleMapBuilder { pub struct SimpleMapBuilder {
map: Map, map: Map,
starting_position: Position, starting_position: Position,

View File

@ -1,11 +1,14 @@
use std::collections::HashMap;
use rltk::RandomNumberGenerator;
use specs::prelude::*;
use super::common::{ use super::common::{
generate_voronoi_spawn_regions, remove_unreachable_areas_returning_most_distant, generate_voronoi_spawn_regions, remove_unreachable_areas_returning_most_distant,
}; };
use super::MapBuilder; use super::MapBuilder;
use crate::{components::Position, spawner, Map, TileType, SHOW_MAPGEN_VISUALIZER}; use crate::components::Position;
use rltk::RandomNumberGenerator; use crate::{spawner, Map, TileType, SHOW_MAPGEN_VISUALIZER};
use specs::prelude::*;
use std::collections::HashMap;
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Copy, Clone)]
#[allow(dead_code)] #[allow(dead_code)]

View File

@ -2,17 +2,19 @@ mod common;
mod constraints; mod constraints;
mod solver; mod solver;
use std::collections::HashMap;
use common::*;
use constraints::*;
use rltk::RandomNumberGenerator;
use solver::*;
use specs::prelude::*;
use super::common::{ use super::common::{
generate_voronoi_spawn_regions, remove_unreachable_areas_returning_most_distant, generate_voronoi_spawn_regions, remove_unreachable_areas_returning_most_distant,
}; };
use super::MapBuilder; use super::MapBuilder;
use crate::{spawner, Map, Position, TileType, SHOW_MAPGEN_VISUALIZER}; use crate::{spawner, Map, Position, TileType, SHOW_MAPGEN_VISUALIZER};
use common::*;
use constraints::*;
use rltk::RandomNumberGenerator;
use solver::*;
use specs::prelude::*;
use std::collections::HashMap;
pub struct WaveformCollapseBuilder { pub struct WaveformCollapseBuilder {
map: Map, map: Map,

View File

@ -1,7 +1,8 @@
use std::collections::HashSet;
use super::MapChunk; use super::MapChunk;
use crate::map_builders::waveform_collapse::common::tile_idx_in_chunk; use crate::map_builders::waveform_collapse::common::tile_idx_in_chunk;
use crate::{Map, TileType}; use crate::{Map, TileType};
use std::collections::HashSet;
pub fn build_patterns( pub fn build_patterns(
map: &Map, map: &Map,

View File

@ -1,6 +1,7 @@
use std::collections::HashSet;
use super::common::MapChunk; use super::common::MapChunk;
use crate::Map; use crate::Map;
use std::collections::HashSet;
pub struct Solver { pub struct Solver {
constraints: Vec<MapChunk>, constraints: Vec<MapChunk>,

View File

@ -1,6 +1,7 @@
use crate::{BlocksTile, Map, Position};
use specs::prelude::*; use specs::prelude::*;
use crate::{BlocksTile, Map, Position};
pub struct MapIndexingSystem {} pub struct MapIndexingSystem {}
impl<'a> System<'a> for MapIndexingSystem { impl<'a> System<'a> for MapIndexingSystem {

View File

@ -1,10 +1,13 @@
use rltk::RGB;
use specs::prelude::*;
use crate::components::{ use crate::components::{
CombatStats, DefenseBonus, Equipped, HungerClock, HungerState, MeleePowerBonus, Name, CombatStats, DefenseBonus, Equipped, HungerClock, HungerState, MeleePowerBonus, Name,
SufferDamage, WantsToMelee, SufferDamage, WantsToMelee,
}; };
use crate::{game_log::GameLog, particle_system::ParticleBuilder, Position}; use crate::game_log::GameLog;
use rltk::RGB; use crate::particle_system::ParticleBuilder;
use specs::prelude::*; use crate::Position;
pub struct MeleeCombatSystem {} pub struct MeleeCombatSystem {}

View File

@ -1,8 +1,10 @@
use crate::components::{Confusion, Monster, Position, Viewshed, WantsToMelee};
use crate::{particle_system::ParticleBuilder, EntityMoved, Map, RunState};
use rltk::{Point, RGB}; use rltk::{Point, RGB};
use specs::prelude::*; use specs::prelude::*;
use crate::components::{Confusion, Monster, Position, Viewshed, WantsToMelee};
use crate::particle_system::ParticleBuilder;
use crate::{EntityMoved, Map, RunState};
pub struct MonsterAI {} pub struct MonsterAI {}
impl<'a> System<'a> for MonsterAI { impl<'a> System<'a> for MonsterAI {

View File

@ -1,8 +1,9 @@
use crate::components::{ParticleLifetime, Renderable};
use crate::Position;
use rltk::{Rltk, RGB}; use rltk::{Rltk, RGB};
use specs::prelude::*; use specs::prelude::*;
use crate::components::{ParticleLifetime, Renderable};
use crate::Position;
pub fn cull_dead_particles(ecs: &mut World, ctx: &Rltk) { pub fn cull_dead_particles(ecs: &mut World, ctx: &Rltk) {
let mut dead_particles: Vec<Entity> = Vec::new(); let mut dead_particles: Vec<Entity> = Vec::new();
{ {

View File

@ -1,11 +1,14 @@
use std::cmp::{max, min};
use rltk::{Point, Rltk, VirtualKeyCode};
use specs::prelude::*;
use crate::components::{ use crate::components::{
CombatStats, EntityMoved, HungerClock, HungerState, Item, Monster, Player, Position, Viewshed, CombatStats, EntityMoved, HungerClock, HungerState, Item, Monster, Player, Position, Viewshed,
WantsToMelee, WantsToPickupItem, WantsToMelee, WantsToPickupItem,
}; };
use crate::{game_log::GameLog, Map, RunState, State, TileType}; use crate::game_log::GameLog;
use rltk::{Point, Rltk, VirtualKeyCode}; use crate::{Map, RunState, State, TileType};
use specs::prelude::*;
use std::cmp::{max, min};
pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) { pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
let mut positions = ecs.write_storage::<Position>(); let mut positions = ecs.write_storage::<Position>();

View File

@ -1,12 +1,14 @@
use crate::components::*; use std::fs;
use std::fs::File;
use std::path::Path;
use specs::error::NoError; use specs::error::NoError;
use specs::prelude::*; use specs::prelude::*;
use specs::saveload::{ use specs::saveload::{
DeserializeComponents, MarkedBuilder, SerializeComponents, SimpleMarker, SimpleMarkerAllocator, DeserializeComponents, MarkedBuilder, SerializeComponents, SimpleMarker, SimpleMarkerAllocator,
}; };
use std::fs;
use std::fs::File; use crate::components::*;
use std::path::Path;
macro_rules! serialize_individually { macro_rules! serialize_individually {
($ecs:expr, $ser:expr, $data:expr, $( $type:ty),*,) => { ($ecs:expr, $ser:expr, $data:expr, $( $type:ty),*,) => {

View File

@ -1,9 +1,13 @@
use crate::components::*; use std::collections::HashMap;
use crate::{map::MAP_WIDTH, random_table::RandomTable, Map, Rect, TileType};
use rltk::{RandomNumberGenerator, RGB}; use rltk::{RandomNumberGenerator, RGB};
use specs::prelude::*; use specs::prelude::*;
use specs::saveload::{MarkedBuilder, SimpleMarker}; use specs::saveload::{MarkedBuilder, SimpleMarker};
use std::collections::HashMap;
use crate::components::*;
use crate::map::MAP_WIDTH;
use crate::random_table::RandomTable;
use crate::{Map, Rect, TileType};
/// Spawns the player and returns their entity object /// Spawns the player and returns their entity object
pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity { pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {

View File

@ -1,9 +1,12 @@
use specs::prelude::*;
use crate::components::{ use crate::components::{
EntityMoved, EntryTrigger, Hidden, InflictsDamage, Name, Position, SingleActivation, EntityMoved, EntryTrigger, Hidden, InflictsDamage, Name, Position, SingleActivation,
SufferDamage, SufferDamage,
}; };
use crate::{game_log::GameLog, particle_system::ParticleBuilder, Map}; use crate::game_log::GameLog;
use specs::prelude::*; use crate::particle_system::ParticleBuilder;
use crate::Map;
pub struct TriggerSystem {} pub struct TriggerSystem {}

View File

@ -1,9 +1,10 @@
use crate::{
components::Hidden, components::Name, game_log::GameLog, Map, Player, Position, Viewshed,
};
use rltk::{field_of_view, Point}; use rltk::{field_of_view, Point};
use specs::prelude::*; use specs::prelude::*;
use crate::components::{Hidden, Name};
use crate::game_log::GameLog;
use crate::{Map, Player, Position, Viewshed};
pub struct VisibilitySystem {} pub struct VisibilitySystem {}
impl<'a> System<'a> for VisibilitySystem { impl<'a> System<'a> for VisibilitySystem {