Package-level declarations

Types

Link copied to clipboard
interface Asset<out Type>

Common interface for asset wrappers. Provides access to an asset instance which might or might not be loaded.

Link copied to clipboard
abstract class AssetGroup(val manager: AssetManager, filePrefix: String = "")

A class for managing a group of assets together, such that they can be loaded or unloaded en masse. AssetGroup should be subclassed and the assets should be defined by properties in the subclass by using asset or, delayedAsset, which can be used as delegates. If not using delegates, it is possible to selectively load and unload them, in which case it is not advised to use loadAll and unloadAll, because AssetManager's reference counts may be thrown off.

Link copied to clipboard
class DelayedAsset<Type>(val manager: AssetManager, val assetDescriptor: AssetDescriptor<Type>) : Asset<Type>

Represents an Asset wrapper of resource loaded at demand. The first asset getter call causes the asset to be scheduled for loading and loaded eagerly - the AssetManager is updated until the asset is reported as loaded. Note that eager asset loading might cause other assets to be loaded synchronously rather than asynchronously, so it is advised to load eager assets with another AssetManager instance or use them after all regular assets are already loaded.

Link copied to clipboard

An implementation of DisposableRegistry that can be subclassed or used as a delegate. Allows to store and dispose of multiple Disposable instances.

Link copied to clipboard
interface DisposableRegistry : Disposable

Interface describing a container for Disposables that provides functions for disposing all its registered items. An implementing class's Disposable declarations can be tagged with .alsoRegister() to conveniently register them as they are instantiated and assigned.

Link copied to clipboard
class ManagedAsset<Type>(val manager: AssetManager, val assetDescriptor: AssetDescriptor<Type>) : Asset<Type>

Default implementation of Asset. Keeps asset data in an AssetDescriptor and delegates asset loading to an AssetManager. Assumes the asset was already scheduled for loading.

Link copied to clipboard
class TextAssetLoader(fileResolver: FileHandleResolver = InternalFileHandleResolver(), charset: String = "UTF-8") : AsynchronousAssetLoader<String, TextAssetLoader.TextAssetLoaderParameters>

Allows reading text files with an AssetManager. Must be registered via setLoader.

Functions

Link copied to clipboard
inline fun <Type : Any> assetDescriptor(file: FileHandle, parameters: AssetLoaderParameters<Type>? = null): AssetDescriptor<Type>
inline fun <Type : Any> assetDescriptor(path: String, parameters: AssetLoaderParameters<Type>? = null): AssetDescriptor<Type>

Allows to quickly prepare a typed AssetDescriptor instance with more Kotlin-friendly syntax.

Link copied to clipboard
fun <Asset : Disposable> Array<Asset>?.dispose(): Unit?

Allows to dispose a collection of resources implementing Disposable interface. Will silently ignore stored nulls. This method does not affect the Array structure in any way: no elements are removed from the array.

fun <Asset : Disposable> Iterable<Asset?>?.dispose(): Unit?

Allows to dispose a collection of resources implementing Disposable interface. Will silently ignore stored nulls. This method does not affect the Iterable structure in any way: no elements are removed from the collection.

inline fun Disposable?.dispose(onError: (Exception) -> Unit)

Allows to dispose a resource implementing Disposable interface. Will silently ignore nulls. Exceptions will be caught and passed to onError function. This is basically an alternative to try-catch block usage.

inline fun <Asset : Disposable> Array<Asset>?.dispose(onError: (Exception) -> Unit): Unit?

Allows to dispose a collection of resources implementing Disposable interface. Will silently ignore stored nulls. Exceptions during asset disposing will be caught and passed to onError function. This method does not affect the Array structure in any way: no elements are removed from the array.

inline fun <Asset : Disposable> Iterable<Asset?>?.dispose(onError: (Exception) -> Unit): Unit?

Allows to dispose a collection of resources implementing Disposable interface. Will silently ignore stored nulls. Exceptions during asset disposing will be caught and passed to onError function. This method does not affect the Iterable structure in any way: no elements are removed from the collection.

Link copied to clipboard
fun Disposable?.disposeSafely()

Allows to gracefully dispose a resource implementing Disposable interface. Will silently ignore nulls and exceptions (except for JVM internal Errors, which should not be caught anyway).

fun <Asset : Disposable> Array<Asset>?.disposeSafely(): Unit?

Allows to dispose a collection of resources implementing Disposable interface. Will silently ignore stored nulls and exceptions thrown during disposing (except for JVM internal Errors, which should not be caught anyway). This method does not affect the Array structure in any way: no elements are removed from the array.

fun <Asset : Disposable> Iterable<Asset?>?.disposeSafely(): Unit?

Allows to dispose a collection of resources implementing Disposable interface. Will silently ignore stored nulls and exceptions thrown during disposing (except for JVM internal Errors, which should not be caught anyway). This method does not affect the Iterable structure in any way: no elements are removed from the collection.

Link copied to clipboard
inline fun file(path: String, type: Files.FileType = Internal): FileHandle
Link copied to clipboard
fun FileHandleResolver.forResolutions(vararg resolutions: ResolutionFileResolver.Resolution): ResolutionFileResolver

Decorates this FileHandleResolver with a ResolutionFileResolver.

Link copied to clipboard
inline fun <Type : Any> AssetManager.getAsset(path: String): Type
Link copied to clipboard
inline fun <Type : Any> AssetManager.getLoader(suffix: String? = null): AssetLoader<Type, *>?

Utility for accessing AssetLoader instances stored by the AssetManager.

Link copied to clipboard
fun Files.FileType.getResolver(): FileHandleResolver

Creates a FileHandleResolver.

Link copied to clipboard
inline operator fun <Type> Asset<Type>.getValue(receiver: Any?, property: KProperty<*>): Type

Extension function that allows Asset instances to be delegates using the "by" keyword.

Link copied to clipboard
inline fun Throwable?.ignore()

This method does nothing. This is a null-safe call that allows to clearly mark an exception as ignored. This approach is preferred to an empty catch block, as at development time you can create custom ignore() methods for each specific Exception types, import them and pass some debugging or logging code to each implementation. For example:

Link copied to clipboard
operator fun <Type> Pool<Type>.invoke(): Type

Allows to use a Pool instance as a functional object. When invoked with no parameters, Pool will provide an instance of the pooled object type.

operator fun <Type> Pool<Type>.invoke(free: Type)

Allows to use a Pool instance as a functional object. When invoked with a parameter, Pool will treat the passed parameter as an object freed to the pool.

Link copied to clipboard
inline fun <Type : Any> AssetManager.load(path: String, parameters: AssetLoaderParameters<Type>? = null): Asset<Type>
Link copied to clipboard
Link copied to clipboard
inline fun <Type : Any> AssetManager.loadOnDemand(path: String, parameters: AssetLoaderParameters<Type>? = null): Asset<Type>
Link copied to clipboard
inline fun <Type> pool(initialCapacity: Int = 16, max: Int = Int.MAX_VALUE, crossinline discard: (Type) -> Unit = {}, crossinline provider: () -> Type): Pool<Type>
Link copied to clipboard
fun resolution(width: Int, height: Int, folder: String = "x"): ResolutionFileResolver.Resolution

Factory method for ResolutionFileResolver.Resolution that allows to used named parameters.

Link copied to clipboard
inline fun <Type : Any, Parameters : AssetLoaderParameters<Type>> AssetManager.setLoader(assetLoader: AssetLoader<Type, Parameters>, suffix: String? = null)
Link copied to clipboard
inline fun String?.toAbsoluteFile(): FileHandle
Link copied to clipboard
inline fun String?.toClasspathFile(): FileHandle
Link copied to clipboard
inline fun String?.toExternalFile(): FileHandle
Link copied to clipboard
inline fun String?.toInternalFile(): FileHandle
Link copied to clipboard
inline fun String?.toLocalFile(): FileHandle
Link copied to clipboard
inline fun AssetManager.unload(path: String, onError: (Exception) -> Unit)
Link copied to clipboard
Link copied to clipboard
fun FileHandleResolver.withPrefix(prefix: String): PrefixFileHandleResolver

Decorates this FileHandleResolver with a PrefixFileHandleResolver.