From 5f77f8d2e0d4c30a263d1e4346cc32f105671cfa Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 26 Aug 2016 11:13:49 +1000 Subject: [PATCH] Create /transform, fix last commit always showing '0 blocks affected'. --- Commands/building/CmdBrush.cs | 2 +- Commands/building/CmdTransform.cs | 72 +++++++++++++++++++ Drawing/DrawOps/DrawOp.Performer.cs | 2 +- .../TransformFactories/SimpleTransforms.cs | 12 ++-- .../TransformFactories/TransformFactory.cs | 8 +-- MCGalaxy_.csproj | 1 + 6 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 Commands/building/CmdTransform.cs diff --git a/Commands/building/CmdBrush.cs b/Commands/building/CmdBrush.cs index edf592bc7..390262716 100644 --- a/Commands/building/CmdBrush.cs +++ b/Commands/building/CmdBrush.cs @@ -24,7 +24,7 @@ namespace MCGalaxy.Commands.Building { public override string name { get { return "brush"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Building; } } - public override bool museumUsable { get { return false; } } + public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("brushes", "list") }; } diff --git a/Commands/building/CmdTransform.cs b/Commands/building/CmdTransform.cs new file mode 100644 index 000000000..11c3c2d9d --- /dev/null +++ b/Commands/building/CmdTransform.cs @@ -0,0 +1,72 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + 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; +using MCGalaxy.Drawing.Transforms; + +namespace MCGalaxy.Commands.Building { + public sealed class CmdTransform : Command { + public override string name { get { return "transform"; } } + public override string shortcut { get { return ""; } } + public override string type { get { return CommandTypes.Building; } } + public override bool museumUsable { get { return true; } } + public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } + public override CommandAlias[] Aliases { + get { return new[] { new CommandAlias("transforms", "list"), new CommandAlias("scale", "scale") }; } + } + + public override void Use(Player p, string message) { + if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } + if (message == "") { + Player.Message(p, "Your current transform is: " + p.Transform.Name); return; + } + string[] args = message.SplitSpaces(2); + TransformFactory transform = TransformFactory.Find(args[0]); + + if (args[0].CaselessEq("list")) { + Player.Message(p, "%HAvailable transforms: %S" + TransformFactory.Available); + } else if (transform == null) { + Player.Message(p, "No transform found with name \"{0}\".", args[0]); + Player.Message(p, "Available transforms: " + TransformFactory.Available); + } else { + Player.Message(p, "Set your transform to: " + transform.Name); + Transform instance = transform.Construct(p, args.Length == 1 ? "" : args[1]); + if (instance == null) return; + p.Transform = instance; + } + } + + public override void Help(Player p) { + Player.Message(p, "%T/transform [name] "); + Player.Message(p, "%HSets your current transform to the transform with that name."); + Player.Message(p, "%T/help transform [name]"); + Player.Message(p, "%HOutputs the help for the transform with that name."); + Player.Message(p, "%HAvailable transform: %S" + TransformFactory.Available); + } + + public override void Help(Player p, string message) { + TransformFactory transform = TransformFactory.Find(message); + if (transform == null) { + Player.Message(p, "No transform found with name \"{0}\".", message); + Player.Message(p, "%HAvailable transforms: %S" + TransformFactory.Available); + } else { + Player.MessageLines(p, transform.Help); + } + } + } +} diff --git a/Drawing/DrawOps/DrawOp.Performer.cs b/Drawing/DrawOps/DrawOp.Performer.cs index db0dd3815..3221e8a67 100644 --- a/Drawing/DrawOps/DrawOp.Performer.cs +++ b/Drawing/DrawOps/DrawOp.Performer.cs @@ -52,7 +52,7 @@ namespace MCGalaxy.Drawing.Ops { return false; } - long affected = checkLimit ? 0L : op.GetBlocksAffected(op.Level, marks); + long affected = op.GetBlocksAffected(op.Level, marks); if (p != null && op.AffectedByTransform) p.Transform.GetBlocksAffected(ref affected); diff --git a/Drawing/TransformFactories/SimpleTransforms.cs b/Drawing/TransformFactories/SimpleTransforms.cs index 4af34f9ef..a1307f341 100644 --- a/Drawing/TransformFactories/SimpleTransforms.cs +++ b/Drawing/TransformFactories/SimpleTransforms.cs @@ -17,7 +17,6 @@ */ using System; using MCGalaxy.Commands.Building; -using MCGalaxy.Drawing.Brushes; namespace MCGalaxy.Drawing.Transforms { public sealed class NoTransformFactory : TransformFactory { @@ -29,9 +28,9 @@ namespace MCGalaxy.Drawing.Transforms { "%HDoes not affect the output of draw operations.", }; - public override Transform Construct(BrushArgs args) { return NoTransform.Instance; } - - public override bool Validate(BrushArgs args) { return true; } + public override Transform Construct(Player p, string message) { + return NoTransform.Instance; + } } public sealed class ScaleTransformFactory : TransformFactory { @@ -46,8 +45,9 @@ namespace MCGalaxy.Drawing.Transforms { "instead of outwards from the first mark. Recommended for cuboid and cylinder.", }; - public override Transform Construct(BrushArgs args) { - return NoTransform.Instance; + public override Transform Construct(Player p, string message) { +// TODO: actually parse the arguments + return new ScaleTransform() { XMul = 2, XDiv = 2, YMul = 1, YDiv = 2, ZMul = 2, ZDiv = 1 }; } } } diff --git a/Drawing/TransformFactories/TransformFactory.cs b/Drawing/TransformFactories/TransformFactory.cs index fdc6f6294..f0c483408 100644 --- a/Drawing/TransformFactories/TransformFactory.cs +++ b/Drawing/TransformFactories/TransformFactory.cs @@ -18,7 +18,6 @@ using System; using System.Collections.Generic; using MCGalaxy.Commands; -using MCGalaxy.Drawing.Brushes; using MCGalaxy.Drawing.Ops; namespace MCGalaxy.Drawing.Transforms { @@ -32,13 +31,10 @@ namespace MCGalaxy.Drawing.Transforms { /// Creates a transform from the given arguments, /// returning null if invalid arguments are specified. - public abstract Transform Construct(BrushArgs args); - - /// Validates the given arguments, returning false if they are invalid. - public virtual bool Validate(BrushArgs args) { return Construct(args) != null; } + public abstract Transform Construct(Player p, string message); public static List Transforms = new List() { - new NoTransformFactory(), + new NoTransformFactory(), new ScaleTransformFactory(), }; public static string Available { get { return Transforms.Join(b => b.Name); } } diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index faae03554..73e4bcc86 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -155,6 +155,7 @@ +