From 8a3e973a5895c68a7cbfa15e9e563a0a2bcd9fd7 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sat, 4 Jun 2011 06:02:47 +0000 Subject: [PATCH] Oops --- NBToolkit/BlockFilter.cs | 157 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 NBToolkit/BlockFilter.cs diff --git a/NBToolkit/BlockFilter.cs b/NBToolkit/BlockFilter.cs new file mode 100644 index 0000000..8db6423 --- /dev/null +++ b/NBToolkit/BlockFilter.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NDesk.Options; + +namespace NBToolkit +{ + public interface IBlockFilterable + { + IBlockFilter GetBlockFilter (); + } + + public interface IBlockFilter + { + int? XAboveEq { get; } + int? XBelowEq { get; } + int? YAboveEq { get; } + int? YBelowEq { get; } + int? ZAboveEq { get; } + int? ZBelowEq { get; } + + bool InvertXYZ { get; } + + IEnumerable IncludedBlocks { get; } // MatchAny + IEnumerable ExcludedBlocks { get; } // MatchAny + + int IncludedBlockCount { get; } + int ExcludedBlockCount { get; } + + double? ProbMatch { get; } + } + + public class BlockFilter : IOptions, IBlockFilter + { + protected int? _xAboveEq = null; + protected int? _xBelowEq = null; + protected int? _yAboveEq = null; + protected int? _yBelowEq = null; + protected int? _zAboveEq = null; + protected int? _zBelowEq = null; + + protected bool _invertXYZ = false; + + protected List _includedBlocks = new List(); + protected List _excludedBlocks = new List(); + + protected double? _prob = null; + + protected OptionSet _options; + + public int? XAboveEq + { + get { return _xAboveEq; } + } + + public int? XBelowEq + { + get { return _xBelowEq; } + } + + public int? YAboveEq + { + get { return _yAboveEq; } + } + + public int? YBelowEq + { + get { return _yBelowEq; } + } + + public int? ZAboveEq + { + get { return _zAboveEq; } + } + + public int? ZBelowEq + { + get { return _zBelowEq; } + } + + public bool InvertXYZ + { + get { return _invertXYZ; } + } + + public IEnumerable IncludedBlocks + { + get { return _includedBlocks; } + } + + public IEnumerable ExcludedBlocks + { + get { return _excludedBlocks; } + } + + public int IncludedBlockCount + { + get { return _includedBlocks.Count; } + } + + public int ExcludedBlockCount + { + get { return _excludedBlocks.Count; } + } + + public double? ProbMatch + { + get { return _prob; } + } + + public BlockFilter () + { + _options = new OptionSet() { + { "bxr|BlockXRange=", "Include blocks with X-coord between {0:V1} and {1:V2}, inclusive. V1 or V2 may be left blank.", + (v1, v2) => { + try { _xAboveEq = Convert.ToInt32(v1); } catch (FormatException) { } + try { _xBelowEq = Convert.ToInt32(v2); } catch (FormatException) { } + } }, + { "byr|BlockYRange=", "Include blocks with Y-coord between {0:V1} and {1:V2}, inclusive. V1 or V2 may be left blank.", + (v1, v2) => { + try { _yAboveEq = Convert.ToInt32(v1); } catch (FormatException) { } + try { _yBelowEq = Convert.ToInt32(v2); } catch (FormatException) { } + } }, + { "bzr|BlockZRange=", "Include blocks with Z-chunk coord between {0:V1} and {1:V2}, inclusive. V1 or V2 may be left blank.", + (v1, v2) => { + try { _zAboveEq = Convert.ToInt32(v1); } catch (FormatException) { } + try { _zBelowEq = Convert.ToInt32(v2); } catch (FormatException) { } + } }, + { "brv|BlockInvertXYZ", "Inverts the block selection created by --cxr, --cyr and --czr when all three options are used.", + v => _invertXYZ = true }, + { "bi|BlockInclude=", "Match blocks of type {ID}. This option is repeatable.", + v => _includedBlocks.Add(Convert.ToInt32(v) % 256) }, + { "bx|BlockExclude=", "Match all blocks except blocks of type {ID}. This option is repeatable.", + v => _excludedBlocks.Add(Convert.ToInt32(v) % 256) }, + { "bp|BlockProbability=", "Selects a matching block with probability {VAL} (0.0-1.0)", + v => _prob = Convert.ToDouble(v) }, + }; + } + + public BlockFilter (string[] args) + : this() + { + Parse(args); + } + + public void Parse (string[] args) + { + _options.Parse(args); + } + + public void PrintUsage () + { + Console.WriteLine("Block Filtering Options:"); + _options.WriteOptionDescriptions(Console.Out); + } + } +}