Add rainbow brush.

This commit is contained in:
UnknownShadow200 2016-03-08 18:09:58 +11:00
parent 91dcb6e8fb
commit ab5f5f3824
6 changed files with 68 additions and 35 deletions

View File

@ -33,6 +33,7 @@ namespace MCGalaxy.Drawing.Brushes {
{ "normal", SolidBrush.Process },
{ "paste", PasteBrush.Process },
{ "checkered", CheckeredBrush.Process },
{ "rainbow", RainbowBrush.Process },
};
}
@ -46,20 +47,6 @@ namespace MCGalaxy.Drawing.Brushes {
}
}
public sealed class RainbowBrush : Brush {
byte curBlock = Block.red;
public override byte NextBlock(DrawOp op) {
byte block = curBlock;
curBlock++;
if (curBlock > Block.darkpink)
curBlock = Block.red;
return block;
}
public override byte NextExtBlock(DrawOp op) { return 0; }
}
public sealed class RandomBrush : Brush {
readonly Random rnd = new Random();
readonly byte type, extType;
@ -75,22 +62,4 @@ namespace MCGalaxy.Drawing.Brushes {
public override byte NextExtBlock(DrawOp op) { return extType; }
}
public sealed class RandomRainbowBrush : Brush {
readonly Random rnd;
public RandomRainbowBrush() {
rnd = new Random();
}
public RandomRainbowBrush(int seed) {
rnd = new Random(seed);
}
public override byte NextBlock(DrawOp op) {
return (byte)rnd.Next(Block.red, Block.darkgrey);
}
public override byte NextExtBlock(DrawOp op) { return 0; }
}
}

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Drawing.Brushes {
this.type2 = type2; this.extType2 = extType2;
}
public static CheckeredBrush Process(BrushArgs args) {
public static Brush Process(BrushArgs args) {
if (args.Message == "")
return new CheckeredBrush(args.Type, args.ExtType, 0, 0);
string[] parts = args.Message.Split(' ');

View File

@ -29,7 +29,7 @@ namespace MCGalaxy.Drawing.Brushes {
this.state = state;
}
public static PasteBrush Process(BrushArgs args) {
public static Brush Process(BrushArgs args) {
if (args.Player.CopyBuffer == null) {
args.Player.SendMessage("You haven't copied anything yet.");
return null;

View File

@ -0,0 +1,63 @@
/*
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 RainbowBrush : Brush {
public override byte NextBlock(DrawOp op) {
int dx = op.Coords.X - op.Min.X;
int dy = op.Coords.Y - op.Min.Y;
int dz = op.Coords.Z - op.Min.Z;
int offset = (dx + dy + dz) % 13;
if (offset < 0) offset += 13;
return (byte)(Block.red + offset);
}
public override byte NextExtBlock(DrawOp op) { return 0; }
public static Brush Process(BrushArgs args) {
if (args.Message == "random")
return new RandomRainbowBrush();
return new RainbowBrush(); // TODO: seed
}
}
public sealed class RandomRainbowBrush : Brush {
readonly Random rnd;
public RandomRainbowBrush() {
rnd = new Random();
}
public RandomRainbowBrush(int seed) {
rnd = new Random(seed);
}
public override byte NextBlock(DrawOp op) {
return (byte)rnd.Next(Block.red, Block.darkgrey);
}
public override byte NextExtBlock(DrawOp op) { return 0; }
}
}

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Drawing.Brushes {
this.extType = extType;
}
public static SolidBrush Process(BrushArgs args) {
public static Brush Process(BrushArgs args) {
if (args.Message == "")
return new SolidBrush(args.Type, args.ExtType);
byte extType;

View File

@ -395,6 +395,7 @@
<Compile Include="Drawing\Brushes\Brush.cs" />
<Compile Include="Drawing\Brushes\CheckeredBrush.cs" />
<Compile Include="Drawing\Brushes\PasteBrush.cs" />
<Compile Include="Drawing\Brushes\RainbowBrush.cs" />
<Compile Include="Drawing\Brushes\SolidBrush.cs" />
<Compile Include="Drawing\CopyState.cs" />
<Compile Include="Drawing\DrawOps\CuboidDrawOp.cs" />