mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 20:53:40 -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;
|
||||
|
@ -24,17 +24,6 @@ namespace MCGalaxy.Commands.Building {
|
||||
public override string name { get { return "line"; } }
|
||||
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];
|
||||
@ -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) {
|
||||
|
@ -14,13 +14,13 @@
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
*/
|
||||
using MCGalaxy.Drawing.Brushes;
|
||||
using MCGalaxy.Drawing.Ops;
|
||||
using System;
|
||||
|
||||
namespace MCGalaxy.Commands.Building {
|
||||
public abstract class DrawCmd : Command {
|
||||
namespace MCGalaxy.Commands.Building {
|
||||
public abstract class DrawCmd : Command {
|
||||
public override string type { get { return CommandTypes.Building; } }
|
||||
public override bool museumUsable { get { return false; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } }
|
||||
@ -33,21 +33,25 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
DrawArgs dArgs = default(DrawArgs);
|
||||
dArgs.Message = message;
|
||||
dArgs.Player = p;
|
||||
dArgs.Mode = GetMode(parts);
|
||||
dArgs.Op = GetDrawOp(dArgs);
|
||||
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);
|
||||
}
|
||||
|
||||
protected virtual bool DoDraw(Player p, Vec3S32[] marks,
|
||||
protected virtual bool DoDraw(Player p, Vec3S32[] marks,
|
||||
object state, byte block, byte extBlock) {
|
||||
DrawArgs dArgs = (DrawArgs)state;
|
||||
dArgs.Block = block; dArgs.ExtBlock = extBlock;
|
||||
dArgs.Player = p;
|
||||
|
||||
dArgs.Block = block; dArgs.ExtBlock = extBlock;
|
||||
GetMarks(dArgs, ref marks);
|
||||
if (marks == null) return false;
|
||||
|
||||
@ -57,11 +61,13 @@ namespace MCGalaxy.Commands.Building {
|
||||
return brush != null && DrawOp.DoDrawOp(dArgs.Op, brush, p, marks);
|
||||
}
|
||||
|
||||
protected virtual string PlaceMessage {
|
||||
get { return "Place two blocks to determine the edges."; }
|
||||
protected virtual string PlaceMessage {
|
||||
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; }
|
||||
@ -98,8 +104,8 @@ namespace MCGalaxy.Commands.Building {
|
||||
return block;
|
||||
}
|
||||
|
||||
protected static Brush ParseBrush(Player p, DrawArgs dArgs,
|
||||
int usedFromEnd, BrushFactory factory = null) {
|
||||
protected static Brush ParseBrush(Player p, DrawArgs dArgs,
|
||||
int usedFromEnd, BrushFactory factory = null) {
|
||||
int end = dArgs.Message.Length;
|
||||
string brushMsg = "";
|
||||
for (int i = 0; i < usedFromEnd; i++) {
|
||||
@ -116,7 +122,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected struct DrawArgs {
|
||||
public DrawMode Mode;
|
||||
public byte Block, ExtBlock;
|
||||
public byte Block, ExtBlock;
|
||||
public string Message;
|
||||
|
||||
public DrawOp Op;
|
||||
@ -126,11 +132,11 @@ namespace MCGalaxy.Commands.Building {
|
||||
protected enum DrawMode {
|
||||
normal, solid, hollow, walls,
|
||||
holes, wire, random,
|
||||
vertical, reverse, straight, // line
|
||||
vertical, reverse, straight, // line
|
||||
up, down, layer, verticalX, verticalZ, // fill
|
||||
cone, hcone, icone, hicone, volcano, // draw
|
||||
pyramid, hpyramid, ipyramid, hipyramid,// draw
|
||||
sphere, hsphere, circle, // draw
|
||||
sphere, hsphere, circle, // draw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user