mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-27 07:11:04 -04:00
The /write command is now a drawop. (Does not use player brush though)
This commit is contained in:
parent
e15b8f1d94
commit
82a08e6b7e
@ -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; }
|
||||||
|
|
||||||
int dir = 0;
|
WriteDrawOp op = new WriteDrawOp();
|
||||||
if (Math.Abs(cpos.x - x) > Math.Abs(cpos.z - z))
|
op.Text = cpos.givenMessage;
|
||||||
dir = x > cpos.x ? 0 : 1;
|
op.Scale = cpos.scale; op.Spacing = cpos.spacing;
|
||||||
else
|
Brush brush = new SolidBrush(type, extType);
|
||||||
dir = z > cpos.z ? 2 : 3;
|
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)
|
if (p.staticCommands)
|
||||||
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
|
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
|
||||||
}
|
}
|
||||||
|
@ -15,34 +15,51 @@
|
|||||||
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;
|
||||||
using System.Collections.Generic;
|
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;
|
int blocks = 0;
|
||||||
foreach (char c in s) {
|
foreach (char c in Text) {
|
||||||
if ((int)c >= 256 || letters[(int)c] == null) {
|
if ((int)c >= 256 || letters[(int)c] == null) {
|
||||||
blocks += (4 * scale) * (4 * scale);
|
blocks += (4 * Scale) * (4 * Scale);
|
||||||
} else {
|
} else {
|
||||||
byte[] flags = letters[(int)c];
|
byte[] flags = letters[(int)c];
|
||||||
for (int i = 0; i < flags.Length; i++)
|
for (int i = 0; i < flags.Length; i++)
|
||||||
blocks += scale * scale * HighestBit(flags[i]);
|
blocks += Scale * Scale * HighestBit(flags[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DrawLetter(Level l, Player p, char c, ref ushort x, ushort y, ref ushort z,
|
int dirX, dirZ;
|
||||||
byte type, byte extType, int dir, byte scale, byte spacing) {
|
public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
|
||||||
int dirX = dir == 0 ? 1 : dir == 1 ? -1 : 0;
|
ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
|
||||||
int dirZ = dir == 2 ? 1 : dir == 3 ? -1 : 0;
|
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) {
|
if ((int)c >= 256 || letters[(int)c] == null) {
|
||||||
Player.SendMessage(p, "\"" + c + "\" is not currently supported, replacing with space.");
|
Player.SendMessage(p, "\"" + c + "\" is not currently supported, replacing with space.");
|
||||||
x = (ushort)(x + dirX * 4 * scale);
|
x = (ushort)(x + dirX * 4 * Scale);
|
||||||
z = (ushort)(z + dirZ * 4 * scale);
|
z = (ushort)(z + dirZ * 4 * Scale);
|
||||||
} else {
|
} else {
|
||||||
byte[] flags = letters[(int)c];
|
byte[] flags = letters[(int)c];
|
||||||
for (int i = 0; i < flags.Length; i++) {
|
for (int i = 0; i < flags.Length; i++) {
|
||||||
@ -50,18 +67,19 @@ namespace MCGalaxy.Drawing {
|
|||||||
for (int j = 0; j < 8; j++) {
|
for (int j = 0; j < 8; j++) {
|
||||||
if ((yUsed & (1 << j)) == 0) continue;
|
if ((yUsed & (1 << j)) == 0) continue;
|
||||||
|
|
||||||
for (int ver = 0; ver < scale; ver++)
|
for (int ver = 0; ver < Scale; ver++)
|
||||||
for (int hor = 0; hor < scale; hor++) {
|
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);
|
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);
|
x = (ushort)(x + dirX * Scale);
|
||||||
z = (ushort)(z + dirZ * scale);
|
z = (ushort)(z + dirZ * Scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x = (ushort)(x + dirX * spacing);
|
x = (ushort)(x + dirX * Spacing);
|
||||||
z = (ushort)(z + dirZ * spacing);
|
z = (ushort)(z + dirZ * Spacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int HighestBit(int value) {
|
static int HighestBit(int value) {
|
||||||
@ -73,7 +91,7 @@ namespace MCGalaxy.Drawing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static byte[][] letters;
|
static byte[][] letters;
|
||||||
static BlockWriter() {
|
static WriteDrawOp() {
|
||||||
letters = new byte[256][];
|
letters = new byte[256][];
|
||||||
// each set bit indicates to place a block with a y offset equal to the bit index.
|
// 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'
|
// e.g. for 0x3, indicates to place a block at 'y = 0' and 'y = 1'
|
@ -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" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user