From 37cd475398d42ba53a545f7069708450ece68293 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 9 Mar 2016 08:09:39 +1100 Subject: [PATCH] Add striped brush, also show brush name in draw operation output to the player. --- Drawing/Brushes/Brush.cs | 6 ++++ Drawing/Brushes/CheckeredBrush.cs | 2 ++ Drawing/Brushes/PasteBrush.cs | 2 ++ Drawing/Brushes/RainbowBrush.cs | 6 ++++ Drawing/Brushes/SolidBrush.cs | 2 ++ Drawing/Brushes/StripedBrush.cs | 59 +++++++++++++++++++++++++++++++ Drawing/DrawOps/DrawOp.cs | 3 +- MCGalaxy_.csproj | 1 + 8 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 Drawing/Brushes/StripedBrush.cs diff --git a/Drawing/Brushes/Brush.cs b/Drawing/Brushes/Brush.cs index 161ccf81c..0f5205a9c 100644 --- a/Drawing/Brushes/Brush.cs +++ b/Drawing/Brushes/Brush.cs @@ -23,6 +23,9 @@ using MCGalaxy.Drawing.Ops; namespace MCGalaxy.Drawing.Brushes { public abstract class Brush { + + /// Human friendly name of this brush. + public abstract string Name { get; } public abstract byte NextBlock(DrawOp op); @@ -35,6 +38,7 @@ namespace MCGalaxy.Drawing.Brushes { { "checkered", CheckeredBrush.Process }, { "rainbow", RainbowBrush.Process }, { "bwrainbow", BWRainbowBrush.Process }, + { "striped", StripedBrush.Process }, }; } @@ -57,6 +61,8 @@ namespace MCGalaxy.Drawing.Brushes { this.extType = extType; } + public override string Name { get { return "Random"; } } + public override byte NextBlock(DrawOp op) { return (byte)rnd.Next(1, 11) <= 5 ? type : Block.Zero; } diff --git a/Drawing/Brushes/CheckeredBrush.cs b/Drawing/Brushes/CheckeredBrush.cs index 0cf130395..91763b6cb 100644 --- a/Drawing/Brushes/CheckeredBrush.cs +++ b/Drawing/Brushes/CheckeredBrush.cs @@ -30,6 +30,8 @@ namespace MCGalaxy.Drawing.Brushes { this.type2 = type2; this.extType2 = extType2; } + public override string Name { get { return "Checkered"; } } + public static Brush Process(BrushArgs args) { if (args.Message == "") return new CheckeredBrush(args.Type, args.ExtType, 0, 0); diff --git a/Drawing/Brushes/PasteBrush.cs b/Drawing/Brushes/PasteBrush.cs index 1f7577593..ad4b65f31 100644 --- a/Drawing/Brushes/PasteBrush.cs +++ b/Drawing/Brushes/PasteBrush.cs @@ -29,6 +29,8 @@ namespace MCGalaxy.Drawing.Brushes { this.state = state; } + public override string Name { get { return "Paste"; } } + public static Brush Process(BrushArgs args) { if (args.Player.CopyBuffer == null) { args.Player.SendMessage("You haven't copied anything yet."); diff --git a/Drawing/Brushes/RainbowBrush.cs b/Drawing/Brushes/RainbowBrush.cs index 65e4e1374..2254078a0 100644 --- a/Drawing/Brushes/RainbowBrush.cs +++ b/Drawing/Brushes/RainbowBrush.cs @@ -24,6 +24,8 @@ namespace MCGalaxy.Drawing.Brushes { public sealed class RainbowBrush : Brush { + public override string Name { get { return "Rainbow"; } } + public override byte NextBlock(DrawOp op) { int offset = (op.Coords.X + op.Coords.Y + op.Coords.Z) % 13; if (offset < 0) offset += 13; @@ -49,6 +51,8 @@ namespace MCGalaxy.Drawing.Brushes { public sealed class BWRainbowBrush : Brush { + public override string Name { get { return "BWRainbow"; } } + static byte[] blocks = { Block.iron, Block.white, Block.lightgrey, Block.darkgrey, Block.obsidian, Block.darkgrey, Block.lightgrey, Block.white }; public override byte NextBlock(DrawOp op) { @@ -67,6 +71,8 @@ namespace MCGalaxy.Drawing.Brushes { public sealed class RandomRainbowBrush : Brush { readonly Random rnd; + public override string Name { get { return "RandomRainbow"; } } + public RandomRainbowBrush() { rnd = new Random(); } diff --git a/Drawing/Brushes/SolidBrush.cs b/Drawing/Brushes/SolidBrush.cs index 69e3d0d73..85a1eaa23 100644 --- a/Drawing/Brushes/SolidBrush.cs +++ b/Drawing/Brushes/SolidBrush.cs @@ -30,6 +30,8 @@ namespace MCGalaxy.Drawing.Brushes { this.extType = extType; } + public override string Name { get { return "Normal"; } } + public static Brush Process(BrushArgs args) { if (args.Message == "") return new SolidBrush(args.Type, args.ExtType); diff --git a/Drawing/Brushes/StripedBrush.cs b/Drawing/Brushes/StripedBrush.cs new file mode 100644 index 000000000..8b55b7ba7 --- /dev/null +++ b/Drawing/Brushes/StripedBrush.cs @@ -0,0 +1,59 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Collections.Generic; +using MCGalaxy.Commands; +using MCGalaxy.Drawing.Ops; + +namespace MCGalaxy.Drawing.Brushes { + + public sealed class StripedBrush : Brush { + readonly byte type1, extType1, type2, extType2; + + public StripedBrush(byte type1, byte extType1, byte type2, byte extType2) { + this.type1 = type1; this.extType1 = extType1; + this.type2 = type2; this.extType2 = extType2; + } + + public override string Name { get { return "Striped"; } } + + public static Brush Process(BrushArgs args) { + if (args.Message == "") + return new StripedBrush(args.Type, args.ExtType, 0, 0); + string[] parts = args.Message.Split(' '); + byte extType1; + byte type1 = DrawCmd.GetBlock(args.Player, parts[0], out extType1); + if (type1 == Block.Zero) return null; + if (parts.Length == 1) + return new StripedBrush(type1, extType1, 0, 0); + + byte extType2; + byte type2 = DrawCmd.GetBlock(args.Player, parts[1], out extType2); + if (type2 == Block.Zero) return null; + return new StripedBrush(type1, extType1, type2, extType2); + } + + public override byte NextBlock(DrawOp op) { + return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 3) <= 1 ? type1 : type2; + } + + public override byte NextExtBlock(DrawOp op) { + return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 3) <= 1 ? extType1 : extType2; + } + } +} diff --git a/Drawing/DrawOps/DrawOp.cs b/Drawing/DrawOps/DrawOp.cs index bcc964125..8e773a598 100644 --- a/Drawing/DrawOps/DrawOp.cs +++ b/Drawing/DrawOps/DrawOp.cs @@ -133,7 +133,8 @@ namespace MCGalaxy.Drawing.Ops { if (!op.CanDraw(x1, y1, z1, x2, y2, z2, p, out affected)) return false; - Player.SendMessage(p, op.Name + ": affecting up to an estimated " + affected + " blocks"); + const string format = "{0}({1}): affecting up to {2} blocks"; + Player.SendMessage(p, String.Format(format, op.Name, brush.Name, affected)); bool needReveal = op.DetermineDrawOpMethod(p.level, affected); op.Perform(x1, y1, z1, x2, y2, z2, p, p.level, brush); diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index 0e84c5e2b..7aaa292fe 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -397,6 +397,7 @@ +