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 System;
using MCGalaxy.Drawing; using MCGalaxy.Drawing;
using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Drawing.Ops;
namespace MCGalaxy.Commands { namespace MCGalaxy.Commands {
@ -53,35 +55,27 @@ namespace MCGalaxy.Commands {
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); 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); RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject; CatchPos bp = (CatchPos)p.blockchangeObject;
bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp; bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2); 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; type = type < 128 ? p.bindings[type] : type;
RevertAndClearState(p, x, y, z); RevertAndClearState(p, x, y, z);
CatchPos cpos = (CatchPos)p.blockchangeObject; CatchPos cpos = (CatchPos)p.blockchangeObject;
Level lvl = p.level; Level lvl = p.level;
if (x == cpos.x && z == cpos.z) { Player.SendMessage(p, "No direction was selected"); return; } if (x == cpos.x && z == cpos.z) { Player.SendMessage(p, "No direction was selected"); return; }
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 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;
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) if (p.staticCommands)
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
} }

View File

@ -1,152 +1,170 @@
/* /*
Copyright 2011 MCForge Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System.Collections.Generic; using System;
using System.Collections.Generic;
namespace MCGalaxy.Drawing { using MCGalaxy.Drawing.Brushes;
internal static class BlockWriter { namespace MCGalaxy.Drawing.Ops {
public static int CountBlocks(string s, byte scale) { public class WriteDrawOp : DrawOp {
int blocks = 0;
foreach (char c in s) { public string Text;
if ((int)c >= 256 || letters[(int)c] == null) { public byte Scale, Spacing;
blocks += (4 * scale) * (4 * scale);
} else { public override string Name { get { return "Write"; } }
byte[] flags = letters[(int)c];
for (int i = 0; i < flags.Length; i++) public override bool MinMaxCoords { get { return false; } }
blocks += scale * scale * HighestBit(flags[i]);
} public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) {
} int blocks = 0;
return blocks; foreach (char c in Text) {
} if ((int)c >= 256 || letters[(int)c] == null) {
blocks += (4 * Scale) * (4 * Scale);
public static void DrawLetter(Level l, Player p, char c, ref ushort x, ushort y, ref ushort z, } else {
byte type, byte extType, int dir, byte scale, byte spacing) { byte[] flags = letters[(int)c];
int dirX = dir == 0 ? 1 : dir == 1 ? -1 : 0; for (int i = 0; i < flags.Length; i++)
int dirZ = dir == 2 ? 1 : dir == 3 ? -1 : 0; blocks += Scale * Scale * HighestBit(flags[i]);
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); return blocks;
z = (ushort)(z + dirZ * 4 * scale); }
} else {
byte[] flags = letters[(int)c]; int dirX, dirZ;
for (int i = 0; i < flags.Length; i++) { public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
byte yUsed = flags[i]; ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
for (int j = 0; j < 8; j++) { if (Math.Abs(x2 - x1) > Math.Abs(z2 - z1))
if ((yUsed & (1 << j)) == 0) continue; dirX = x2 > x1? 1 : -1;
else
for (int ver = 0; ver < scale; ver++) dirZ = z2 > z1 ? 1 : -1;
for (int hor = 0; hor < scale; hor++) { foreach (char c in Text)
int xx = x + dirX * hor, yy = y + j * scale + ver, zz = z + dirZ * hor; DrawLetter(p, lvl, c, ref x1, y1, ref z1, brush);
l.UpdateBlock(p, (ushort)xx, (ushort)yy, (ushort)zz, type, extType); }
}
} void DrawLetter(Player p, Level lvl, char c, ref ushort x, ushort y, ref ushort z, Brush brush) {
x = (ushort)(x + dirX * scale); if ((int)c >= 256 || letters[(int)c] == null) {
z = (ushort)(z + dirZ * scale); 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 * spacing); } else {
z = (ushort)(z + dirZ * spacing); byte[] flags = letters[(int)c];
} for (int i = 0; i < flags.Length; i++) {
byte yUsed = flags[i];
static int HighestBit(int value) { for (int j = 0; j < 8; j++) {
int bits = 0; if ((yUsed & (1 << j)) == 0) continue;
while (value > 0) {
value >>= 1; bits++; for (int ver = 0; ver < Scale; ver++)
} for (int hor = 0; hor < Scale; hor++)
return bits; {
} int xx = x + dirX * hor, yy = y + j * Scale + ver, zz = z + dirZ * hor;
PlaceBlock(p, lvl, (ushort)xx, (ushort)yy, (ushort)zz, brush);
static byte[][] letters; }
static BlockWriter() { }
letters = new byte[256][]; x = (ushort)(x + dirX * Scale);
// each set bit indicates to place a block with a y offset equal to the bit index. z = (ushort)(z + dirZ * Scale);
// e.g. for 0x3, indicates to place a block at 'y = 0' and 'y = 1' }
letters['A'] = new byte[] { 0x0F, 0x14, 0x0F }; }
letters['B'] = new byte[] { 0x1F, 0x15, 0x0A }; x = (ushort)(x + dirX * Spacing);
letters['C'] = new byte[] { 0x0E, 0x11, 0x11 }; z = (ushort)(z + dirZ * Spacing);
letters['D'] = new byte[] { 0x1F, 0x11, 0x0E }; }
letters['E'] = new byte[] { 0x1F, 0x15, 0x15 };
letters['F'] = new byte[] { 0x1F, 0x14, 0x14 }; static int HighestBit(int value) {
letters['G'] = new byte[] { 0x0E, 0x11, 0x17 }; int bits = 0;
letters['H'] = new byte[] { 0x1F, 0x04, 0x1F }; while (value > 0) {
letters['I'] = new byte[] { 0x11, 0x1F, 0x11 }; value >>= 1; bits++;
letters['J'] = new byte[] { 0x11, 0x11, 0x1E }; }
letters['K'] = new byte[] { 0x1F, 0x04, 0x1B }; return bits;
letters['L'] = new byte[] { 0x1F, 0x01, 0x01 }; }
letters['M'] = new byte[] { 0x1F, 0x08, 0x04, 0x08, 0x1F };
letters['N'] = new byte[] { 0x1F, 0x08, 0x04, 0x02, 0x1F }; static byte[][] letters;
letters['O'] = new byte[] { 0x0E, 0x11, 0x0E }; static WriteDrawOp() {
letters['P'] = new byte[] { 0x1F, 0x14, 0x08 }; letters = new byte[256][];
letters['Q'] = new byte[] { 0x0E, 0x11, 0x13, 0x0F }; // each set bit indicates to place a block with a y offset equal to the bit index.
letters['R'] = new byte[] { 0x1F, 0x14, 0x0B }; // e.g. for 0x3, indicates to place a block at 'y = 0' and 'y = 1'
letters['S'] = new byte[] { 0x09, 0x15, 0x12 }; letters['A'] = new byte[] { 0x0F, 0x14, 0x0F };
letters['T'] = new byte[] { 0x10, 0x1F, 0x10 }; letters['B'] = new byte[] { 0x1F, 0x15, 0x0A };
letters['U'] = new byte[] { 0x1E, 0x01, 0x1E }; letters['C'] = new byte[] { 0x0E, 0x11, 0x11 };
letters['V'] = new byte[] { 0x18, 0x06, 0x01, 0x06, 0x18 }; letters['D'] = new byte[] { 0x1F, 0x11, 0x0E };
letters['W'] = new byte[] { 0x1F, 0x02, 0x04, 0x02, 0x1F }; letters['E'] = new byte[] { 0x1F, 0x15, 0x15 };
letters['X'] = new byte[] { 0x1B, 0x04, 0x1B }; letters['F'] = new byte[] { 0x1F, 0x14, 0x14 };
letters['Y'] = new byte[] { 0x10, 0x08, 0x07, 0x08, 0x10 }; letters['G'] = new byte[] { 0x0E, 0x11, 0x17 };
letters['Z'] = new byte[] { 0x11, 0x13, 0x15, 0x19, 0x11 }; letters['H'] = new byte[] { 0x1F, 0x04, 0x1F };
letters['0'] = new byte[] { 0x0E, 0x13, 0x15, 0x19, 0x0E }; letters['I'] = new byte[] { 0x11, 0x1F, 0x11 };
letters['1'] = new byte[] { 0x09, 0x1F, 0x01 }; letters['J'] = new byte[] { 0x11, 0x11, 0x1E };
letters['2'] = new byte[] { 0x17, 0x15, 0x1D }; letters['K'] = new byte[] { 0x1F, 0x04, 0x1B };
letters['3'] = new byte[] { 0x15, 0x15, 0x1F }; letters['L'] = new byte[] { 0x1F, 0x01, 0x01 };
letters['4'] = new byte[] { 0x1E, 0x02, 0x07, 0x02 }; letters['M'] = new byte[] { 0x1F, 0x08, 0x04, 0x08, 0x1F };
letters['5'] = new byte[] { 0x1D, 0x15, 0x17 }; letters['N'] = new byte[] { 0x1F, 0x08, 0x04, 0x02, 0x1F };
letters['6'] = new byte[] { 0x1F, 0x15, 0x17 }; letters['O'] = new byte[] { 0x0E, 0x11, 0x0E };
letters['7'] = new byte[] { 0x10, 0x10, 0x1F }; letters['P'] = new byte[] { 0x1F, 0x14, 0x08 };
letters['8'] = new byte[] { 0x1F, 0x15, 0x1F }; letters['Q'] = new byte[] { 0x0E, 0x11, 0x13, 0x0F };
letters['9'] = new byte[] { 0x1D, 0x15, 0x1F }; letters['R'] = new byte[] { 0x1F, 0x14, 0x0B };
letters['S'] = new byte[] { 0x09, 0x15, 0x12 };
letters[' '] = new byte[] { 0x00 }; letters['T'] = new byte[] { 0x10, 0x1F, 0x10 };
letters['!'] = new byte[] { 0x1D }; letters['U'] = new byte[] { 0x1E, 0x01, 0x1E };
letters['"'] = new byte[] { 0x18, 0x00, 0x18 }; letters['V'] = new byte[] { 0x18, 0x06, 0x01, 0x06, 0x18 };
// # is missing letters['W'] = new byte[] { 0x1F, 0x02, 0x04, 0x02, 0x1F };
// $ is missing letters['X'] = new byte[] { 0x1B, 0x04, 0x1B };
// % is missing letters['Y'] = new byte[] { 0x10, 0x08, 0x07, 0x08, 0x10 };
// & is missing letters['Z'] = new byte[] { 0x11, 0x13, 0x15, 0x19, 0x11 };
letters['\''] = new byte[] { 0x18 }; letters['0'] = new byte[] { 0x0E, 0x13, 0x15, 0x19, 0x0E };
letters['('] = new byte[] { 0x0E, 0x11 }; letters['1'] = new byte[] { 0x09, 0x1F, 0x01 };
letters[')'] = new byte[] { 0x11, 0x0E }; letters['2'] = new byte[] { 0x17, 0x15, 0x1D };
// * is missing letters['3'] = new byte[] { 0x15, 0x15, 0x1F };
letters['+'] = new byte[] { 0x04, 0x0E, 0x04 }; letters['4'] = new byte[] { 0x1E, 0x02, 0x07, 0x02 };
letters[','] = new byte[] { 0x01, 0x03 }; letters['5'] = new byte[] { 0x1D, 0x15, 0x17 };
letters['-'] = new byte[] { 0x04, 0x04, 0x04 }; letters['6'] = new byte[] { 0x1F, 0x15, 0x17 };
letters['.'] = new byte[] { 0x01 }; letters['7'] = new byte[] { 0x10, 0x10, 0x1F };
letters['/'] = new byte[] { 0x01, 0x02, 0x04, 0x08, 0x10 }; letters['8'] = new byte[] { 0x1F, 0x15, 0x1F };
letters[':'] = new byte[] { 0x0A }; letters['9'] = new byte[] { 0x1D, 0x15, 0x1F };
letters[';'] = new byte[] { 0x10, 0x0A };
letters['\\'] = new byte[] { 0x10, 0x08, 0x04, 0x02, 0x01 }; letters[' '] = new byte[] { 0x00 };
letters['<'] = new byte[] { 0x04, 0x0A, 0x11 }; letters['!'] = new byte[] { 0x1D };
letters['='] = new byte[] { 0x0A, 0x0A, 0x0A }; letters['"'] = new byte[] { 0x18, 0x00, 0x18 };
letters['>'] = new byte[] { 0x11, 0x0A, 0x04 }; // # is missing
// '?' is missing // $ is missing
// '@' is missing // % is missing
letters['['] = new byte[] { 0x1F, 0x11 }; // & is missing
letters['\''] = new byte[] { 0x18 }; letters['\''] = new byte[] { 0x18 };
letters[']'] = new byte[] { 0x11, 0x1F }; letters['('] = new byte[] { 0x0E, 0x11 };
letters['_'] = new byte[] { 0x01, 0x01, 0x01, 0x01 }; letters[')'] = new byte[] { 0x11, 0x0E };
letters['`'] = new byte[] { 0x10, 0x08 }; // * is missing
letters['{'] = new byte[] { 0x04, 0x1B, 0x11 }; letters['+'] = new byte[] { 0x04, 0x0E, 0x04 };
letters['|'] = new byte[] { 0x1F }; letters[','] = new byte[] { 0x01, 0x03 };
letters['}'] = new byte[] { 0x11, 0x1B, 0x04 }; letters['-'] = new byte[] { 0x04, 0x04, 0x04 };
letters['~'] = new byte[] { 0x04, 0x08, 0x04, 0x08 }; letters['.'] = new byte[] { 0x01 };
} letters['/'] = new byte[] { 0x01, 0x02, 0x04, 0x08, 0x10 };
} letters[':'] = new byte[] { 0x0A };
} letters[';'] = new byte[] { 0x10, 0x0A };
letters['\\'] = new byte[] { 0x10, 0x08, 0x04, 0x02, 0x01 };
letters['<'] = new byte[] { 0x04, 0x0A, 0x11 };
letters['='] = new byte[] { 0x0A, 0x0A, 0x0A };
letters['>'] = new byte[] { 0x11, 0x0A, 0x04 };
// '?' is missing
// '@' is missing
letters['['] = new byte[] { 0x1F, 0x11 };
letters['\''] = new byte[] { 0x18 };
letters[']'] = new byte[] { 0x11, 0x1F };
letters['_'] = new byte[] { 0x01, 0x01, 0x01, 0x01 };
letters['`'] = new byte[] { 0x10, 0x08 };
letters['{'] = new byte[] { 0x04, 0x1B, 0x11 };
letters['|'] = new byte[] { 0x1F };
letters['}'] = new byte[] { 0x11, 0x1B, 0x04 };
letters['~'] = new byte[] { 0x04, 0x08, 0x04, 0x08 };
}
}
}

View File

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