mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
More usage of DrawCmd
This commit is contained in:
parent
dcce5f2f7f
commit
814278ba32
@ -51,12 +51,12 @@ namespace MCGalaxy.Commands.Building {
|
||||
return new CuboidDrawOp();
|
||||
}
|
||||
|
||||
protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
|
||||
protected override string GetBrush(DrawArgs dArgs, ref int offset) {
|
||||
offset = dArgs.Mode == DrawMode.normal ? 0 : 1;
|
||||
if (dArgs.Mode == DrawMode.solid) return "normal";
|
||||
if (dArgs.Mode == DrawMode.holes) return "checkered";
|
||||
if (dArgs.Mode == DrawMode.random) return "random";
|
||||
return p.BrushName;
|
||||
return dArgs.Player.BrushName;
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -91,9 +91,9 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
}
|
||||
|
||||
protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
|
||||
protected override string GetBrush(DrawArgs dArgs, ref int offset) {
|
||||
offset = ((AdvDrawOp)dArgs.Op).UsesHeight ? 3 : 2;
|
||||
return p.BrushName;
|
||||
return dArgs.Player.BrushName;
|
||||
}
|
||||
|
||||
bool CheckTwoArgs(Player p, ref int radius, ref int height, string[] parts) {
|
||||
|
@ -48,10 +48,10 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected override DrawOp GetDrawOp(DrawArgs dArg) { return new FillDrawOp(); }
|
||||
|
||||
protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
|
||||
protected override string GetBrush(DrawArgs dArgs, ref int offset) {
|
||||
offset = dArgs.Mode == DrawMode.normal ? 0 : 1;
|
||||
if (IsConfirmed(dArgs.Message)) offset++;
|
||||
return p.BrushName;
|
||||
return dArgs.Player.BrushName;
|
||||
}
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||
|
@ -16,35 +16,28 @@
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MCGalaxy.Drawing.Ops;
|
||||
using MCGalaxy.Maths;
|
||||
|
||||
namespace MCGalaxy.Commands.Building {
|
||||
public sealed class CmdHollow : Command {
|
||||
public sealed class CmdHollow : DrawCmd {
|
||||
public override string name { get { return "hollow"; } }
|
||||
public override string type { get { return CommandTypes.Building; } }
|
||||
public override bool museumUsable { get { return false; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } }
|
||||
public override bool SuperUseable { get { return false; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
protected override DrawOp GetDrawOp(DrawArgs dArgs) {
|
||||
byte skip = Block.Invalid;
|
||||
if (message != "") {
|
||||
skip = Block.Byte(message);
|
||||
if (skip == Block.Invalid) { Player.Message(p, "Cannot find block entered."); return; }
|
||||
if (dArgs.Message != "") {
|
||||
skip = Block.Byte(dArgs.Message);
|
||||
|
||||
if (skip == Block.Invalid) {
|
||||
Player.Message(dArgs.Player, "Cannot find block entered."); return null;
|
||||
}
|
||||
}
|
||||
|
||||
Player.Message(p, "Place or break two blocks to determine the edges.");
|
||||
p.MakeSelection(2, skip, DoHollow);
|
||||
|
||||
HollowDrawOp op = new HollowDrawOp();
|
||||
op.Skip = skip;
|
||||
return op;
|
||||
}
|
||||
|
||||
bool DoHollow(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||
HollowDrawOp op = new HollowDrawOp();
|
||||
op.Skip = (byte)state;
|
||||
DrawOpPerformer.Do(op, null, p, marks);
|
||||
return true;
|
||||
}
|
||||
protected override string GetBrush(DrawArgs dArgs, ref int offset) { return "normal"; }
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/hollow");
|
||||
|
@ -72,12 +72,12 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
}
|
||||
|
||||
protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
|
||||
protected override string GetBrush(DrawArgs dArgs, ref int offset) {
|
||||
LineDrawOp line = (LineDrawOp)dArgs.Op;
|
||||
offset = dArgs.Mode == DrawMode.normal ? 0 : 1;
|
||||
|
||||
if (line.MaxLength != int.MaxValue) offset++;
|
||||
return p.BrushName;
|
||||
return dArgs.Player.BrushName;
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -14,34 +14,26 @@
|
||||
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 System;
|
||||
using MCGalaxy.Drawing.Ops;
|
||||
using MCGalaxy.Maths;
|
||||
|
||||
namespace MCGalaxy.Commands.Building {
|
||||
public sealed class CmdMaze : Command {
|
||||
public sealed class CmdMaze : DrawCmd {
|
||||
public override string name { get { return "maze"; } }
|
||||
public override string type { get { return CommandTypes.Building; } }
|
||||
public override bool museumUsable { get { return false; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
||||
protected override DrawOp GetDrawOp(DrawArgs dArgs) {
|
||||
if (dArgs.Message == "") return new MazeDrawOp();
|
||||
int randomizer = 0;
|
||||
if (message.Length > 0 && !int.TryParse(message, out randomizer)) {
|
||||
Help(p); return;
|
||||
}
|
||||
if (!CommandParser.GetInt(dArgs.Player, dArgs.Message, "Randomizer", ref randomizer)) return null;
|
||||
|
||||
Player.Message(p, "Place or break two blocks to determine the edges.");
|
||||
p.MakeSelection(2, randomizer, DoMaze);
|
||||
MazeDrawOp op = new MazeDrawOp();
|
||||
op.randomizer = randomizer;
|
||||
return op;
|
||||
}
|
||||
|
||||
bool DoMaze(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||
MazeDrawOp op = new MazeDrawOp();
|
||||
op.randomizer = (int)state;
|
||||
DrawOpPerformer.Do(op, null, p, marks);
|
||||
return true;
|
||||
}
|
||||
protected override string GetBrush(DrawArgs dArgs, ref int offset) { return "normal"; }
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/maze");
|
||||
|
@ -14,51 +14,35 @@
|
||||
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 System;
|
||||
using MCGalaxy.Drawing.Brushes;
|
||||
using MCGalaxy.Drawing.Ops;
|
||||
using MCGalaxy.Maths;
|
||||
|
||||
namespace MCGalaxy.Commands.Building {
|
||||
public sealed class CmdOutline : Command {
|
||||
public sealed class CmdOutline : DrawCmd {
|
||||
public override string name { get { return "outline"; } }
|
||||
public override string type { get { return CommandTypes.Building; } }
|
||||
public override bool museumUsable { get { return false; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||
public override bool SuperUseable { get { return false; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] args = message.SplitSpaces(2);
|
||||
DrawArgs dArgs = default(DrawArgs);
|
||||
|
||||
protected override DrawOp GetDrawOp(DrawArgs dArgs) {
|
||||
if (dArgs.Message == "") {
|
||||
Player.Message(dArgs.Player, "Block name is required."); return null;
|
||||
}
|
||||
|
||||
if (!CommandParser.GetBlockIfAllowed(p, args[0], out dArgs.target)) return;
|
||||
string brushArgs = args.Length > 1 ? args[1] : "";
|
||||
dArgs.brushArgs = brushArgs;
|
||||
ExtBlock target;
|
||||
string[] parts = dArgs.Message.SplitSpaces(2);
|
||||
if (!CommandParser.GetBlockIfAllowed(dArgs.Player, parts[0], out target)) return null;
|
||||
|
||||
BrushFactory factory = BrushFactory.Find(p.BrushName);
|
||||
ExtBlock held = p.GetHeldBlock();
|
||||
BrushArgs bArgs = new BrushArgs(p, brushArgs, held);
|
||||
if (!factory.Validate(bArgs)) return;
|
||||
|
||||
Player.Message(p, "Place or break two blocks to determine the edges.");
|
||||
p.MakeSelection(2, dArgs, DoOutline);
|
||||
OutlineDrawOp op = new OutlineDrawOp();
|
||||
op.Target = target;
|
||||
return op;
|
||||
}
|
||||
|
||||
bool DoOutline(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||
DrawArgs dArgs = (DrawArgs)state;
|
||||
OutlineDrawOp op = new OutlineDrawOp();
|
||||
op.Target = dArgs.target;
|
||||
|
||||
BrushFactory factory = BrushFactory.Find(p.BrushName);
|
||||
BrushArgs bArgs = new BrushArgs(p, dArgs.brushArgs, block);
|
||||
Brush brush = factory.Construct(bArgs);
|
||||
if (brush == null) return false;
|
||||
|
||||
DrawOpPerformer.Do(op, brush, p, marks);
|
||||
return true;
|
||||
protected override string GetBrushArgs(DrawArgs dArgs, int usedFromEnd) {
|
||||
string[] parts = dArgs.Message.SplitSpaces(2);
|
||||
return parts.Length == 1 ? "" : parts[1];
|
||||
}
|
||||
struct DrawArgs { public ExtBlock target; public string brushArgs; }
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/outline [block] <brush args>");
|
||||
|
@ -20,26 +20,17 @@ using MCGalaxy.Drawing.Ops;
|
||||
using MCGalaxy.Maths;
|
||||
|
||||
namespace MCGalaxy.Commands.Building {
|
||||
public sealed class CmdRainbow : Command {
|
||||
public sealed class CmdRainbow : DrawCmd {
|
||||
public override string name { get { return "rainbow"; } }
|
||||
public override string type { get { return CommandTypes.Building; } }
|
||||
public override bool museumUsable { get { return false; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||
public override bool SuperUseable { get { return false; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
Player.Message(p, "Place or break two blocks to determine the edges.");
|
||||
p.MakeSelection(2, null, DoRainbow);
|
||||
}
|
||||
protected override DrawOp GetDrawOp(DrawArgs dArgs) { return new RainbowDrawOp(); }
|
||||
|
||||
bool DoRainbow(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||
DrawOpPerformer.Do(new RainbowDrawOp(), null, p, marks);
|
||||
return true;
|
||||
}
|
||||
protected override string GetBrush(DrawArgs dArgs, ref int offset) { return "normal"; }
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/rainbow");
|
||||
Player.Message(p, "%HTaste the rainbow");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -58,10 +58,10 @@ namespace MCGalaxy.Commands.Building {
|
||||
m[0] = p0 - radius; m[1] = p0 + radius;
|
||||
}
|
||||
|
||||
protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
|
||||
protected override string GetBrush(DrawArgs dArgs, ref int offset) {
|
||||
offset = dArgs.Mode == DrawMode.normal ? 0 : 1;
|
||||
if (dArgs.Mode == DrawMode.solid) return "normal";
|
||||
return p.BrushName;
|
||||
return dArgs.Player.BrushName;
|
||||
}
|
||||
|
||||
static Vec3S32 GetRadius(DrawMode mode, Vec3S32[] m) {
|
||||
|
@ -27,10 +27,10 @@ namespace MCGalaxy.Commands.Building {
|
||||
get { return new[] { new CommandAlias("eh", null, "hollow"), new CommandAlias("cylinder", null, "vertical") }; }
|
||||
}
|
||||
|
||||
protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
|
||||
protected override string GetBrush(DrawArgs dArgs, ref int offset) {
|
||||
offset = dArgs.Mode == DrawMode.normal ? 0 : 1;
|
||||
if (dArgs.Mode == DrawMode.solid) return "normal";
|
||||
return p.BrushName;
|
||||
return dArgs.Player.BrushName;
|
||||
}
|
||||
|
||||
protected override DrawMode GetMode(string[] parts) {
|
||||
|
@ -41,8 +41,10 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
// Validate the brush syntax is correct
|
||||
int offset = 0;
|
||||
BrushFactory factory = BrushFactory.Find(GetBrush(p, dArgs, ref offset));
|
||||
BrushArgs bArgs = GetBrushArgs(dArgs, offset);
|
||||
BrushFactory factory = BrushFactory.Find(GetBrush(dArgs, ref offset));
|
||||
|
||||
string brushArgs = GetBrushArgs(dArgs, offset);
|
||||
BrushArgs bArgs = new BrushArgs(p, brushArgs, dArgs.Block);
|
||||
if (!factory.Validate(bArgs)) return;
|
||||
|
||||
Player.Message(p, PlaceMessage);
|
||||
@ -56,8 +58,10 @@ namespace MCGalaxy.Commands.Building {
|
||||
if (marks == null) return false;
|
||||
|
||||
int offset = 0;
|
||||
BrushFactory factory = BrushFactory.Find(GetBrush(p, dArgs, ref offset));
|
||||
BrushArgs bArgs = GetBrushArgs(dArgs, offset);
|
||||
BrushFactory factory = BrushFactory.Find(GetBrush(dArgs, ref offset));
|
||||
|
||||
string brushArgs = GetBrushArgs(dArgs, offset);
|
||||
BrushArgs bArgs = new BrushArgs(p, brushArgs, dArgs.Block);
|
||||
Brush brush = factory.Construct(bArgs);
|
||||
if (brush == null) return false;
|
||||
|
||||
@ -76,12 +80,12 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected virtual void GetMarks(DrawArgs dArgs, ref Vec3S32[] m) { }
|
||||
|
||||
protected virtual string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
|
||||
protected virtual string GetBrush(DrawArgs dArgs, ref int offset) {
|
||||
offset = dArgs.Mode == DrawMode.normal ? 0 : 1;
|
||||
return p.BrushName;
|
||||
return dArgs.Player.BrushName;
|
||||
}
|
||||
|
||||
protected static BrushArgs GetBrushArgs(DrawArgs dArgs, int usedFromEnd) {
|
||||
protected virtual string GetBrushArgs(DrawArgs dArgs, int usedFromEnd) {
|
||||
int end = dArgs.Message.Length;
|
||||
string brushMsg = "";
|
||||
for (int i = 0; i < usedFromEnd; i++) {
|
||||
@ -91,7 +95,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
if (end >= 0) brushMsg = dArgs.Message.Substring(0, end);
|
||||
if (brushMsg == "") brushMsg = dArgs.Player.DefaultBrushArgs;
|
||||
return new BrushArgs(dArgs.Player, brushMsg, dArgs.Block);
|
||||
return brushMsg;
|
||||
}
|
||||
|
||||
protected struct DrawArgs {
|
||||
|
@ -21,35 +21,18 @@ using MCGalaxy.Drawing.Ops;
|
||||
using MCGalaxy.Maths;
|
||||
|
||||
namespace MCGalaxy.Commands.Building {
|
||||
public class CmdReplace : Command {
|
||||
public class CmdReplace : DrawCmd {
|
||||
public override string name { get { return "replace"; } }
|
||||
public override string shortcut { get { return "r"; } }
|
||||
public override string type { get { return CommandTypes.Building; } }
|
||||
public override bool museumUsable { get { return false; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||
protected virtual bool ReplaceNot { get { return false; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string brushMsg = message.ToLower();
|
||||
ExtBlock held = p.GetHeldBlock();
|
||||
|
||||
BrushArgs args = new BrushArgs(p, brushMsg, held);
|
||||
string name = ReplaceNot ? "replacenot" : "replace";
|
||||
if (!BrushFactory.Find(name).Validate(args)) return;
|
||||
|
||||
Player.Message(p, "Place or break two blocks to determine the edges.");
|
||||
p.MakeSelection(2, message.ToLower(), DoReplace);
|
||||
protected override DrawOp GetDrawOp(DrawArgs dArgs) {
|
||||
return new CuboidDrawOp();
|
||||
}
|
||||
|
||||
bool DoReplace(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||
BrushArgs args = new BrushArgs(p, (string)state, block);
|
||||
string name = ReplaceNot ? "replacenot" : "replace";
|
||||
Brush brush = BrushFactory.Find(name).Construct(args);
|
||||
if (brush == null) return false;
|
||||
|
||||
DrawOp op = new CuboidDrawOp();
|
||||
DrawOpPerformer.Do(op, brush, p, marks);
|
||||
return true;
|
||||
protected override string GetBrush(DrawArgs dArgs, ref int offset) {
|
||||
return ReplaceNot ? "replacenot" : "replace";
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user