The /write command is now a drawop. (Does not use player brush though)

This commit is contained in:
UnknownShadow200 2016-03-14 23:12:35 +11:00
parent e15b8f1d94
commit 82a08e6b7e
3 changed files with 182 additions and 170 deletions

View File

@ -17,6 +17,8 @@
*/
using System;
using MCGalaxy.Drawing;
using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Drawing.Ops;
namespace MCGalaxy.Commands {
@ -53,35 +55,27 @@ namespace MCGalaxy.Commands {
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
}
public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject;
bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
}
public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
type = type < 128 ? p.bindings[type] : type;
RevertAndClearState(p, x, y, z);
CatchPos cpos = (CatchPos)p.blockchangeObject;
Level lvl = p.level;
if (x == cpos.x && z == cpos.z) { Player.SendMessage(p, "No direction was selected"); return; }
int dir = 0;
if (Math.Abs(cpos.x - x) > Math.Abs(cpos.z - z))
dir = x > cpos.x ? 0 : 1;
else
dir = z > cpos.z ? 2 : 3;
WriteDrawOp op = new WriteDrawOp();
op.Text = cpos.givenMessage;
op.Scale = cpos.scale; op.Spacing = cpos.spacing;
Brush brush = new SolidBrush(type, extType);
if (!DrawOp.DoDrawOp(op, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))
return;
int count = BlockWriter.CountBlocks(cpos.givenMessage, cpos.scale);
if (count > p.group.maxBlocks) {
Player.SendMessage(p, "You cannot affect more than " + p.group.maxBlocks + " blocks."); return;
}
foreach (char c in cpos.givenMessage)
BlockWriter.DrawLetter(lvl, p, c, ref cpos.x, cpos.y, ref cpos.z,
type, extType, dir, cpos.scale, cpos.spacing);
if (p.staticCommands)
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
}

View File

@ -15,34 +15,51 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using MCGalaxy.Drawing.Brushes;
namespace MCGalaxy.Drawing {
namespace MCGalaxy.Drawing.Ops {
internal static class BlockWriter {
public class WriteDrawOp : DrawOp {
public static int CountBlocks(string s, byte scale) {
public string Text;
public byte Scale, Spacing;
public override string Name { get { return "Write"; } }
public override bool MinMaxCoords { get { return false; } }
public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) {
int blocks = 0;
foreach (char c in s) {
foreach (char c in Text) {
if ((int)c >= 256 || letters[(int)c] == null) {
blocks += (4 * scale) * (4 * scale);
blocks += (4 * Scale) * (4 * Scale);
} else {
byte[] flags = letters[(int)c];
for (int i = 0; i < flags.Length; i++)
blocks += scale * scale * HighestBit(flags[i]);
blocks += Scale * Scale * HighestBit(flags[i]);
}
}
return blocks;
}
public static void DrawLetter(Level l, Player p, char c, ref ushort x, ushort y, ref ushort z,
byte type, byte extType, int dir, byte scale, byte spacing) {
int dirX = dir == 0 ? 1 : dir == 1 ? -1 : 0;
int dirZ = dir == 2 ? 1 : dir == 3 ? -1 : 0;
int dirX, dirZ;
public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
if (Math.Abs(x2 - x1) > Math.Abs(z2 - z1))
dirX = x2 > x1? 1 : -1;
else
dirZ = z2 > z1 ? 1 : -1;
foreach (char c in Text)
DrawLetter(p, lvl, c, ref x1, y1, ref z1, brush);
}
void DrawLetter(Player p, Level lvl, char c, ref ushort x, ushort y, ref ushort z, Brush brush) {
if ((int)c >= 256 || letters[(int)c] == null) {
Player.SendMessage(p, "\"" + c + "\" is not currently supported, replacing with space.");
x = (ushort)(x + dirX * 4 * scale);
z = (ushort)(z + dirZ * 4 * scale);
x = (ushort)(x + dirX * 4 * Scale);
z = (ushort)(z + dirZ * 4 * Scale);
} else {
byte[] flags = letters[(int)c];
for (int i = 0; i < flags.Length; i++) {
@ -50,18 +67,19 @@ namespace MCGalaxy.Drawing {
for (int j = 0; j < 8; j++) {
if ((yUsed & (1 << j)) == 0) continue;
for (int ver = 0; ver < scale; ver++)
for (int hor = 0; hor < scale; hor++) {
int xx = x + dirX * hor, yy = y + j * scale + ver, zz = z + dirZ * hor;
l.UpdateBlock(p, (ushort)xx, (ushort)yy, (ushort)zz, type, extType);
for (int ver = 0; ver < Scale; ver++)
for (int hor = 0; hor < Scale; hor++)
{
int xx = x + dirX * hor, yy = y + j * Scale + ver, zz = z + dirZ * hor;
PlaceBlock(p, lvl, (ushort)xx, (ushort)yy, (ushort)zz, brush);
}
}
x = (ushort)(x + dirX * scale);
z = (ushort)(z + dirZ * scale);
x = (ushort)(x + dirX * Scale);
z = (ushort)(z + dirZ * Scale);
}
}
x = (ushort)(x + dirX * spacing);
z = (ushort)(z + dirZ * spacing);
x = (ushort)(x + dirX * Spacing);
z = (ushort)(z + dirZ * Spacing);
}
static int HighestBit(int value) {
@ -73,7 +91,7 @@ namespace MCGalaxy.Drawing {
}
static byte[][] letters;
static BlockWriter() {
static WriteDrawOp() {
letters = new byte[256][];
// each set bit indicates to place a block with a y offset equal to the bit index.
// e.g. for 0x3, indicates to place a block at 'y = 0' and 'y = 1'

View File

@ -391,7 +391,6 @@
<Compile Include="Database\DatabaseParameterisedQuery.cs" />
<Compile Include="Database\MySQLParameterisedQuery.cs" />
<Compile Include="Database\SQLiteParameterisedQuery.cs" />
<Compile Include="Drawing\BlockWriter.cs" />
<Compile Include="Drawing\Brushes\Brush.cs" />
<Compile Include="Drawing\Brushes\CheckeredBrush.cs" />
<Compile Include="Drawing\Brushes\PasteBrush.cs" />
@ -410,6 +409,7 @@
<Compile Include="Drawing\DrawOps\SpheroidDrawOp.cs" />
<Compile Include="Drawing\DrawOps\PyramidDrawOp.cs" />
<Compile Include="Drawing\DrawOps\TorusDrawOp.cs" />
<Compile Include="Drawing\DrawOps\WriteDrawOp.cs" />
<Compile Include="Drawing\Vector3U16.cs" />
<Compile Include="Games\Countdown\CountdownGame.cs" />
<Compile Include="Games\Countdown\CountdownGame.Game.cs" />