mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -04:00
Create /transform, fix last commit always showing '0 blocks affected'.
This commit is contained in:
parent
122cb4999d
commit
5f77f8d2e0
@ -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") }; }
|
||||
|
72
Commands/building/CmdTransform.cs
Normal file
72
Commands/building/CmdTransform.cs
Normal file
@ -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] <transform args>");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
|
@ -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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
/// <summary> Creates a transform from the given arguments,
|
||||
/// returning null if invalid arguments are specified. </summary>
|
||||
public abstract Transform Construct(BrushArgs args);
|
||||
|
||||
/// <summary> Validates the given arguments, returning false if they are invalid. </summary>
|
||||
public virtual bool Validate(BrushArgs args) { return Construct(args) != null; }
|
||||
public abstract Transform Construct(Player p, string message);
|
||||
|
||||
public static List<TransformFactory> Transforms = new List<TransformFactory>() {
|
||||
new NoTransformFactory(),
|
||||
new NoTransformFactory(), new ScaleTransformFactory(),
|
||||
};
|
||||
|
||||
public static string Available { get { return Transforms.Join(b => b.Name); } }
|
||||
|
@ -155,6 +155,7 @@
|
||||
<Compile Include="Commands\building\CmdRedo.cs" />
|
||||
<Compile Include="Commands\building\CmdReplaceBrush.cs" />
|
||||
<Compile Include="Commands\building\CmdSphere.cs" />
|
||||
<Compile Include="Commands\building\CmdTransform.cs" />
|
||||
<Compile Include="Commands\building\CmdTriangle.cs" />
|
||||
<Compile Include="Commands\building\ReplaceCmd.cs" />
|
||||
<Compile Include="Commands\building\CmdRestartPhysics.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user