Update gdx-teavm to 1.5.0
This commit is contained in:
@@ -68,7 +68,9 @@ public class TextInput extends Component {
|
|||||||
viewport.setCamera(new OrthographicCamera());
|
viewport.setCamera(new OrthographicCamera());
|
||||||
//TODO this is needed for the moment as Spritebatch switched to using VAOs in libGDX v1.13.1
|
//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
|
// 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);
|
stage = new Stage(viewport);
|
||||||
Game.inputHandler.addInputProcessor(stage);
|
Game.inputHandler.addInputProcessor(stage);
|
||||||
|
|
||||||
@@ -141,13 +143,32 @@ public class TextInput extends Component {
|
|||||||
textField.setOnscreenKeyboard(new TextField.OnscreenKeyboard() {
|
textField.setOnscreenKeyboard(new TextField.OnscreenKeyboard() {
|
||||||
@Override
|
@Override
|
||||||
public void show(boolean visible) {
|
public void show(boolean visible) {
|
||||||
Game.platform.setOnscreenKeyboardVisible(visible, multiline);
|
if (!DeviceCompat.isWeb()) {
|
||||||
|
Game.platform.setOnscreenKeyboardVisible(visible, multiline);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
container.setActor(textField);
|
container.setActor(textField);
|
||||||
stage.setKeyboardFocus(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(){
|
public void enterPressed(){
|
||||||
@@ -258,7 +279,9 @@ public class TextInput extends Component {
|
|||||||
stage.dispose();
|
stage.dispose();
|
||||||
skin.dispose();
|
skin.dispose();
|
||||||
Game.inputHandler.removeInputProcessor(stage);
|
Game.inputHandler.removeInputProcessor(stage);
|
||||||
Game.platform.setOnscreenKeyboardVisible(false, false);
|
if (!DeviceCompat.isWeb()) {
|
||||||
|
Game.platform.setOnscreenKeyboardVisible(false, false);
|
||||||
|
}
|
||||||
if (!DeviceCompat.isDesktop()) Game.platform.updateSystemUI();
|
if (!DeviceCompat.isDesktop()) Game.platform.updateSystemUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ allprojects {
|
|||||||
gdxControllersVersion = '2.2.4'
|
gdxControllersVersion = '2.2.4'
|
||||||
robovmVersion = '2.3.24'
|
robovmVersion = '2.3.24'
|
||||||
|
|
||||||
gdxTeaVMVersion = '1.4.0'
|
gdxTeaVMVersion = '1.5.0'
|
||||||
teaVMVersion = '0.13.0'
|
teaVMVersion = '0.13.0'
|
||||||
}
|
}
|
||||||
version = appVersionName
|
version = appVersionName
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
apply plugin: 'java-library'
|
apply plugin: 'java-library'
|
||||||
|
|
||||||
dependencies {
|
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.github.xpenatan.gdx-teavm:gdx-freetype-teavm:$gdxTeaVMVersion"
|
||||||
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
|
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
|
||||||
implementation project(':core')
|
implementation project(':core')
|
||||||
|
|||||||
@@ -12,37 +12,48 @@
|
|||||||
* - Adjusted to compile Shattered Pixel Dungeon
|
* - Adjusted to compile Shattered Pixel Dungeon
|
||||||
* Modifications made by Konsthol on 27/9/25:
|
* Modifications made by Konsthol on 27/9/25:
|
||||||
* - Adjusted to be used with gdx-teavm 1.2.4
|
* - 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
|
* Copyright 2022 Daniel Hollingsworth
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.shatteredpixel.shatteredpixeldungeon.html;
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.teavm.tooling.TeaVMTool;
|
|
||||||
import org.teavm.vm.TeaVMOptimizationLevel;
|
import org.teavm.vm.TeaVMOptimizationLevel;
|
||||||
|
|
||||||
public class Compile {
|
public class Compile {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
File webappDir = new File("../release/webapp");
|
File webappDir = new File("../release");
|
||||||
Configure.deleteDir(webappDir);
|
deleteDir(webappDir);
|
||||||
Configure.configure();
|
|
||||||
|
|
||||||
TeaVMTool tool = new TeaVMTool();
|
new TeaCompiler(new WebBackend()
|
||||||
tool.setMainClass(TeaVMLauncher.class.getName());
|
.setWebAssembly(false)
|
||||||
tool.setOptimizationLevel(TeaVMOptimizationLevel.ADVANCED);
|
.setStartJettyAfterBuild(false))
|
||||||
tool.setObfuscated(true);
|
.addAssets(new AssetFileHandle("../core/src/main/assets"))
|
||||||
tool.setShortFileNames(true);
|
.addAssets(new AssetFileHandle("../html/src/main/assets"))
|
||||||
tool.setSourceFilesCopied(false);
|
.setMainClass(TeaVMLauncher.class.getName())
|
||||||
tool.setStrict(false);
|
.setOptimizationLevel(TeaVMOptimizationLevel.ADVANCED)
|
||||||
tool.setSourceMapsFileGenerated(false);
|
.setObfuscated(true)
|
||||||
tool.setDebugInformationGenerated(false);
|
.setSourceMapsFileGenerated(false)
|
||||||
tool.setIncremental(false);
|
.setDebugInformationGenerated(false)
|
||||||
|
.build(webappDir);
|
||||||
TeaBuilder.build(tool);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void deleteDir(File dir) {
|
||||||
|
File[] files = dir.listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
for (File file : files) {
|
||||||
|
deleteDir(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dir.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -22,12 +22,12 @@ import com.badlogic.gdx.utils.Align;
|
|||||||
import com.badlogic.gdx.utils.Scaling;
|
import com.badlogic.gdx.utils.Scaling;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||||
import com.github.xpenatan.gdx.backends.teavm.assetloader.AssetInstance;
|
import com.github.xpenatan.gdx.teavm.backends.web.assetloader.AssetInstance;
|
||||||
import com.github.xpenatan.gdx.backends.teavm.assetloader.AssetLoader;
|
import com.github.xpenatan.gdx.teavm.backends.web.assetloader.AssetLoader;
|
||||||
import com.github.xpenatan.gdx.backends.teavm.assetloader.AssetLoaderListener;
|
import com.github.xpenatan.gdx.teavm.backends.web.assetloader.AssetLoaderListener;
|
||||||
import com.github.xpenatan.gdx.backends.teavm.assetloader.AssetType;
|
import com.github.xpenatan.gdx.teavm.backends.web.assetloader.AssetType;
|
||||||
import com.github.xpenatan.gdx.backends.teavm.assetloader.TeaBlob;
|
import com.github.xpenatan.gdx.teavm.backends.web.assetloader.WebBlob;
|
||||||
import com.github.xpenatan.gdx.backends.teavm.TeaApplication;
|
import com.github.xpenatan.gdx.teavm.backends.web.WebApplication;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -42,11 +42,6 @@ import java.util.regex.Pattern;
|
|||||||
* Two-stage preload:
|
* Two-stage preload:
|
||||||
* - stage 1: sequentially load explicit frame list and build animation
|
* - stage 1: sequentially load explicit frame list and build animation
|
||||||
* - stage 2: preload assets.txt and show progress
|
* - 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 {
|
public class CustomPreloadScreen extends ApplicationAdapter {
|
||||||
|
|
||||||
@@ -86,8 +81,8 @@ public class CustomPreloadScreen extends ApplicationAdapter {
|
|||||||
private float barMaxWidth = 600f;
|
private float barMaxWidth = 600f;
|
||||||
private final float progressBoxHeight = 35f;
|
private final float progressBoxHeight = 35f;
|
||||||
private final float innerBarHeight = 20f;
|
private final float innerBarHeight = 20f;
|
||||||
private final float borderPadding = 4f; // keep border unchanged
|
private final float borderPadding = 4f;
|
||||||
private final float barInset = 8f; // increased inset so gray gap doubles
|
private final float barInset = 8f;
|
||||||
|
|
||||||
private Animation<TextureRegion> gifAnimation;
|
private Animation<TextureRegion> gifAnimation;
|
||||||
private TextureRegionDrawable gifDrawable;
|
private TextureRegionDrawable gifDrawable;
|
||||||
@@ -100,7 +95,7 @@ public class CustomPreloadScreen extends ApplicationAdapter {
|
|||||||
private float originalHeight = 128f;
|
private float originalHeight = 128f;
|
||||||
|
|
||||||
protected AssetLoader assetLoader;
|
protected AssetLoader assetLoader;
|
||||||
private TeaApplication teaApplication;
|
private WebApplication teaApplication;
|
||||||
private int initQueue = 0;
|
private int initQueue = 0;
|
||||||
private int assetsInitial = -1;
|
private int assetsInitial = -1;
|
||||||
private float displayedProgress = 0f;
|
private float displayedProgress = 0f;
|
||||||
@@ -113,7 +108,7 @@ public class CustomPreloadScreen extends ApplicationAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
teaApplication = TeaApplication.get();
|
teaApplication = WebApplication.get();
|
||||||
assetLoader = AssetInstance.getLoaderInstance();
|
assetLoader = AssetInstance.getLoaderInstance();
|
||||||
startLoadFrames(framesFolder, FIXED_FILENAMES);
|
startLoadFrames(framesFolder, FIXED_FILENAMES);
|
||||||
}
|
}
|
||||||
@@ -141,8 +136,8 @@ public class CustomPreloadScreen extends ApplicationAdapter {
|
|||||||
addQueue();
|
addQueue();
|
||||||
final String filename = names[idx];
|
final String filename = names[idx];
|
||||||
final String path = folder + "/" + filename;
|
final String path = folder + "/" + filename;
|
||||||
assetLoader.loadAsset(path, AssetType.Binary, Files.FileType.Internal, new AssetLoaderListener<TeaBlob>() {
|
assetLoader.loadAsset(path, AssetType.Binary, Files.FileType.Internal, new AssetLoaderListener<WebBlob>() {
|
||||||
public void onSuccess(String url, TeaBlob blob) {
|
public void onSuccess(String url, WebBlob blob) {
|
||||||
try {
|
try {
|
||||||
Texture tex = tryTextureFromInternal(path);
|
Texture tex = tryTextureFromInternal(path);
|
||||||
if (tex == null && blob != null) tex = tryTextureFromBlob(path, blob);
|
if (tex == null && blob != null) tex = tryTextureFromBlob(path, blob);
|
||||||
@@ -186,7 +181,7 @@ public class CustomPreloadScreen extends ApplicationAdapter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Texture tryTextureFromBlob(String path, TeaBlob blob) {
|
private Texture tryTextureFromBlob(String path, WebBlob blob) {
|
||||||
try {
|
try {
|
||||||
byte[] bytes = blobToBytes(blob);
|
byte[] bytes = blobToBytes(blob);
|
||||||
if (bytes != null && bytes.length > 0) {
|
if (bytes != null && bytes.length > 0) {
|
||||||
@@ -374,7 +369,7 @@ public class CustomPreloadScreen extends ApplicationAdapter {
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] blobToBytes(TeaBlob blob) {
|
private byte[] blobToBytes(WebBlob blob) {
|
||||||
if (blob == null) return null;
|
if (blob == null) return null;
|
||||||
String[] names = new String[] {"getBytes","getByteArray","toArray","getData","asArray"};
|
String[] names = new String[] {"getBytes","getByteArray","toArray","getData","asArray"};
|
||||||
for (String n : names) {
|
for (String n : names) {
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package com.shatteredpixel.shatteredpixeldungeon.html;
|
|||||||
import com.badlogic.gdx.Files;
|
import com.badlogic.gdx.Files;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||||
import com.github.xpenatan.gdx.backends.teavm.TeaApplicationConfiguration;
|
import com.github.xpenatan.gdx.teavm.backends.web.WebApplicationConfiguration;
|
||||||
import com.github.xpenatan.gdx.backends.teavm.TeaApplication;
|
import com.github.xpenatan.gdx.teavm.backends.web.WebApplication;
|
||||||
import com.watabou.utils.FileUtils;
|
import com.watabou.utils.FileUtils;
|
||||||
|
|
||||||
public class TeaVMLauncher {
|
public class TeaVMLauncher {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
TeaApplicationConfiguration config = new TeaApplicationConfiguration("canvas");
|
WebApplicationConfiguration config = new WebApplicationConfiguration("canvas");
|
||||||
config.width = 0;
|
config.width = 0;
|
||||||
config.height = 0;
|
config.height = 0;
|
||||||
config.useGL30 = true;
|
config.useGL30 = true;
|
||||||
@@ -31,10 +31,10 @@ public class TeaVMLauncher {
|
|||||||
|
|
||||||
platformSupport.setupClickListener();
|
platformSupport.setupClickListener();
|
||||||
|
|
||||||
new TeaApplication(new ShatteredPixelDungeon(platformSupport), new CustomPreloadScreen(), config);
|
new WebApplication(new ShatteredPixelDungeon(platformSupport), new CustomPreloadScreen(), config);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Error launching TeaApplication: " + e.getMessage());
|
System.err.println("Error launching WebApplication: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user