Skip to content

Commit

Permalink
add delay count in application
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed May 29, 2024
1 parent 12c5607 commit 565cb69
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.github.xpenatan.gdx.backends.teavm.dom.EventListenerWrapper;
import com.github.xpenatan.gdx.backends.teavm.dom.EventWrapper;
import com.github.xpenatan.gdx.backends.teavm.dom.impl.TeaWindow;
import com.github.xpenatan.gdx.backends.teavm.filesystem.FileDB;
import com.github.xpenatan.gdx.backends.teavm.preloader.AssetDownloadImpl;
import com.github.xpenatan.gdx.backends.teavm.preloader.AssetDownloader;
import com.github.xpenatan.gdx.backends.teavm.preloader.AssetDownloader.AssetDownload;
Expand All @@ -37,6 +38,8 @@ public class TeaApplication implements Application, Runnable {

private static TeaAgentInfo agentInfo;

public int delayInitCount;

public static TeaAgentInfo getAgentInfo() {
return agentInfo;
}
Expand All @@ -56,7 +59,7 @@ public static TeaApplication get() {
private final Array<LifecycleListener> lifecycleListeners = new Array<LifecycleListener>(4);
private TeaWindow window;

private AppState initState = AppState.LOAD_ASSETS;
private AppState initState = AppState.INIT;

private int lastWidth = -1;
private int lastHeight = 1;
Expand Down Expand Up @@ -162,8 +165,6 @@ public void handleEvent(EventWrapper evt) {
}
});

window.requestAnimationFrame(this);

if(config.isAutoSizeApplication()) {
window.addEventListener("resize", new EventListenerWrapper() {
@Override
Expand All @@ -188,13 +189,21 @@ public void handleEvent(EventWrapper evt) {
}
});
}

// Init database
FileDB.getInstance();
window.requestAnimationFrame(this);
}

@Override
public void run() {
AppState state = initState;
try {
switch(state) {
case INIT:
if(delayInitCount == 0) {
initState = AppState.LOAD_ASSETS;
}
case LOAD_ASSETS:
int queue = AssetDownloader.getInstance().getQueue();
if(queue == 0) {
Expand Down Expand Up @@ -448,6 +457,7 @@ public static boolean isMobileDevice () {
}

public enum AppState {
INIT,
LOAD_ASSETS,
APP_CREATE,
APP_LOOP
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.xpenatan.gdx.backends.teavm.filesystem;

import com.badlogic.gdx.Gdx;
import com.github.xpenatan.gdx.backends.teavm.TeaApplication;
import com.github.xpenatan.gdx.backends.teavm.TeaFileHandle;
import java.io.InputStream;
import org.teavm.jso.indexeddb.IDBDatabase;
Expand All @@ -8,65 +10,75 @@

public class IndexedDBStorage extends FileDB {

private IDBDatabase result = null;
private IDBDatabase dataBase = null;

public IndexedDBStorage() {

TeaApplication teaApplication = (TeaApplication)Gdx.app;
teaApplication.delayInitCount++;
IDBFactory instance = IDBFactory.getInstance();

IDBOpenDBRequest request = instance.open("TeaVM", 1);
request.setOnSuccess(() -> {
result = request.getResult();
dataBase = request.getResult();
System.out.println("SUCCESS");
teaApplication.delayInitCount--;
});

request.setOnError(() -> {
System.out.println("ERROR");
teaApplication.delayInitCount--;
});
}

@Override
public InputStream read(TeaFileHandle file) {

System.out.println("1111");
return null;
}

@Override
protected void writeInternal(TeaFileHandle file, byte[] data, boolean append, int expectedLength) {

System.out.println("2222");
}

@Override
protected String[] paths(TeaFileHandle file) {

System.out.println("3333");
return new String[0];
}

@Override
public boolean isDirectory(TeaFileHandle file) {
System.out.println("4444");
return false;
}

@Override
public void mkdirs(TeaFileHandle file) {

System.out.println("5555");
}

@Override
public boolean exists(TeaFileHandle file) {
System.out.println("6666");
return false;
}

@Override
public boolean delete(TeaFileHandle file) {
System.out.println("7777");
return false;
}

@Override
public long length(TeaFileHandle file) {
System.out.println("8888");
return 0;
}

@Override
public void rename(TeaFileHandle source, TeaFileHandle target) {

System.out.println("9999");
}
}

0 comments on commit 565cb69

Please sign in to comment.