From 9e6265663619bf1e0cb15795245a29e3e06dac30 Mon Sep 17 00:00:00 2001 From: konsthol Date: Sat, 14 Feb 2026 16:41:48 +0200 Subject: [PATCH] Update gdx-teavm to 1.5.0 --- .../java/com/watabou/noosa/TextInput.java | 31 +++++++++-- build.gradle | 2 +- html/build.gradle | 2 +- html/src/main/java/Compile.java | 45 +++++++++------ html/src/main/java/Configure.java | 55 ------------------- html/src/main/java/CustomPreloadScreen.java | 33 +++++------ html/src/main/java/TeaVMLauncher.java | 10 ++-- 7 files changed, 76 insertions(+), 102 deletions(-) delete mode 100644 html/src/main/java/Configure.java diff --git a/SPD-classes/src/main/java/com/watabou/noosa/TextInput.java b/SPD-classes/src/main/java/com/watabou/noosa/TextInput.java index 5d5673394..1b408df84 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/TextInput.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/TextInput.java @@ -68,7 +68,9 @@ public class TextInput extends Component { viewport.setCamera(new OrthographicCamera()); //TODO this is needed for the moment as Spritebatch switched to using VAOs in libGDX v1.13.1 // This results in HARD crashes atm, whereas old vertex arrays work fine - SpriteBatch.overrideVertexType = Mesh.VertexDataType.VertexArray; + if (!DeviceCompat.isWeb()) { + SpriteBatch.overrideVertexType = Mesh.VertexDataType.VertexArray; + } stage = new Stage(viewport); Game.inputHandler.addInputProcessor(stage); @@ -141,13 +143,32 @@ public class TextInput extends Component { textField.setOnscreenKeyboard(new TextField.OnscreenKeyboard() { @Override public void show(boolean visible) { - Game.platform.setOnscreenKeyboardVisible(visible, multiline); + if (!DeviceCompat.isWeb()) { + Game.platform.setOnscreenKeyboardVisible(visible, multiline); + } } }); container.setActor(textField); stage.setKeyboardFocus(textField); - Game.platform.setOnscreenKeyboardVisible(true, multiline); + if (!DeviceCompat.isWeb()) { + Game.platform.setOnscreenKeyboardVisible(true, multiline); + } + if (DeviceCompat.isWeb()) { + textField.addListener(new com.badlogic.gdx.scenes.scene2d.InputListener() { + private boolean opened = false; + + @Override + public boolean touchDown(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y, int pointer, int button) { + if (!opened) { + opened = true; + Game.platform.setOnscreenKeyboardVisible(true, textField instanceof TextArea); + stage.setKeyboardFocus(textField); + } + return false; + } + }); + } } public void enterPressed(){ @@ -258,7 +279,9 @@ public class TextInput extends Component { stage.dispose(); skin.dispose(); Game.inputHandler.removeInputProcessor(stage); - Game.platform.setOnscreenKeyboardVisible(false, false); + if (!DeviceCompat.isWeb()) { + Game.platform.setOnscreenKeyboardVisible(false, false); + } if (!DeviceCompat.isDesktop()) Game.platform.updateSystemUI(); } } diff --git a/build.gradle b/build.gradle index ce5204f63..9f151f2ca 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ allprojects { gdxControllersVersion = '2.2.4' robovmVersion = '2.3.24' - gdxTeaVMVersion = '1.4.0' + gdxTeaVMVersion = '1.5.0' teaVMVersion = '0.13.0' } version = appVersionName diff --git a/html/build.gradle b/html/build.gradle index 370f001e0..f4c121809 100644 --- a/html/build.gradle +++ b/html/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'java-library' dependencies { - implementation "com.github.xpenatan.gdx-teavm:backend-teavm:$gdxTeaVMVersion" + implementation "com.github.xpenatan.gdx-teavm:backend-web:$gdxTeaVMVersion" implementation "com.github.xpenatan.gdx-teavm:gdx-freetype-teavm:$gdxTeaVMVersion" implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" implementation project(':core') diff --git a/html/src/main/java/Compile.java b/html/src/main/java/Compile.java index 73a1e2087..d082b62a3 100644 --- a/html/src/main/java/Compile.java +++ b/html/src/main/java/Compile.java @@ -12,37 +12,48 @@ * - Adjusted to compile Shattered Pixel Dungeon * Modifications made by Konsthol on 27/9/25: * - Adjusted to be used with gdx-teavm 1.2.4 + * Modifications made by Konsthol on 7/2/25: + * - Adjusted to be used with gdx-teavm 1.5.0 * * Copyright 2022 Daniel Hollingsworth */ package com.shatteredpixel.shatteredpixeldungeon.html; -import com.github.xpenatan.gdx.backends.teavm.config.TeaBuilder; +import com.github.xpenatan.gdx.teavm.backends.shared.config.AssetFileHandle; +import com.github.xpenatan.gdx.teavm.backends.shared.config.compiler.TeaCompiler; +import com.github.xpenatan.gdx.teavm.backends.web.config.backend.WebBackend; + import java.io.File; import java.io.IOException; -import org.teavm.tooling.TeaVMTool; import org.teavm.vm.TeaVMOptimizationLevel; public class Compile { public static void main(String[] args) throws IOException { - File webappDir = new File("../release/webapp"); - Configure.deleteDir(webappDir); - Configure.configure(); + File webappDir = new File("../release"); + deleteDir(webappDir); - TeaVMTool tool = new TeaVMTool(); - tool.setMainClass(TeaVMLauncher.class.getName()); - tool.setOptimizationLevel(TeaVMOptimizationLevel.ADVANCED); - tool.setObfuscated(true); - tool.setShortFileNames(true); - tool.setSourceFilesCopied(false); - tool.setStrict(false); - tool.setSourceMapsFileGenerated(false); - tool.setDebugInformationGenerated(false); - tool.setIncremental(false); - - TeaBuilder.build(tool); + new TeaCompiler(new WebBackend() + .setWebAssembly(false) + .setStartJettyAfterBuild(false)) + .addAssets(new AssetFileHandle("../core/src/main/assets")) + .addAssets(new AssetFileHandle("../html/src/main/assets")) + .setMainClass(TeaVMLauncher.class.getName()) + .setOptimizationLevel(TeaVMOptimizationLevel.ADVANCED) + .setObfuscated(true) + .setSourceMapsFileGenerated(false) + .setDebugInformationGenerated(false) + .build(webappDir); } + private static void deleteDir(File dir) { + File[] files = dir.listFiles(); + if (files != null) { + for (File file : files) { + deleteDir(file); + } + } + dir.delete(); + } } diff --git a/html/src/main/java/Configure.java b/html/src/main/java/Configure.java deleted file mode 100644 index 191569a4b..000000000 --- a/html/src/main/java/Configure.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * This file is derived from micronaut-libgdx-teavm (https://github.com/hollingsworthd/micronaut-libgdx-teavm), - * originally licensed under the Apache License, Version 2.0. - * - * Modifications made by Konsthol on 13/4/25: - * - Adjusted to compile Shattered Pixel Dungeon - * Modifications made by Konsthol on 27/9/25: - * - Adjusted to be used with gdx-teavm 1.2.4 - * - * Copyright 2022 Daniel Hollingsworth - */ - -package com.shatteredpixel.shatteredpixeldungeon.html; - -import com.github.xpenatan.gdx.backends.teavm.config.AssetFileHandle; -import com.github.xpenatan.gdx.backends.teavm.config.TeaBuildConfiguration; -import com.github.xpenatan.gdx.backends.teavm.config.TeaBuilder; -import java.io.File; -import java.io.IOException; -import org.teavm.tooling.TeaVMTool; -import org.teavm.tooling.TeaVMTargetType; -import org.teavm.vm.TeaVMOptimizationLevel; - -public class Configure { - - public static void main(String[] args) {} - - public static void deleteDir(File dir) { - File[] files = dir.listFiles(); - if (files != null) { - for (File file : files) { - deleteDir(file); - } - } - dir.delete(); - } - - public static void configure() throws IOException { - TeaBuildConfiguration conf = new TeaBuildConfiguration(); - conf.assetsPath.add(new AssetFileHandle("../core/src/main/assets")); - conf.assetsPath.add(new AssetFileHandle("../html/src/main/assets")); - conf.shouldGenerateAssetFile = true; - conf.webappPath = new File("../release").getAbsolutePath(); - conf.targetType = TeaVMTargetType.JAVASCRIPT; - //conf.targetType = TeaVMTargetType.WEBASSEMBLY; - TeaBuilder.config(conf); - } - -} diff --git a/html/src/main/java/CustomPreloadScreen.java b/html/src/main/java/CustomPreloadScreen.java index 2dd47d696..baf378e8a 100644 --- a/html/src/main/java/CustomPreloadScreen.java +++ b/html/src/main/java/CustomPreloadScreen.java @@ -22,12 +22,12 @@ import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Scaling; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.viewport.ScreenViewport; -import com.github.xpenatan.gdx.backends.teavm.assetloader.AssetInstance; -import com.github.xpenatan.gdx.backends.teavm.assetloader.AssetLoader; -import com.github.xpenatan.gdx.backends.teavm.assetloader.AssetLoaderListener; -import com.github.xpenatan.gdx.backends.teavm.assetloader.AssetType; -import com.github.xpenatan.gdx.backends.teavm.assetloader.TeaBlob; -import com.github.xpenatan.gdx.backends.teavm.TeaApplication; +import com.github.xpenatan.gdx.teavm.backends.web.assetloader.AssetInstance; +import com.github.xpenatan.gdx.teavm.backends.web.assetloader.AssetLoader; +import com.github.xpenatan.gdx.teavm.backends.web.assetloader.AssetLoaderListener; +import com.github.xpenatan.gdx.teavm.backends.web.assetloader.AssetType; +import com.github.xpenatan.gdx.teavm.backends.web.assetloader.WebBlob; +import com.github.xpenatan.gdx.teavm.backends.web.WebApplication; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; @@ -42,11 +42,6 @@ import java.util.regex.Pattern; * Two-stage preload: * - stage 1: sequentially load explicit frame list and build animation * - stage 2: preload assets.txt and show progress - * - * This variant keeps the border unchanged and reduces the inner progress bar height - * by barInset at top and bottom so the gray gap between the white border and the green fill - * appears larger. The fills are laid out using the computed innerHeight and the table - * is invalidated/validated so the change is applied immediately. */ public class CustomPreloadScreen extends ApplicationAdapter { @@ -86,8 +81,8 @@ public class CustomPreloadScreen extends ApplicationAdapter { private float barMaxWidth = 600f; private final float progressBoxHeight = 35f; private final float innerBarHeight = 20f; - private final float borderPadding = 4f; // keep border unchanged - private final float barInset = 8f; // increased inset so gray gap doubles + private final float borderPadding = 4f; + private final float barInset = 8f; private Animation gifAnimation; private TextureRegionDrawable gifDrawable; @@ -100,7 +95,7 @@ public class CustomPreloadScreen extends ApplicationAdapter { private float originalHeight = 128f; protected AssetLoader assetLoader; - private TeaApplication teaApplication; + private WebApplication teaApplication; private int initQueue = 0; private int assetsInitial = -1; private float displayedProgress = 0f; @@ -113,7 +108,7 @@ public class CustomPreloadScreen extends ApplicationAdapter { @Override public void create() { - teaApplication = TeaApplication.get(); + teaApplication = WebApplication.get(); assetLoader = AssetInstance.getLoaderInstance(); startLoadFrames(framesFolder, FIXED_FILENAMES); } @@ -141,8 +136,8 @@ public class CustomPreloadScreen extends ApplicationAdapter { addQueue(); final String filename = names[idx]; final String path = folder + "/" + filename; - assetLoader.loadAsset(path, AssetType.Binary, Files.FileType.Internal, new AssetLoaderListener() { - public void onSuccess(String url, TeaBlob blob) { + assetLoader.loadAsset(path, AssetType.Binary, Files.FileType.Internal, new AssetLoaderListener() { + public void onSuccess(String url, WebBlob blob) { try { Texture tex = tryTextureFromInternal(path); if (tex == null && blob != null) tex = tryTextureFromBlob(path, blob); @@ -186,7 +181,7 @@ public class CustomPreloadScreen extends ApplicationAdapter { return null; } - private Texture tryTextureFromBlob(String path, TeaBlob blob) { + private Texture tryTextureFromBlob(String path, WebBlob blob) { try { byte[] bytes = blobToBytes(blob); if (bytes != null && bytes.length > 0) { @@ -374,7 +369,7 @@ public class CustomPreloadScreen extends ApplicationAdapter { return t; } - private byte[] blobToBytes(TeaBlob blob) { + private byte[] blobToBytes(WebBlob blob) { if (blob == null) return null; String[] names = new String[] {"getBytes","getByteArray","toArray","getData","asArray"}; for (String n : names) { diff --git a/html/src/main/java/TeaVMLauncher.java b/html/src/main/java/TeaVMLauncher.java index ba8398bb8..abefc9f3d 100644 --- a/html/src/main/java/TeaVMLauncher.java +++ b/html/src/main/java/TeaVMLauncher.java @@ -3,14 +3,14 @@ package com.shatteredpixel.shatteredpixeldungeon.html; import com.badlogic.gdx.Files; import com.watabou.noosa.Game; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; -import com.github.xpenatan.gdx.backends.teavm.TeaApplicationConfiguration; -import com.github.xpenatan.gdx.backends.teavm.TeaApplication; +import com.github.xpenatan.gdx.teavm.backends.web.WebApplicationConfiguration; +import com.github.xpenatan.gdx.teavm.backends.web.WebApplication; import com.watabou.utils.FileUtils; public class TeaVMLauncher { public static void main(String[] args) { - TeaApplicationConfiguration config = new TeaApplicationConfiguration("canvas"); + WebApplicationConfiguration config = new WebApplicationConfiguration("canvas"); config.width = 0; config.height = 0; config.useGL30 = true; @@ -31,10 +31,10 @@ public class TeaVMLauncher { platformSupport.setupClickListener(); - new TeaApplication(new ShatteredPixelDungeon(platformSupport), new CustomPreloadScreen(), config); + new WebApplication(new ShatteredPixelDungeon(platformSupport), new CustomPreloadScreen(), config); } catch (Exception e) { - System.err.println("Error launching TeaApplication: " + e.getMessage()); + System.err.println("Error launching WebApplication: " + e.getMessage()); e.printStackTrace(); } }