raeleus / skin-composer

Create skins for LibGDX scene2d.ui with a graphical interface.
MIT License
431 stars 35 forks source link

TextraTypist Playground: Failed to parse number values (effect settings) #125

Closed H0k493 closed 1 year ago

H0k493 commented 2 years ago

Got following exception when try to play with effects

java.lang.RuntimeException: Actor: ImageButton: tt-button-up
    at com.badlogic.gdx.scenes.scene2d.Actor.notify(Actor.java:192)
    at com.badlogic.gdx.scenes.scene2d.Actor.fire(Actor.java:152)
    at com.badlogic.gdx.scenes.scene2d.ui.Button.setChecked(Button.java:125)
    at com.badlogic.gdx.scenes.scene2d.ui.Button$1.clicked(Button.java:93)
    at com.badlogic.gdx.scenes.scene2d.utils.ClickListener.touchUp(ClickListener.java:88)
    at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java:71)
    at com.badlogic.gdx.scenes.scene2d.Stage.touchUp(Stage.java:355)
    at com.badlogic.gdx.InputEventQueue.drain(InputEventQueue.java:70)
    at com.badlogic.gdx.backends.lwjgl3.DefaultLwjgl3Input.update(DefaultLwjgl3Input.java:189)
    at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:378)
    at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:192)
    at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:166)
    at com.ray3k.skincomposer.desktop.DesktopLauncher.main(DesktopLauncher.java:484)
Caused by: java.lang.NumberFormatException: For input string: "1,0"
    at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054)
    at java.base/jdk.internal.math.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
    at java.base/java.lang.Float.parseFloat(Float.java:455)
    at com.ray3k.skincomposer.dialog.textratypist.PopTextraEffects.lambda$createNumberField$27(PopTextraEffects.java:942)
    at com.ray3k.skincomposer.utils.Utils$1.changed(Utils.java:573)
    at com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.handle(ChangeListener.java:28)
    at com.badlogic.gdx.scenes.scene2d.Actor.notify(Actor.java:188)
    ... 12 more

In my locale delimeter for floating point is ',' instead of '.' Simple code snippet:

    public static void main(String[] args) {
        System.out.println("Default (current locale) " + Locale.getDefault().getCountry());
        System.out.println("Set DE locale - also have ',' as floating point delimeter (as example)");
        Locale.setDefault(Locale.GERMANY);
        String formattedNumber = String.format("%.1f", .1f);
        System.out.println("Formatting 0.1 (locale dependent) -> " + formattedNumber);
        System.out.println("Parsing locale dependent formatted floating number [" + formattedNumber + "] using default floating point parser");
        System.out.println(Float.parseFloat(formattedNumber));
    }

gave me following output:

Default (current locale) RU
Set DE locale - also have ',' as floating point delimeter (as example)
Formatting 0.1 (locale dependent) -> 0,1
Parsing locale dependent formatted floating number [0,1] using default floating point parser
Exception in thread "main" java.lang.NumberFormatException: For input string: "0,1"
    at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054)
    at java.base/jdk.internal.math.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
    at java.base/java.lang.Float.parseFloat(Float.java:455)
    at [REDACTED]

Possible quick solution: specify Locale.US when formatting floating numbers for number fields

Version: 52
raeleus commented 1 year ago

Thanks for the PR!