Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kill old file system and update audio #119

Merged
merged 11 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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