Remove map lint module

This commit is contained in:
Tad Hardesty 2019-12-22 15:48:02 -08:00
parent bf793f8aad
commit 4a8317c232
3 changed files with 0 additions and 153 deletions

View file

@ -168,20 +168,6 @@ enum Command {
/// The list of maps to process.
files: Vec<String>,
},
/// 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<String>,
},
/// 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,
} => {

View file

@ -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;

View file

@ -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<T, F>(v: &mut Vec<T>, 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);
}
}