Fix brush arguments being incorrectly treated as draw modes in some cases.

This commit is contained in:
UnknownShadow200 2016-03-09 11:44:52 +11:00
parent 37cd475398
commit 3fc5bb1b75
7 changed files with 104 additions and 82 deletions

View File

@ -34,23 +34,25 @@ namespace MCGalaxy.Commands
DrawOp drawOp = null; DrawOp drawOp = null;
Brush brush = null; Brush brush = null;
switch (cpos.solid) { switch (cpos.mode) {
case SolidType.solid: case DrawMode.solid:
case DrawMode.normal:
drawOp = new CuboidDrawOp(); break; drawOp = new CuboidDrawOp(); break;
case SolidType.hollow: case DrawMode.hollow:
drawOp = new CuboidHollowsDrawOp(); break; drawOp = new CuboidHollowsDrawOp(); break;
case SolidType.walls: case DrawMode.walls:
drawOp = new CuboidWallsDrawOp(); break; drawOp = new CuboidWallsDrawOp(); break;
case SolidType.holes: case DrawMode.holes:
drawOp = new CuboidHolesDrawOp(); break; drawOp = new CuboidHolesDrawOp(); break;
case SolidType.wire: case DrawMode.wire:
drawOp = new CuboidWireframeDrawOp(); break; drawOp = new CuboidWireframeDrawOp(); break;
case SolidType.random: case DrawMode.random:
drawOp = new CuboidDrawOp(); drawOp = new CuboidDrawOp();
brush = new RandomBrush(cpos.type, cpos.extType); break; brush = new RandomBrush(cpos.type, cpos.extType); break;
} }
if (brush == null) brush = GetBrush(p, cpos, 1); int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
if (brush == null) brush = GetBrush(p, cpos, brushOffset);
if (brush == null) return; if (brush == null) return;
if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z)) if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))
return; return;
@ -58,19 +60,20 @@ namespace MCGalaxy.Commands
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
} }
protected override SolidType GetType(string msg) { protected override DrawMode ParseMode(string msg) {
if (msg == "hollow") return SolidType.hollow; if (msg == "solid") return DrawMode.solid;
else if (msg == "walls") return SolidType.walls; else if (msg == "hollow") return DrawMode.hollow;
else if (msg == "holes") return SolidType.holes; else if (msg == "walls") return DrawMode.walls;
else if (msg == "wire") return SolidType.wire; else if (msg == "holes") return DrawMode.holes;
else if (msg == "random") return SolidType.random; else if (msg == "wire") return DrawMode.wire;
return SolidType.solid; else if (msg == "random") return DrawMode.random;
return DrawMode.normal;
} }
public override void Help(Player p) { public override void Help(Player p) {
Player.SendMessage(p, "%T/cuboid [block type] <mode>"); Player.SendMessage(p, "%T/cuboid [block type] <mode>");
Player.SendMessage(p, " %HCreates a cuboid between two points."); Player.SendMessage(p, " %HCreates a cuboid between two points.");
Player.SendMessage(p, " %HMode can be: solid/hollow/walls/holes/wire/random"); Player.SendMessage(p, " %HMode can be: solid/hollow/walls/holes/wire/random");
} }
} }
} }

View File

@ -28,13 +28,13 @@ namespace MCGalaxy.Commands {
public override string shortcut { get { return "f"; } } public override string shortcut { get { return "f"; } }
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
protected override SolidType GetType(string msg) { protected override DrawMode ParseMode(string msg) {
if (msg == "up") return SolidType.up; if (msg == "up") return DrawMode.up;
else if (msg == "down") return SolidType.down; else if (msg == "down") return DrawMode.down;
else if (msg == "layer") return SolidType.layer; else if (msg == "layer") return DrawMode.layer;
else if (msg == "vertical_x") return SolidType.verticalX; else if (msg == "vertical_x") return DrawMode.verticalX;
else if (msg == "vertical_z") return SolidType.verticalZ; else if (msg == "vertical_z") return DrawMode.verticalZ;
return SolidType.solid; return DrawMode.normal;
} }
protected override string PlaceMessage { protected override string PlaceMessage {
@ -62,19 +62,20 @@ namespace MCGalaxy.Commands {
SparseBitSet bits = new SparseBitSet(p.level.Width, p.level.Height, p.level.Length); SparseBitSet bits = new SparseBitSet(p.level.Width, p.level.Height, p.level.Length);
List<int> buffer = new List<int>(), origins = new List<int>(); List<int> buffer = new List<int>(), origins = new List<int>();
FloodFill(p, x, y, z, oldType, oldExtType, cpos.solid, bits, buffer, origins, 0); FloodFill(p, x, y, z, oldType, oldExtType, cpos.mode, bits, buffer, origins, 0);
int totalFill = origins.Count; int totalFill = origins.Count;
for (int i = 0; i < totalFill; i++) { for (int i = 0; i < totalFill; i++) {
int pos = origins[i]; int pos = origins[i];
p.level.IntToPos(pos, out x, out y, out z); p.level.IntToPos(pos, out x, out y, out z);
FloodFill(p, x, y, z, oldType, oldExtType, cpos.solid, bits, buffer, origins, 0); FloodFill(p, x, y, z, oldType, oldExtType, cpos.mode, bits, buffer, origins, 0);
totalFill = origins.Count; totalFill = origins.Count;
} }
FillDrawOp drawOp = new FillDrawOp(); FillDrawOp drawOp = new FillDrawOp();
drawOp.Positions = buffer; drawOp.Positions = buffer;
Brush brush = GetBrush(p, cpos, 1); int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
Brush brush = GetBrush(p, cpos, brushOffset);
if (brush == null) return; if (brush == null) return;
if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, cpos.x, cpos.y, cpos.z)) if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, cpos.x, cpos.y, cpos.z))
return; return;
@ -87,7 +88,7 @@ namespace MCGalaxy.Commands {
protected override void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { } protected override void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { }
void FloodFill(Player p, ushort x, ushort y, ushort z, byte oldType, byte oldExtType, SolidType fillType, void FloodFill(Player p, ushort x, ushort y, ushort z, byte oldType, byte oldExtType, DrawMode fillType,
SparseBitSet bits, List<int> buffer, List<int> origins, int depth) { SparseBitSet bits, List<int> buffer, List<int> origins, int depth) {
if (bits.Get(x, y, z)) return; if (bits.Get(x, y, z)) return;
int index = p.level.PosToInt(x, y, z); int index = p.level.PosToInt(x, y, z);
@ -95,26 +96,26 @@ namespace MCGalaxy.Commands {
bits.Set(x, y, z, true); bits.Set(x, y, z, true);
buffer.Add(index); buffer.Add(index);
if (fillType != SolidType.verticalX) { // x if (fillType != DrawMode.verticalX) { // x
if (CheckTile(p, (ushort)(x + 1), y, z, oldType, oldExtType)) if (CheckTile(p, (ushort)(x + 1), y, z, oldType, oldExtType))
FloodFill(p, (ushort)(x + 1), y, z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); FloodFill(p, (ushort)(x + 1), y, z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
if (CheckTile(p, (ushort)(x - 1), y, z, oldType, oldExtType)) if (CheckTile(p, (ushort)(x - 1), y, z, oldType, oldExtType))
FloodFill(p, (ushort)(x - 1), y, z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); FloodFill(p, (ushort)(x - 1), y, z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
} }
if (fillType != SolidType.verticalZ) { // z if (fillType != DrawMode.verticalZ) { // z
if (CheckTile(p, x, y, (ushort)(z + 1), oldType, oldExtType)) if (CheckTile(p, x, y, (ushort)(z + 1), oldType, oldExtType))
FloodFill(p, x, y, (ushort)(z + 1), oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); FloodFill(p, x, y, (ushort)(z + 1), oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
if (CheckTile(p, x, y, (ushort)(z - 1), oldType, oldExtType)) if (CheckTile(p, x, y, (ushort)(z - 1), oldType, oldExtType))
FloodFill(p, x, y, (ushort)(z - 1), oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); FloodFill(p, x, y, (ushort)(z - 1), oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
} }
if (!(fillType == SolidType.down || fillType == SolidType.layer)) { // y up if (!(fillType == DrawMode.down || fillType == DrawMode.layer)) { // y up
if (CheckTile(p, x, (ushort)(y + 1), z, oldType, oldExtType)) if (CheckTile(p, x, (ushort)(y + 1), z, oldType, oldExtType))
FloodFill(p, x, (ushort)(y + 1), z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); FloodFill(p, x, (ushort)(y + 1), z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
} }
if (!(fillType == SolidType.up || fillType == SolidType.layer)) { // y down if (!(fillType == DrawMode.up || fillType == DrawMode.layer)) { // y down
if (CheckTile(p, x, (ushort)(y - 1), z, oldType, oldExtType)) if (CheckTile(p, x, (ushort)(y - 1), z, oldType, oldExtType))
FloodFill(p, x, (ushort)(y - 1), z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); FloodFill(p, x, (ushort)(y - 1), z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1);
} }

View File

@ -28,23 +28,30 @@ namespace MCGalaxy.Commands {
public override string name { get { return "line"; } } public override string name { get { return "line"; } }
public override string shortcut { get { return "l"; } } public override string shortcut { get { return "l"; } }
protected override SolidType GetType(string msg) { protected override DrawMode ParseMode(string msg) {
if (msg == "walls") return SolidType.walls; if (msg == "normal") return DrawMode.solid;
else if (msg == "straight") return SolidType.straight; else if (msg == "walls") return DrawMode.walls;
return SolidType.solid; else if (msg == "straight") return DrawMode.straight;
return DrawMode.normal;
} }
protected override void OnUse(Player p, string msg, string[] parts, ref CatchPos cpos) { protected override void OnUse(Player p, string msg, string[] parts, ref CatchPos cpos) {
if (parts.Length >= 2) { if (parts.Length < 2 || cpos.mode == DrawMode.normal) return;
string arg = parts[parts.Length - 1]; string arg = parts[parts.Length - 1];
ushort len; ushort len;
if (!ushort.TryParse(arg, out len)) { if (ushort.TryParse(arg, out len))
if (arg == "walls" || arg == "straight" || arg == "normal") return; cpos.data = len;
Player.SendMessage(p, msg + " is not valid length, assuming maximum length allowed."); }
} else {
cpos.data = len; protected override DrawMode GetMode(string message, string[] parts) {
} if (message == "") return DrawMode.normal;
} DrawMode mode = ParseMode(parts[parts.Length - 1]);
if (mode != DrawMode.normal) return mode;
// May be in the format <brush args> <mode> <max_length>
ushort len;
if (!ushort.TryParse(parts[parts.Length - 1], out len)) return DrawMode.normal;
return ParseMode(parts[parts.Length - 2]);
} }
protected override void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { protected override void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
@ -52,7 +59,7 @@ namespace MCGalaxy.Commands {
CatchPos cpos = (CatchPos)p.blockchangeObject; CatchPos cpos = (CatchPos)p.blockchangeObject;
GetRealBlock(type, extType, p, ref cpos); GetRealBlock(type, extType, p, ref cpos);
if (cpos.solid == SolidType.straight) { if (cpos.mode == DrawMode.straight) {
int dx = Math.Abs(cpos.x - x); int dx = Math.Abs(cpos.x - x);
int dy = Math.Abs(cpos.y - y); int dy = Math.Abs(cpos.y - y);
int dz = Math.Abs(cpos.z - z); int dz = Math.Abs(cpos.z - z);
@ -67,10 +74,12 @@ namespace MCGalaxy.Commands {
} }
LineDrawOp drawOp = new LineDrawOp(); LineDrawOp drawOp = new LineDrawOp();
drawOp.WallsMode = cpos.solid == SolidType.walls; drawOp.WallsMode = cpos.mode == DrawMode.walls;
if (cpos.data != null) int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
drawOp.MaxLength = (ushort)cpos.data; if (cpos.data != null) {
Brush brush = GetBrush(p, cpos, cpos.data == null ? 1 : 2); drawOp.MaxLength = (ushort)cpos.data; brushOffset++;
}
Brush brush = GetBrush(p, cpos, brushOffset);
if (brush == null) return; if (brush == null) return;
if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z)) if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))

View File

@ -32,7 +32,8 @@ namespace MCGalaxy.Commands
CatchPos cpos = (CatchPos)p.blockchangeObject; CatchPos cpos = (CatchPos)p.blockchangeObject;
GetRealBlock(type, extType, p, ref cpos); GetRealBlock(type, extType, p, ref cpos);
DrawOp drawOp = null; DrawOp drawOp = null;
Brush brush = GetBrush(p, cpos, 1); int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
Brush brush = GetBrush(p, cpos, brushOffset);
if (brush == null) return; if (brush == null) return;
if (y != cpos.y) { if (y != cpos.y) {
@ -40,12 +41,13 @@ namespace MCGalaxy.Commands
return; return;
} }
switch (cpos.solid) { switch (cpos.mode) {
case SolidType.solid: case DrawMode.solid:
case DrawMode.normal:
drawOp = new PyramidSolidDrawOp(); break; drawOp = new PyramidSolidDrawOp(); break;
case SolidType.hollow: case DrawMode.hollow:
drawOp = new PyramidHollowDrawOp(); break; drawOp = new PyramidHollowDrawOp(); break;
case SolidType.reverse: case DrawMode.reverse:
drawOp = new PyramidReverseDrawOp(); break; drawOp = new PyramidReverseDrawOp(); break;
} }
@ -55,10 +57,11 @@ namespace MCGalaxy.Commands
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
} }
protected override SolidType GetType(string msg) { protected override DrawMode ParseMode(string msg) {
if (msg == "hollow") return SolidType.hollow; if (msg == "solid") return DrawMode.solid;
else if (msg == "reverse") return SolidType.reverse; else if (msg == "hollow") return DrawMode.hollow;
return SolidType.solid; else if (msg == "reverse") return DrawMode.reverse;
return DrawMode.normal;
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -32,15 +32,17 @@ namespace MCGalaxy.Commands {
CatchPos cpos = (CatchPos)p.blockchangeObject; CatchPos cpos = (CatchPos)p.blockchangeObject;
GetRealBlock(type, extType, p, ref cpos); GetRealBlock(type, extType, p, ref cpos);
DrawOp drawOp = null; DrawOp drawOp = null;
Brush brush = GetBrush(p, cpos, 1); int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
Brush brush = GetBrush(p, cpos, brushOffset);
if (brush == null) return; if (brush == null) return;
switch (cpos.solid) { switch (cpos.mode) {
case SolidType.solid: case DrawMode.solid:
case DrawMode.normal:
drawOp = new EllipsoidDrawOp(); break; drawOp = new EllipsoidDrawOp(); break;
case SolidType.hollow: case DrawMode.hollow:
drawOp = new EllipsoidHollowDrawOp(); break; drawOp = new EllipsoidHollowDrawOp(); break;
case SolidType.vertical: case DrawMode.vertical:
drawOp = new CylinderDrawOp(); break; drawOp = new CylinderDrawOp(); break;
} }
@ -50,10 +52,11 @@ namespace MCGalaxy.Commands {
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
} }
protected override SolidType GetType(string msg) { protected override DrawMode ParseMode(string msg) {
if (msg == "hollow") return SolidType.hollow; if (msg == "solid") return DrawMode.solid;
else if (msg == "vertical") return SolidType.vertical; else if (msg == "hollow") return DrawMode.hollow;
return SolidType.solid; else if (msg == "vertical") return DrawMode.vertical;
return DrawMode.normal;
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -41,8 +41,8 @@ namespace MCGalaxy.Commands {
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
} }
protected override SolidType GetType(string msg) { protected override DrawMode ParseMode(string msg) {
return SolidType.solid; return DrawMode.normal;
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -27,12 +27,11 @@ namespace MCGalaxy.Commands {
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } public override LevelPermission defaultRank { get { return LevelPermission.Builder; } }
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
message = message.ToLower();
string[] parts = message.Split(' '); string[] parts = message.Split(' ');
for (int i = 0; i < parts.Length; i++)
parts[i] = parts[i].ToLower();
CatchPos cpos = default(CatchPos); CatchPos cpos = default(CatchPos);
cpos.message = message.ToLower(); cpos.message = message;
cpos.solid = message == "" ? SolidType.solid : GetType(parts[parts.Length - 1]); cpos.mode = GetMode(message, parts);
OnUse(p, message, parts, ref cpos); OnUse(p, message, parts, ref cpos);
p.blockchangeObject = cpos; p.blockchangeObject = cpos;
@ -58,10 +57,14 @@ namespace MCGalaxy.Commands {
protected abstract void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType); protected abstract void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType);
protected abstract SolidType GetType(string msg); protected abstract DrawMode ParseMode(string mode);
protected virtual void OnUse(Player p, string msg, string[] parts, ref CatchPos cpos) { } protected virtual void OnUse(Player p, string msg, string[] parts, ref CatchPos cpos) { }
protected virtual DrawMode GetMode(string message, string[] parts) {
return message == "" ? DrawMode.normal : ParseMode(parts[parts.Length - 1]);
}
internal static byte GetBlock(Player p, string msg, out byte extType, bool checkPlacePerm = true) { internal static byte GetBlock(Player p, string msg, out byte extType, bool checkPlacePerm = true) {
byte type = Block.Byte(msg); byte type = Block.Byte(msg);
extType = 0; extType = 0;
@ -84,10 +87,10 @@ namespace MCGalaxy.Commands {
} }
protected static Brush GetBrush(Player p, CatchPos cpos, int usedFromEnd) { protected static Brush GetBrush(Player p, CatchPos cpos, int usedFromEnd) {
int end = cpos.message.Length - 1; int end = cpos.message.Length;
string brushMsg = ""; string brushMsg = "";
for (int i = 0; i < usedFromEnd; i++) { for (int i = 0; i < usedFromEnd; i++) {
end = cpos.message.LastIndexOf(' ', end); end = cpos.message.LastIndexOf(' ', end - 1);
if (end == -1) break; if (end == -1) break;
} }
@ -103,15 +106,15 @@ namespace MCGalaxy.Commands {
} }
protected struct CatchPos { protected struct CatchPos {
public SolidType solid; public DrawMode mode;
public byte type, extType; public byte type, extType;
public ushort x, y, z; public ushort x, y, z;
public object data; public object data;
public string message; public string message;
} }
protected enum SolidType { protected enum DrawMode {
solid, hollow, walls, normal, solid, hollow, walls,
holes, wire, random, holes, wire, random,
vertical, reverse, straight, vertical, reverse, straight,
up, down, layer, verticalX, verticalZ, up, down, layer, verticalX, verticalZ,