Skip to content

Commit

Permalink
Merge pull request #1 from jpooleycodes/develop
Browse files Browse the repository at this point in the history
Fix desktop support for runtime
  • Loading branch information
JamesTKhan authored Feb 4, 2022
2 parents 469a2e2 + d56c597 commit 0567bae
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.mbrlabs.mundus.commons.assets;

import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
Expand Down Expand Up @@ -157,11 +158,37 @@ public boolean accept(File file) {

final MetaLoader metaLoader = new MetaLoader();

FileHandle[] metaFiles;

if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
// Desktop applications cannot use .list() for internal jar files.
// Application will need to provide an assets.txt file listing all Mundus assets
// in the Mundus root directory.
// https://lyze.dev/2021/04/29/libGDX-Internal-Assets-List/
FileHandle fileList = rootFolder.child("assets.txt");
String[] files = fileList.readString().split("\\n");

// Get meta file extension file names
Array<String> metalFileNames = new Array<>();
for (String filename: files) {
if (filename.endsWith(Meta.META_EXTENSION)) {
metalFileNames.add(filename);
}
}

metaFiles = new FileHandle[metalFileNames.size];
for (int i = 0; i < metaFiles.length; i++) {
metaFiles[i] = rootFolder.child(metalFileNames.get(i));
}

} else {
metaFiles = rootFolder.list(metaFileFilter);
}

// load assets
FileHandle[] metaFiles = rootFolder.list(metaFileFilter);
for (FileHandle meta : metaFiles) {
Asset asset = loadAsset(metaLoader.load(meta));
if(listener != null) {
if (listener != null) {
listener.onLoad(asset, assets.size, metaFiles.length);
}
}
Expand Down
1 change: 1 addition & 0 deletions gdx-runtime/CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[0.2.0]
- Updated min java version to 1.7
- Add Desktop support by handling loading of assets without using FileHandle.list();

[0.1.0] ~ 12/8/2021
- First working implementation compatible with the v0.1.0 Mundus editor
5 changes: 5 additions & 0 deletions gdx-runtime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Desktop support
For the runtime to work on Desktop applications, an assets.txt file listing
all assets in the mundus/assets directory is required due to technical limitations
getting a list of files in a directory on Desktop. Guide for creating
assets.txt is here: https://lyze.dev/2021/04/29/libGDX-Internal-Assets-List/
9 changes: 5 additions & 4 deletions gdx-runtime/src/com/mbrlabs/mundus/runtime/Mundus.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,28 @@
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Disposable;
import com.mbrlabs.mundus.commons.Scene;
import com.mbrlabs.mundus.commons.assets.Asset;
import com.mbrlabs.mundus.commons.assets.AssetManager;

/**
* @author Marcus Brummer
* @version 27-10-2016
*/
public class Mundus implements Disposable {
public static final String PROJECT_ASSETS_DIR = "assets";
public static final String PROJECT_SCENES_DIR = "scenes";

private static final String TAG = Mundus.class.getSimpleName();

private SceneLoader sceneLoader;
private final SceneLoader sceneLoader;
private final AssetManager assetManager;
private final FileHandle root;

private Shaders shaders;

public Mundus(final FileHandle mundusRoot) {
this.root = mundusRoot;
this.assetManager = new AssetManager(root.child("assets"));
this.sceneLoader = new SceneLoader(this, root.child("scenes"));
this.assetManager = new AssetManager(root.child(PROJECT_ASSETS_DIR));
this.sceneLoader = new SceneLoader(this, root.child(PROJECT_SCENES_DIR));
}

public void init() {
Expand Down

0 comments on commit 0567bae

Please sign in to comment.