mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Now also perform brush syntax validation at the time the draw operation is called, in addition to when all marks are placed.
This commit is contained in:
parent
c13c4c5c26
commit
41a6c2ca0a
@ -43,34 +43,35 @@ namespace MCGalaxy.Commands.Building {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks,
|
||||
object state, byte block, byte extBlock) {
|
||||
DrawArgs dArgs = (DrawArgs)state;
|
||||
ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
|
||||
byte oldType = p.level.GetTile(x, y, z), oldExtType = 0;
|
||||
if (oldType == Block.custom_block)
|
||||
oldExtType = p.level.GetExtTile(x, y, z);
|
||||
byte oldBlock = p.level.GetTile(x, y, z), oldExtBlock = 0;
|
||||
if (oldBlock == Block.custom_block)
|
||||
oldExtBlock = p.level.GetExtTile(x, y, z);
|
||||
|
||||
cpos.Block = type; cpos.ExtBlock = extType;
|
||||
if (!Block.canPlace(p, oldType) && !Block.BuildIn(oldType)) {
|
||||
Formatter.MessageBlock(p, "fill over ", oldType); return false;
|
||||
dArgs.Block = block; dArgs.ExtBlock = extBlock;
|
||||
if (!Block.canPlace(p, oldBlock) && !Block.BuildIn(oldBlock)) {
|
||||
Formatter.MessageBlock(p, "fill over ", oldBlock); return false;
|
||||
}
|
||||
|
||||
SparseBitSet bits = new SparseBitSet(p.level.Width, p.level.Height, p.level.Length);
|
||||
List<int> buffer = new List<int>(), origins = new List<int>();
|
||||
FloodFill(p, x, y, z, oldType, oldExtType, cpos.Mode, bits, buffer, origins, 0);
|
||||
FloodFill(p, x, y, z, oldBlock, oldExtBlock, dArgs.Mode, bits, buffer, origins, 0);
|
||||
|
||||
int totalFill = origins.Count;
|
||||
for (int i = 0; i < totalFill; i++) {
|
||||
int pos = origins[i];
|
||||
p.level.IntToPos(pos, out x, out y, out z);
|
||||
FloodFill(p, x, y, z, oldType, oldExtType, cpos.Mode, bits, buffer, origins, 0);
|
||||
FloodFill(p, x, y, z, oldBlock, oldExtBlock, dArgs.Mode, bits, buffer, origins, 0);
|
||||
totalFill = origins.Count;
|
||||
}
|
||||
|
||||
FillDrawOp op = new FillDrawOp();
|
||||
op.Positions = buffer;
|
||||
int offset = cpos.Mode == DrawMode.normal ? 0 : 1;
|
||||
Brush brush = ParseBrush(p, cpos, offset);
|
||||
int offset = dArgs.Mode == DrawMode.normal ? 0 : 1;
|
||||
Brush brush = ParseBrush(p, dArgs, offset);
|
||||
if (brush == null || !DrawOp.DoDrawOp(op, brush, p, marks)) return false;
|
||||
bits.Clear();
|
||||
op.Positions = null;
|
||||
|
@ -25,17 +25,6 @@ namespace MCGalaxy.Commands.Building {
|
||||
public override string shortcut { get { return "l"; } }
|
||||
protected override string PlaceMessage { get { return "Place two blocks to determine the endpoints."; } }
|
||||
|
||||
protected override void OnUse(Player p, string msg, string[] parts, ref DrawArgs dArgs) {
|
||||
LineDrawOp line = (LineDrawOp)dArgs.Op;
|
||||
line.WallsMode = dArgs.Mode == DrawMode.walls;
|
||||
if (parts.Length < 2 || dArgs.Mode == DrawMode.normal) return;
|
||||
|
||||
string arg = parts[parts.Length - 1];
|
||||
ushort len;
|
||||
if (ushort.TryParse(arg, out len))
|
||||
line.MaxLength = len;
|
||||
}
|
||||
|
||||
protected override DrawMode GetMode(string[] parts) {
|
||||
string mode = parts[parts.Length - 1];
|
||||
if (mode == "") return DrawMode.normal;
|
||||
@ -57,7 +46,16 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
|
||||
protected override DrawOp GetDrawOp(DrawArgs dArgs) {
|
||||
return new LineDrawOp();
|
||||
LineDrawOp line = new LineDrawOp();
|
||||
line.WallsMode = dArgs.Mode == DrawMode.walls;
|
||||
string msg = dArgs.Message;
|
||||
if (msg.IndexOf(' ') == -1 || dArgs.Mode == DrawMode.normal) return line;
|
||||
|
||||
string arg = msg.Substring(msg.LastIndexOf(' ') + 1);
|
||||
ushort len;
|
||||
if (ushort.TryParse(arg, out len))
|
||||
line.MaxLength = len;
|
||||
return line;
|
||||
}
|
||||
|
||||
protected override void GetMarks(DrawArgs dArgs, ref Vec3S32[] m) {
|
||||
|
@ -33,11 +33,17 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
DrawArgs dArgs = default(DrawArgs);
|
||||
dArgs.Message = message;
|
||||
dArgs.Player = p;
|
||||
dArgs.Mode = GetMode(parts);
|
||||
dArgs.Op = GetDrawOp(dArgs);
|
||||
if (dArgs.Op == null) return;
|
||||
|
||||
OnUse(p, message, parts, ref dArgs);
|
||||
// Validate the brush syntax is correct
|
||||
int offset = 0;
|
||||
BrushFactory factory = BrushFactory.Find(GetBrush(p, dArgs, ref offset));
|
||||
Brush brush = ParseBrush(p, dArgs, offset, factory);
|
||||
if (brush == null) return;
|
||||
|
||||
Player.Message(p, PlaceMessage);
|
||||
p.MakeSelection(MarksCount, dArgs, DoDraw);
|
||||
}
|
||||
@ -46,8 +52,6 @@ namespace MCGalaxy.Commands.Building {
|
||||
object state, byte block, byte extBlock) {
|
||||
DrawArgs dArgs = (DrawArgs)state;
|
||||
dArgs.Block = block; dArgs.ExtBlock = extBlock;
|
||||
dArgs.Player = p;
|
||||
|
||||
GetMarks(dArgs, ref marks);
|
||||
if (marks == null) return false;
|
||||
|
||||
@ -61,7 +65,9 @@ namespace MCGalaxy.Commands.Building {
|
||||
get { return "Place two blocks to determine the edges."; }
|
||||
}
|
||||
|
||||
protected virtual void OnUse(Player p, string msg, string[] parts, ref DrawArgs dArgs) { }
|
||||
protected virtual bool OnUse(Player p, string msg, string[] parts, ref DrawArgs dArgs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected virtual DrawMode GetMode(string[] parts) { return DrawMode.normal; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user