From 4a8317c232a2627317b612d49cfa246bc51c41db Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Sun, 22 Dec 2019 15:48:02 -0800 Subject: [PATCH] Remove map lint module --- src/cli/main.rs | 33 ------------- src/tools/lib.rs | 1 - src/tools/lint.rs | 119 ---------------------------------------------- 3 files changed, 153 deletions(-) delete mode 100644 src/tools/lint.rs diff --git a/src/cli/main.rs b/src/cli/main.rs index bd190165..1ba69acd 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -168,20 +168,6 @@ enum Command { /// The list of maps to process. files: Vec, }, - /// Lint and automatically fix the specified maps. - #[structopt(name = "lint-maps")] - LintMaps { - /// Only report and do not save out changes. - #[structopt(short="n", long="dry-run")] - dry_run: bool, - - /// Reformat the specified maps even if nothing was changed. - #[structopt(long="reformat")] - reformat: bool, - - /// The list of maps to process. - files: Vec, - }, /// List the differing coordinates between two maps. #[structopt(name="diff-maps")] DiffMaps { @@ -387,25 +373,6 @@ fn run(opt: &Opt, command: &Command, context: &mut Context) { } }, // -------------------------------------------------------------------- - Command::LintMaps { - dry_run, reformat, ref files, - } => { - context.objtree(opt); - - for path in files.iter() { - let path: &std::path::Path = path.as_ref(); - println!("{}", path.display()); - let mut map = dmm::Map::from_file(path).unwrap(); - - let linted = lint::check(&context.objtree, &mut map); - print!("{}", linted); - if !dry_run && (linted.any() || reformat) { - println!(" saving {}", path.display()); - map.to_file(path).unwrap(); - } - } - }, - // -------------------------------------------------------------------- Command::DiffMaps { ref left, ref right, } => { diff --git a/src/tools/lib.rs b/src/tools/lib.rs index 87abc8fe..f265eae2 100644 --- a/src/tools/lib.rs +++ b/src/tools/lib.rs @@ -18,7 +18,6 @@ pub mod dmm; mod icon_cache; pub mod minimap; pub mod render_passes; -pub mod lint; pub mod dmi; pub use icon_cache::IconCache; diff --git a/src/tools/lint.rs b/src/tools/lint.rs deleted file mode 100644 index 7fe3b11d..00000000 --- a/src/tools/lint.rs +++ /dev/null @@ -1,119 +0,0 @@ -//! Simplistic linting tools for maps, to automatically fix certain issues. -use std::fmt; - -use dm::objtree::*; -use dm::constants::Constant; -use crate::dmm::Map; - -macro_rules! lints { - ($($ident:ident = $desc:expr;)*) => { - #[derive(Default)] - pub struct Lints { - $($ident: u32,)* - } - - impl Lints { - pub fn any(&self) -> bool { - $(self.$ident > 0)||* - } - } - - impl fmt::Display for Lints { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - $(if self.$ident > 0 { writeln!(f, concat!(" ", $desc, ": {}"), self.$ident)?; })* - Ok(()) - } - } - } -} - -lints! { - cable_pixels = "cable pixel offsets"; - cable_directions = "cable directions"; - tag_empty = "empty tags"; - tag_icon = "icon tags"; - stacked_turfs = "stacked turfs"; -} - -#[allow(unused_variables)] -pub fn check( - objtree: &ObjectTree, - map: &mut Map, -) -> Lints { - let mut lints = Lints::default(); - let key_length = map.key_length(); - - for (z, level) in map.iter_levels() { - for (coord, key) in level.iter_top_down() { - let prefabs = &map.dictionary[&key]; - let mut found_turf = 0; - for fab in prefabs { - if subpath(&fab.path, "/turf/") { - found_turf += 1; - } - } - if found_turf != 1 { - println!(" at {}: found {} turfs", coord.z(z), found_turf); - } - } - } - - for (&key, prefabs) in map.dictionary.iter_mut() { - let mut found_turf = false; - retain_mut(prefabs, |fab| { - if subpath(&fab.path, "/turf/") { - if found_turf { - lints.stacked_turfs += 1; - return false; - } - found_turf = true; - } - - let tag = fab.vars.get("tag").cloned(); - if let Some(Constant::String(tag)) = tag { - if tag.is_empty() { - lints.tag_empty += 1; - fab.vars.remove("tag"); - } else if tag.starts_with("icon-") { - lints.tag_icon += 1; - fab.vars.remove("tag"); - } - } - - if subpath(&fab.path, "/obj/structure/cable/") { - if fab.vars.remove("pixel_y").is_some() | fab.vars.remove("pixel_x").is_some() { - lints.cable_pixels += 1; - } - if fab.vars.remove("d1").is_some() | fab.vars.remove("d2").is_some() { - lints.cable_directions += 1; - } - } - - true - }); - } - - lints -} - -pub fn retain_mut(v: &mut Vec, mut f: F) -where - F: FnMut(&mut T) -> bool, -{ - let len = v.len(); - let mut del = 0; - { - let v = &mut **v; - - for i in 0..len { - if !f(&mut v[i]) { - del += 1; - } else if del > 0 { - v.swap(i - del, i); - } - } - } - if del > 0 { - v.truncate(len - del); - } -}