How to locate and load custom file formats?

How do I build an AssetLocator and an AssetLoader to find and load a custom file format in my assets folder?

The file format contains information used by a WeaponControl class to calculate stuff like accuracy and fire rate. The information is in plain text so I can easily edit it by hand.

1 Like

Just implement AssetLoader from jME and register it to the Asset Manager like so:
getAssetManager().registerLoader(MyAwesomeAssetLoader.class, ".my extension");

After this you can just load the asset from the asset manager like you would any other asset like a model or a texture.

For example:

public class MyAwesomeAssetLoader implements AssetLoader {

    public final MyCustomFileFormatReader reader = new MyCustomFileFormatReader();

    @Override
    public Object load(AssetInfo assetInfo) throws IOException {
        return reader.load(assetInfo.openStream());
    }
}

AssetLocator you don’t probably need if your asset is just where you would have them normally. jME already offers a variety of locators to cater many needs.

2 Likes

And note: nothing requires you to use JME’s AssetManager to load your own files. You can also load and manage them like you would in any other application.

3 Likes