rafaskb/typing-label

GWT Compatibility

Closed this issue ยท 10 comments

The Parser class is the problem here. I believe that both of these imports are not fully supported by libGDX GWT:

java.util.regex.Matcher;
java.util.regex.Pattern;

Specifically it complains about the Matcher class during GWT compile.

For my purposes, I just removed the Parser class from the library, and then it builds without a problem.

There are some libraries that are supposed to provide full regex functionality for GWT but I have not tried them myself. One of them is RegExodus

I can confirm that RegExodus works on GWT. I've used it to highlight syntax in LML online tutorial. SquidLib (roguelike utilities with LibGDX renderer) also depends on RegExodus and seems to work fine.

Oh it's good to know big libraries use that successfully, I checked RegExodus and it seems perfect, but there is a performance cost I'm a bit worried about, especially for Android. Did you have any issues with it so far?

On desktop platforms, this shouldn't be an issue. On GWT - it's not like you've got a viable choice. Unless you're making thousands of pattern checks each second, I wouldn't worry too much about mobile performance either.

Anyway, RegExodus was probably checked against the native implementation of a desktop JVM. I wouldn't be surprised if the mobile Pattern/Matcher implementations turn out just as fast as RegExodus. It would be best to perform a benchmark before worrying about the performance. Run some of your demos and see if profiling points to the regex checks as the bottleneck.

I had to edit your source to make it work with GWT.
First of all, I used RegExodus as both of you suggested.

Then, I changed lines 35 and 36 of TypingLabel (diamond notation):
before:
private final ObjectMap<String, String> variables = new ObjectMap<>();
protected final Array tokenEntries = new Array<>();
after:
private final ObjectMap<String, String> variables = new ObjectMap<String, String>();
protected final Array tokenEntries = new Array();

Finally, line 448 of TypingLabel (reflection)
before:
if (effectClass.isAssignableFrom(effect.getClass())) {
after:
if (ClassReflection.isAssignableFrom(effectClass.getClass(), effect.getClass())) {
I'm using libgdx v.1.9.8.

It works as expected.

Please make a PR.

Done

Hey thanks for putting your time into fixing this issue! I personally have never used the GWT backend while working with libGDX so I don't even know where to start from.

PR looks good! Are the reflection changes enough for the library to work with GWT or is RegExodus still necessary? And if that's the case could you please include the library in the PR as well? Thanks!

Hey, sorry for the delayed answer.
I didn't include RegExodus in your gradle file because it's not necessary if your library is used on Desktop/Android.
Only if you want to use TypingLabel on html5 libgdx projects, you should include RegExodus which is fully compatible with gwt rather than java.util.regex package.
But for TypingLabel, its usage is transparent.
Greetings!

BTW my PR doesn't affect anything. Your library will still working as well as before on Android, Desktop and now on HTML5.

Sounds good to me, I merged the PR to the base branch. Thanks again!