mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Fix being unable to do /transform scale 63/64
This commit is contained in:
parent
b2ce0de82e
commit
9000302f43
@ -16,10 +16,11 @@
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using MCGalaxy.Commands;
|
||||
using MCGalaxy.Commands.Building;
|
||||
|
||||
namespace MCGalaxy.Drawing.Transforms {
|
||||
public sealed class NoTransformFactory : TransformFactory {
|
||||
public sealed class NoTransformFactory : TransformFactory {
|
||||
public override string Name { get { return "None"; } }
|
||||
public override string[] Help { get { return HelpString; } }
|
||||
|
||||
@ -28,8 +29,8 @@ namespace MCGalaxy.Drawing.Transforms {
|
||||
"%HDoes not affect the output of draw operations.",
|
||||
};
|
||||
|
||||
public override Transform Construct(Player p, string message) {
|
||||
return NoTransform.Instance;
|
||||
public override Transform Construct(Player p, string message) {
|
||||
return NoTransform.Instance;
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,7 +43,7 @@ namespace MCGalaxy.Drawing.Transforms {
|
||||
"%TAlternatively: [scale] <centre>",
|
||||
"%H[scale] values can be an integer or a fraction (e.g. 2 or 1/2).",
|
||||
"%H[centre] if given, indicates to scale from the centre of a draw operation, " +
|
||||
"instead of outwards from the first mark. Recommended for cuboid and cylinder.",
|
||||
"instead of outwards from the first mark. Recommended for cuboid and cylinder.",
|
||||
};
|
||||
|
||||
public override Transform Construct(Player p, string message) {
|
||||
@ -51,16 +52,17 @@ namespace MCGalaxy.Drawing.Transforms {
|
||||
int mul = 0, div = 0;
|
||||
ScaleTransform scaler = new ScaleTransform();
|
||||
|
||||
if (!ParseFraction(p, args[0], out mul, out div)) return null;
|
||||
if (args.Length <= 2) {
|
||||
if (!ParseFraction(p, args[0], "Scale", out mul, out div)) return null;
|
||||
scaler.XMul = mul; scaler.XDiv = div;
|
||||
scaler.YMul = mul; scaler.YDiv = div;
|
||||
scaler.ZMul = mul; scaler.ZDiv = div;
|
||||
} else {
|
||||
if (!ParseFraction(p, args[0], "X scale", out mul, out div)) return null;
|
||||
scaler.XMul = mul; scaler.XDiv = div;
|
||||
if (!ParseFraction(p, args[1], out mul, out div)) return null;
|
||||
if (!ParseFraction(p, args[1], "Y scale", out mul, out div)) return null;
|
||||
scaler.YMul = mul; scaler.YDiv = div;
|
||||
if (!ParseFraction(p, args[2], out mul, out div)) return null;
|
||||
if (!ParseFraction(p, args[2], "Z scale", out mul, out div)) return null;
|
||||
scaler.ZMul = mul; scaler.ZDiv = div;
|
||||
}
|
||||
|
||||
@ -72,21 +74,22 @@ namespace MCGalaxy.Drawing.Transforms {
|
||||
return scaler;
|
||||
}
|
||||
|
||||
static bool ParseFraction(Player p, string input, out int mul, out int div) {
|
||||
static bool ParseFraction(Player p, string input, string argName, out int mul, out int div) {
|
||||
int sep = input.IndexOf('/');
|
||||
bool success = false;
|
||||
div = 1;
|
||||
div = 1; mul = 1;
|
||||
|
||||
if (sep == -1) { // single whole number
|
||||
success = int.TryParse(input, out mul);
|
||||
} else {
|
||||
string top = input.Substring(0, sep), bottom = input.Substring(sep + 1);
|
||||
success = int.TryParse(top, out mul) && int.TryParse(bottom, out div);
|
||||
return CommandParser.GetInt(p, input, argName, ref mul, -32, 32);
|
||||
}
|
||||
|
||||
if (mul > 32 || mul < -32) { Player.Message(p, "Scale must be between -32 and 32."); return false; }
|
||||
if (!success) { Player.MessageLines(p, HelpString); }
|
||||
return success;
|
||||
string top = input.Substring(0, sep), bottom = input.Substring(sep + 1);
|
||||
if (!CommandParser.GetInt(p, top, argName + " (numerator)", ref mul, -32768, 32768)) return false;
|
||||
if (!CommandParser.GetInt(p, bottom, argName + " (denominator)", ref div, -32768, 32768)) return false;
|
||||
|
||||
if (div == 0) { Player.Message(p, "Cannot divide by 0."); return false; }
|
||||
float fract = mul / (float)div;
|
||||
if (Math.Abs(fract) > 32) { Player.Message(p, argName + " must be between -32 and 32."); return false; }
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user