mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 17:43:08 -05:00
Core: Fix model scale not working when computer is set to a language that doesn't use . as its decimal point. (Thanks Daeslender)
This commit is contained in:
parent
390f3acd09
commit
0b7b5e3a83
4 changed files with 18 additions and 4 deletions
|
@ -95,12 +95,12 @@ namespace ClassicalSharp.Gui.Widgets {
|
|||
public override bool IsValidString( string s ) {
|
||||
float value;
|
||||
if( s.Length == 1 && IsValidChar( s[0] ) ) return true;
|
||||
return Single.TryParse( s, out value );
|
||||
return Utils.TryParseDecimal( s, out value );
|
||||
}
|
||||
|
||||
public override bool IsValidValue( string s ) {
|
||||
float value;
|
||||
if( !Single.TryParse( s, out value ) ) return false;
|
||||
if( !Utils.TryParseDecimal( s, out value ) ) return false;
|
||||
return min <= value && value <= max;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace ClassicalSharp.Entities {
|
|||
|
||||
string num = joined.Substring( start, end - start );
|
||||
float value = 0;
|
||||
if( !Single.TryParse( num, out value ) || value <= 0 ) return;
|
||||
if( !Utils.TryParseDecimal( num, out value ) || value <= 0 ) return;
|
||||
MaxSpeedMultiplier = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace ClassicalSharp.Entities {
|
|||
void ParseScale( string scale ) {
|
||||
if( scale == null ) return;
|
||||
float value;
|
||||
if( !float.TryParse( scale, out value ) || float.IsNaN( value ) )
|
||||
if( !Utils.TryParseDecimal( scale, out value ) )
|
||||
return;
|
||||
|
||||
Utils.Clamp( ref value, 0.25f, Model.MaxScale );
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using ClassicalSharp.Model;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
|
@ -187,5 +188,18 @@ namespace ClassicalSharp {
|
|||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// Not all languages use . as their decimal point separator
|
||||
public static bool TryParseDecimal( string s, out float result ) {
|
||||
result = 0;
|
||||
float temp;
|
||||
const NumberStyles style = NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite
|
||||
| NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint;
|
||||
|
||||
if( !Single.TryParse( s, style, NumberFormatInfo.InvariantInfo, out temp ) ) return false;
|
||||
if( Single.IsInfinity( temp ) || Single.IsNaN( temp ) ) return false;
|
||||
result = temp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue