generated from GarandPLG/rust-flake-template
Add rustfmt configuration and reformat code
- Document new Rust formatting standards in AGENTS, CODE_MAP, and PROGRESS. - Add rustfmt.toml with style 2024, 2‑space indents, 100‑char width, LF endings. - Apply consistent 2‑space indentation and ordering across source files. - Minor clean‑up of imports and whitespace to match the new style.
This commit is contained in:
1 parent
9e09aaf75e
commit
c4313b4117
60 files changed
+3632
-3610
No files matched your search
+93
-93
@@ -1,13 +1,13 @@
|
||||
use crate::{
|
||||
app::{
|
||||
states::{
|
||||
PerkDecks,
|
||||
skirmish_states::{GameMode, ZoomLevel},
|
||||
},
|
||||
threads::Soundtrack,
|
||||
view::View,
|
||||
app::{
|
||||
states::{
|
||||
PerkDecks,
|
||||
skirmish_states::{GameMode, ZoomLevel},
|
||||
},
|
||||
logs::init_logger,
|
||||
threads::Soundtrack,
|
||||
view::View,
|
||||
},
|
||||
logs::init_logger,
|
||||
};
|
||||
use clap::{Error, Parser, error::ErrorKind, value_parser};
|
||||
use std::num::ParseFloatError;
|
||||
@@ -21,8 +21,8 @@ use std::num::ParseFloatError;
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
#[command(version, about = "War in Tunnels", long_about = "War in Tunnels")]
|
||||
pub struct Cli {
|
||||
/// The initial view/window to display.
|
||||
#[arg(
|
||||
/// The initial view/window to display.
|
||||
#[arg(
|
||||
long,
|
||||
short,
|
||||
help = "Default window",
|
||||
@@ -30,20 +30,20 @@ pub struct Cli {
|
||||
default_value_t = View::MainMenu,
|
||||
value_enum
|
||||
)]
|
||||
pub view: View,
|
||||
pub view: View,
|
||||
|
||||
/// Player name shown in the UI.
|
||||
#[arg(
|
||||
long,
|
||||
short,
|
||||
help = "Username",
|
||||
value_name = "String",
|
||||
default_value = "Player"
|
||||
)]
|
||||
pub username: String,
|
||||
/// Player name shown in the UI.
|
||||
#[arg(
|
||||
long,
|
||||
short,
|
||||
help = "Username",
|
||||
value_name = "String",
|
||||
default_value = "Player"
|
||||
)]
|
||||
pub username: String,
|
||||
|
||||
/// Game mode selection.
|
||||
#[arg(
|
||||
/// Game mode selection.
|
||||
#[arg(
|
||||
long,
|
||||
short,
|
||||
help = "Game mode",
|
||||
@@ -51,10 +51,10 @@ pub struct Cli {
|
||||
default_value_t = GameMode::LastManStanding,
|
||||
value_enum
|
||||
)]
|
||||
pub game_mode: GameMode,
|
||||
pub game_mode: GameMode,
|
||||
|
||||
/// Width of the generated map (36–100 tiles).
|
||||
#[arg(
|
||||
/// Width of the generated map (36–100 tiles).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'W',
|
||||
help = "Map width",
|
||||
@@ -62,10 +62,10 @@ pub struct Cli {
|
||||
default_value = "42",
|
||||
value_parser = value_parser!(u8).range(36..=108)
|
||||
)]
|
||||
pub map_width: u8,
|
||||
pub map_width: u8,
|
||||
|
||||
/// Height of the generated map (11–50 tiles).
|
||||
#[arg(
|
||||
/// Height of the generated map (11–50 tiles).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'H',
|
||||
help = "Map height",
|
||||
@@ -73,10 +73,10 @@ pub struct Cli {
|
||||
default_value = "11",
|
||||
value_parser = value_parser!(u8).range(11..=39)
|
||||
)]
|
||||
pub map_height: u8,
|
||||
pub map_height: u8,
|
||||
|
||||
/// Zoom level used for the UI.
|
||||
#[arg(
|
||||
/// Zoom level used for the UI.
|
||||
#[arg(
|
||||
long,
|
||||
short,
|
||||
help = "Zoom level",
|
||||
@@ -84,10 +84,10 @@ pub struct Cli {
|
||||
default_value_t = ZoomLevel::Default,
|
||||
value_enum
|
||||
)]
|
||||
pub zoom_level: ZoomLevel,
|
||||
pub zoom_level: ZoomLevel,
|
||||
|
||||
/// Which perk deck to use.
|
||||
#[arg(
|
||||
/// Which perk deck to use.
|
||||
#[arg(
|
||||
long,
|
||||
short,
|
||||
help = "Perk Deck",
|
||||
@@ -95,10 +95,10 @@ pub struct Cli {
|
||||
default_value_t = PerkDecks::Silesian,
|
||||
value_enum
|
||||
)]
|
||||
pub perk_deck: PerkDecks,
|
||||
pub perk_deck: PerkDecks,
|
||||
|
||||
/// Starting amount of wood (1–150).
|
||||
#[arg(
|
||||
/// Starting amount of wood (1–150).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'w',
|
||||
help = "Starting wood",
|
||||
@@ -106,10 +106,10 @@ pub struct Cli {
|
||||
default_value = "50",
|
||||
value_parser = value_parser!(u16).range(1..=150)
|
||||
)]
|
||||
pub starting_wood: u16,
|
||||
pub starting_wood: u16,
|
||||
|
||||
/// Starting amount of iron (1–150).
|
||||
#[arg(
|
||||
/// Starting amount of iron (1–150).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'i',
|
||||
help = "Starting iron",
|
||||
@@ -117,10 +117,10 @@ pub struct Cli {
|
||||
default_value = "25",
|
||||
value_parser = value_parser!(u16).range(1..=150)
|
||||
)]
|
||||
pub starting_iron: u16,
|
||||
pub starting_iron: u16,
|
||||
|
||||
/// Maximum amount of units (49–149).
|
||||
#[arg(
|
||||
/// Maximum amount of units (49–149).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'L',
|
||||
help = "Supply limit",
|
||||
@@ -128,10 +128,10 @@ pub struct Cli {
|
||||
default_value = "99",
|
||||
value_parser = value_parser!(u8).range(49..=149)
|
||||
)]
|
||||
pub supply_limit: u8,
|
||||
pub supply_limit: u8,
|
||||
|
||||
/// Modifier applied to experience points (0.5–2.0).
|
||||
#[arg(
|
||||
/// Modifier applied to experience points (0.5–2.0).
|
||||
#[arg(
|
||||
long,
|
||||
short,
|
||||
help = "XP modifier",
|
||||
@@ -139,10 +139,10 @@ pub struct Cli {
|
||||
default_value = "1.0",
|
||||
value_parser = parse_xp
|
||||
)]
|
||||
pub xp_modifier: f32,
|
||||
pub xp_modifier: f32,
|
||||
|
||||
/// Upper bound for skill points that can be earned (90–690).
|
||||
#[arg(
|
||||
/// Upper bound for skill points that can be earned (90–690).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'P',
|
||||
help = "Skill points limit",
|
||||
@@ -150,10 +150,10 @@ pub struct Cli {
|
||||
default_value = "120",
|
||||
value_parser = value_parser!(u16).range(90..=690)
|
||||
)]
|
||||
pub skill_points_limit: u16,
|
||||
pub skill_points_limit: u16,
|
||||
|
||||
/// Which soundtrack to play (default: default)
|
||||
#[arg(
|
||||
/// Which soundtrack to play (default: default)
|
||||
#[arg(
|
||||
long,
|
||||
short = 'S',
|
||||
help = "Soundtrack",
|
||||
@@ -161,34 +161,34 @@ pub struct Cli {
|
||||
default_value_t = Soundtrack::Default,
|
||||
value_enum
|
||||
)]
|
||||
pub soundtrack: Soundtrack,
|
||||
pub soundtrack: Soundtrack,
|
||||
|
||||
/// Disable soundtrack (default: disabled).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'D',
|
||||
help = "Disable soundtrack (default: disable)",
|
||||
default_value_t = false
|
||||
)]
|
||||
pub disable_audio: bool,
|
||||
/// Disable soundtrack (default: disabled).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'D',
|
||||
help = "Disable soundtrack (default: disable)",
|
||||
default_value_t = false
|
||||
)]
|
||||
pub disable_audio: bool,
|
||||
|
||||
/// Mute soundtrack (default: disabled).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'm',
|
||||
help = "Mute soundtrack (default: disabled)",
|
||||
default_value_t = false
|
||||
)]
|
||||
pub mute: bool,
|
||||
/// Mute soundtrack (default: disabled).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'm',
|
||||
help = "Mute soundtrack (default: disabled)",
|
||||
default_value_t = false
|
||||
)]
|
||||
pub mute: bool,
|
||||
|
||||
/// Enable logging to a file (default: disabled).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'l',
|
||||
help = "Enable logging to file (default: disabled)",
|
||||
default_value_t = false
|
||||
)]
|
||||
pub log: bool,
|
||||
/// Enable logging to a file (default: disabled).
|
||||
#[arg(
|
||||
long,
|
||||
short = 'l',
|
||||
help = "Enable logging to file (default: disabled)",
|
||||
default_value_t = false
|
||||
)]
|
||||
pub log: bool,
|
||||
}
|
||||
|
||||
/// Parses the command line arguments and returns a fully populated `Cli`
|
||||
@@ -196,13 +196,13 @@ pub struct Cli {
|
||||
/// handles argument validation and displays helpful error messages if
|
||||
/// the user supplies invalid input.
|
||||
pub fn get_args() -> Cli {
|
||||
let args: Cli = Cli::parse();
|
||||
let args: Cli = Cli::parse();
|
||||
|
||||
if args.log {
|
||||
init_logger();
|
||||
}
|
||||
if args.log {
|
||||
init_logger();
|
||||
}
|
||||
|
||||
args
|
||||
args
|
||||
}
|
||||
|
||||
/// Parses a string into a floating‑point XP modifier and validates that it
|
||||
@@ -217,15 +217,15 @@ pub fn get_args() -> Cli {
|
||||
/// * Returns an error if the string cannot be parsed as `f32`.
|
||||
/// * Returns an error if the parsed value is outside the allowed range.
|
||||
fn parse_xp(s: &str) -> Result<f32, Error> {
|
||||
let v: f32 = s
|
||||
.parse()
|
||||
.map_err(|e: ParseFloatError| Error::raw(ErrorKind::InvalidValue, e.to_string()))?;
|
||||
if (0.5..=2.0).contains(&v) {
|
||||
Ok(v)
|
||||
} else {
|
||||
Err(Error::raw(
|
||||
ErrorKind::InvalidValue,
|
||||
format!("Value {} is out of range 0.5..=2.0", v),
|
||||
))
|
||||
}
|
||||
let v: f32 = s
|
||||
.parse()
|
||||
.map_err(|e: ParseFloatError| Error::raw(ErrorKind::InvalidValue, e.to_string()))?;
|
||||
if (0.5..=2.0).contains(&v) {
|
||||
Ok(v)
|
||||
} else {
|
||||
Err(Error::raw(
|
||||
ErrorKind::InvalidValue,
|
||||
format!("Value {} is out of range 0.5..=2.0", v),
|
||||
))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user