Skip to content

Commit

Permalink
Merge pull request #119 from xpenatan/work/kill-old-filesystem
Browse files Browse the repository at this point in the history
Kill old file system and update audio
  • Loading branch information
xpenatan authored Jul 6, 2024
2 parents 454c201 + acdce56 commit 1c3064f
Show file tree
Hide file tree
Showing 43 changed files with 784 additions and 2,840 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[1.0.0-SNAPSHOT]
- Update teavm to 0.10.0
- Pixmap now use Gdx2DPixmap
- Add useNewFileHandle set to true as default. Gdx.files.internal/classpath use new class to hold files and add IndexedDB support for Gdx.files.local
- New Gdx.files.internal, classpath and local implementation. Local files uses IndexedDB.
- Call dispose when browser closes
- Improve clipboard text copy/paste.
- Change default sound/music api to howler.js

[1.0.0-b9]
- add TeaClassFilter printAllowedClasses() and printExcludedClasses()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,19 @@ public boolean onSuccess(String url, Blob result) {
return false;
}
};
AssetDownloader.getInstance().load(true, url, AssetType.Image, null, listener);
AssetDownloader.getInstance().load(true, url, AssetType.Binary, null, listener);
}

public PixmapEmu(FileHandle file) {
TeaFileHandle webFileHandler = (TeaFileHandle)file;
String path = webFileHandler.path();

TeaApplicationConfiguration config = ((TeaApplication)Gdx.app).getConfig();
byte[] bytes = null;
if(config.useNewFileHandle) {
if(!file.exists()) {
// Add a way to debug when assets was not loaded in preloader.
throw new GdxRuntimeException("File is null, it does not exist: " + path);
}
bytes = file.readBytes();
}
else {
Blob object = webFileHandler.preloader.images.get(path);
if(object == null) {
// Add a way to debug when assets was not loaded in preloader.
throw new GdxRuntimeException("File is null, it does not exist: " + path);
}
Int8ArrayWrapper response = object.getData();
bytes = TypedArrays.toByteArray(response);
if(!file.exists()) {
// Add a way to debug when assets was not loaded in preloader.
throw new GdxRuntimeException("File is null, it does not exist: " + path);
}
byte[] bytes = file.readBytes();
nativePixmap = new Gdx2DPixmapEmu(bytes, 0, bytes.length, 0);
initPixmapEmu();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.github.xpenatan.gdx.backends.teavm.webaudio.WebAudioAPIManager;
import com.github.xpenatan.gdx.backends.teavm.webaudio.howler.HowlerAudioManager;

/**
* @author xpenatan
* Port from GWT gdx 1.12.0
*/
public class DefaultTeaAudio implements TeaAudio {
private WebAudioAPIManager webAudioAPIManager = null;
private HowlerAudioManager webAudioAPIManager = null;

public DefaultTeaAudio() {
webAudioAPIManager = new WebAudioAPIManager();
webAudioAPIManager = new HowlerAudioManager();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ else if(agentInfo.isLinux())
AssetLoaderListener<Object> assetListener = new AssetLoaderListener();

input = new TeaInput(this, graphics.canvas);
files = new TeaFiles(config, this, preloader);
files = new TeaFiles(config, this);
net = new TeaNet();
logger = new TeaApplicationLogger();
clipboard = new TeaClipboard();

initGdx();
initSound();

Gdx.app = this;
Gdx.graphics = graphics;
Expand Down Expand Up @@ -456,10 +457,6 @@ public void removeLifecycleListener(LifecycleListener listener) {
}
}

public String getAssetUrl() {
return preloader.getAssetUrl();
}

/** @return {@code true} if application runs on a mobile device */
public static boolean isMobileDevice () {
// RegEx pattern from detectmobilebrowsers.com (public domain)
Expand Down Expand Up @@ -489,4 +486,13 @@ public boolean onSuccess(String url, Object result) {
}
});
}

private void initSound() {
preloader.loadScript(true, "howler.js", new AssetLoaderListener<Object>() {
@Override
public boolean onSuccess(String url, Object result) {
return true;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ public class TeaApplicationConfiguration {
*/
public boolean preloadAssets = true;

/**
* Experimental new Gdx.files.internal and Gdx.files.local implementation
*/
@Deprecated
public boolean useNewFileHandle = true;

/**
* The prefix for the browser storage. If you have multiple apps on the same server and want to keep the
* data separate for those applications, you will need to set unique prefixes. This is useful if you are
Expand All @@ -35,7 +29,7 @@ public class TeaApplicationConfiguration {
* browser is not shared between the applications. If you leave the storage prefix at "", all the data
* and files stored will be shared between the applications.
*/
public String storagePrefix = "";
public String storagePrefix = "db/assets";

/**
* Show download logs.
Expand Down
Loading

0 comments on commit 1c3064f

Please sign in to comment.