diff --git a/core/src/main/java/com/agifans/agile/HomeScreen.java b/core/src/main/java/com/agifans/agile/HomeScreen.java index d32c128..c8c04d2 100644 --- a/core/src/main/java/com/agifans/agile/HomeScreen.java +++ b/core/src/main/java/com/agifans/agile/HomeScreen.java @@ -107,13 +107,7 @@ public HomeScreen(Agile agile, DialogHandler dialogHandler) { this.agile = agile; this.dialogHandler = dialogHandler; - // Load the app meta data. - Json json = getJson(); - //String appConfigJson = Gdx.files.internal("data/games.json").readString(); - String appConfigJson = - json.prettyPrint(agile.getPreferences().getString(HOME_SCREEN_APP_LIST_PREF_NAME, DEFAULT_APP_CONFIG_JSON)); - agile.getPreferences().putString(HOME_SCREEN_APP_LIST_PREF_NAME, appConfigJson); - AppConfig appConfig = json.fromJson(AppConfig.class, appConfigJson); + AppConfig appConfig = loadAppConfig(); appConfigMap = new TreeMap(); for (AppConfigItem appConfigItem : appConfig.getApps()) { appConfigMap.put(appConfigItem.getName(), appConfigItem); @@ -146,6 +140,24 @@ public HomeScreen(Agile agile, DialogHandler dialogHandler) { landscapeInputProcessor.addProcessor(this); } + private AppConfig loadAppConfig() { + Json json = getJson(); + String appConfigJson = null; + if (agile.getPreferences().contains(HOME_SCREEN_APP_LIST_PREF_NAME)) { + appConfigJson = json.prettyPrint(agile.getPreferences().getString(HOME_SCREEN_APP_LIST_PREF_NAME)); + } else { + if (Gdx.app.getType().equals(ApplicationType.WebGL)) { + // First time use for web version, so load preconfigured file. + appConfigJson = Gdx.files.internal("data/games.json").readString(); + } else { + // Desktop currently empty to begin with. + appConfigJson = DEFAULT_APP_CONFIG_JSON; + } + } + agile.getPreferences().putString(HOME_SCREEN_APP_LIST_PREF_NAME, appConfigJson); + return json.fromJson(AppConfig.class, appConfigJson); + } + private Texture createWhitePixelTexture() { Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888); pixmap.setColor(1,1,1,1); diff --git a/html/src/main/java/com/agifans/agile/gwt/GwtGameLoader.java b/html/src/main/java/com/agifans/agile/gwt/GwtGameLoader.java index bda43c6..d951f10 100644 --- a/html/src/main/java/com/agifans/agile/gwt/GwtGameLoader.java +++ b/html/src/main/java/com/agifans/agile/gwt/GwtGameLoader.java @@ -33,30 +33,34 @@ public GwtGameLoader(PixelData pixelData) { @Override public void fetchGameFiles(String gameUri, Consumer> gameFilesConsumer) { - //Map gameFileMap = new HashMap<>(); - - opfsGameFiles.readGameFilesData(gameUri, new GwtOpenFileResultsHandler() { - @Override - public void onFileResultsReady(GwtOpenFileResult[] openFileResultArray) { - if (openFileResultArray.length == 1) { - GwtOpenFileResult openFileResult = openFileResultArray[0]; - Map gameFileMap = gameFileMapEncoder.decodeGameFileMap(openFileResult.getFileData()); - gameFilesConsumer.accept(gameFileMap); + if (gameUri.toLowerCase().endsWith(".zip")) { + // Must be a ZIP URL for one of the embedded fan made games. + Map gameFileMap = new HashMap<>(); + JSZip jsZip = JSZip.loadFile(gameUri); + JsArrayString files = jsZip.getFiles(); + + for (int i=0; i < files.length(); i++) { + String fileName = files.get(i); + if (isGameFile(fileName)) { + JSFile gameFile = jsZip.getFile(fileName); + gameFileMap.put(fileName.toLowerCase(), gameFile.asUint8Array().toByteArray()); } } - }); + + gameFilesConsumer.accept(gameFileMap); - /* TODO: Add back in when ZIP files are supported again. - JSZip jsZip = JSZip.loadFile(gameUri); - JsArrayString files = jsZip.getFiles(); - - for (int i=0; i < files.length(); i++) { - String fileName = files.get(i); - if (isGameFile(fileName)) { - JSFile gameFile = jsZip.getFile(fileName); - gameFileMap.put(fileName.toLowerCase(), gameFile.asUint8Array().toByteArray()); - } + } else { + // Otherwise, if it isn't a ZIP URL, then it must be in the OPFS. + opfsGameFiles.readGameFilesData(gameUri, new GwtOpenFileResultsHandler() { + @Override + public void onFileResultsReady(GwtOpenFileResult[] openFileResultArray) { + if (openFileResultArray.length == 1) { + GwtOpenFileResult openFileResult = openFileResultArray[0]; + Map gameFileMap = gameFileMapEncoder.decodeGameFileMap(openFileResult.getFileData()); + gameFilesConsumer.accept(gameFileMap); + } + } + }); } - */ } }