mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
More work towards parsing/serialising integers using invariant culture
This commit is contained in:
parent
c2efe55058
commit
f0f8ce9ab9
@ -256,11 +256,10 @@ namespace MCGalaxy.Commands.World {
|
||||
);
|
||||
|
||||
static void HandleMapPhysics(Player p, string message) {
|
||||
if (message == "0" || message == "1" || message == "2" || message == "3" || message == "4" || message == "5") {
|
||||
CmdPhysics.SetPhysics(p.level, int.Parse(message));
|
||||
} else {
|
||||
p.Message("Accepted numbers are: 0, 1, 2, 3, 4 or 5");
|
||||
}
|
||||
int level = 0;
|
||||
if (!CommandParser.GetInt(p, message, "Physics level", ref level, 0, 5)) return;
|
||||
|
||||
CmdPhysics.SetPhysics(p.level, level);
|
||||
}
|
||||
|
||||
static void HandleMapAdd(Player p, string message) {
|
||||
|
@ -31,8 +31,9 @@ namespace MCGalaxy.Commands.Misc {
|
||||
int TotalTime = 0;
|
||||
try
|
||||
{
|
||||
TotalTime = int.Parse(message.SplitSpaces()[0]);
|
||||
message = message.Substring(message.IndexOf(' ') + 1);
|
||||
string[] bits = message.SplitSpaces(2);
|
||||
TotalTime = int.Parse(bits[0]);
|
||||
message = bits[1];
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -43,6 +43,12 @@ namespace MCGalaxy.Config
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public override string Serialise(object value) {
|
||||
if (value is int) return NumberUtils.StringifyInt((int)value);
|
||||
|
||||
return base.Serialise(value);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ConfigIntAttribute : ConfigIntegerAttribute
|
||||
@ -120,6 +126,7 @@ namespace MCGalaxy.Config
|
||||
public override string Serialise(object value) {
|
||||
if (value is float) return NumberUtils.StringifyDouble((float)value);
|
||||
if (value is double) return NumberUtils.StringifyDouble((double)value);
|
||||
|
||||
return base.Serialise(value);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,8 @@ namespace MCGalaxy.Config {
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ConfigPermAttribute : ConfigAttribute {
|
||||
public sealed class ConfigPermAttribute : ConfigAttribute
|
||||
{
|
||||
LevelPermission defPerm;
|
||||
|
||||
public ConfigPermAttribute(string name, string section, LevelPermission def)
|
||||
@ -69,11 +70,12 @@ namespace MCGalaxy.Config {
|
||||
|
||||
public override string Serialise(object value) {
|
||||
LevelPermission perm = (LevelPermission)value;
|
||||
return ((sbyte)perm).ToString();
|
||||
return NumberUtils.StringifyInt((sbyte)perm);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ConfigEnumAttribute : ConfigAttribute {
|
||||
public sealed class ConfigEnumAttribute : ConfigAttribute
|
||||
{
|
||||
object defValue;
|
||||
Type enumType;
|
||||
|
||||
@ -93,7 +95,8 @@ namespace MCGalaxy.Config {
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ConfigVec3Attribute : ConfigAttribute {
|
||||
public sealed class ConfigVec3Attribute : ConfigAttribute
|
||||
{
|
||||
public ConfigVec3Attribute(string name, string section) : base(name, section) { }
|
||||
|
||||
public override object Parse(string raw) {
|
||||
@ -109,7 +112,8 @@ namespace MCGalaxy.Config {
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ConfigBoolArrayAttribute : ConfigAttribute {
|
||||
public sealed class ConfigBoolArrayAttribute : ConfigAttribute
|
||||
{
|
||||
bool defValue;
|
||||
int minCount;
|
||||
|
||||
|
@ -125,8 +125,9 @@ namespace MCGalaxy.Eco
|
||||
public int Price = 100;
|
||||
|
||||
public override void Parse(string prop, string value) {
|
||||
if (prop.CaselessEq("price"))
|
||||
Price = int.Parse(value);
|
||||
if (prop.CaselessEq("price")) {
|
||||
Price = NumberUtils.ParseInt32(value);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Serialise(List<string> cfg) {
|
||||
|
@ -49,7 +49,7 @@ namespace MCGalaxy
|
||||
if (num == -1) return "-1.0";
|
||||
|
||||
if (num == EnvConfig.ENV_USE_DEFAULT) num = -1;
|
||||
return num.ToString();
|
||||
return NumberUtils.StringifyInt(num);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ namespace MCGalaxy
|
||||
if (value == null) return defPerm;
|
||||
|
||||
sbyte perm;
|
||||
if (sbyte.TryParse(value, out perm))
|
||||
if (NumberUtils.TryParseInt8(value, out perm))
|
||||
return (LevelPermission)perm;
|
||||
|
||||
Group grp = Find(value);
|
||||
|
@ -52,6 +52,10 @@ namespace MCGalaxy
|
||||
return value.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static string StringifyInt(int value) {
|
||||
return value.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
|
||||
// Some languages don't have - as the negative sign symbol
|
||||
public static bool TryParseInt32(string s, out int result) {
|
||||
@ -61,5 +65,9 @@ namespace MCGalaxy
|
||||
public static int ParseInt32(string s) {
|
||||
return int.Parse(s, INTEGER_STYLE, NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
|
||||
public static bool TryParseInt8(string s, out sbyte result) {
|
||||
return sbyte.TryParse(s, INTEGER_STYLE, NumberFormatInfo.InvariantInfo, out result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user