Update gdx-teavm to 1.5.0

This commit is contained in:
2026-02-14 16:41:48 +02:00
parent 2317b70a3b
commit 9e62656636
7 changed files with 76 additions and 102 deletions

View File

@@ -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')

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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<TextureRegion> 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<TeaBlob>() {
public void onSuccess(String url, TeaBlob blob) {
assetLoader.loadAsset(path, AssetType.Binary, Files.FileType.Internal, new AssetLoaderListener<WebBlob>() {
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) {

View File

@@ -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();
}
}