mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-26 06:43:25 -04:00
Add rainbow brush.
This commit is contained in:
parent
91dcb6e8fb
commit
ab5f5f3824
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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(' ');
|
||||
|
@ -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;
|
||||
|
63
Drawing/Brushes/RainbowBrush.cs
Normal file
63
Drawing/Brushes/RainbowBrush.cs
Normal 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; }
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user