All Downloads are FREE. Search and download functionalities are using the official Maven repository.

walkmc.ResourceLoader.kt Maven / Gradle / Ivy

package walkmc

import walkmc.annotation.*
import kotlin.reflect.full.*

/**
 * Represents a loader for [Resource].
 *
 * This has the ability to start/update/trigger resources in an easy way.
 */
interface ResourceLoader {
	
	/**
	 * All registered resources from this loader.
	 */
	val resources: MutableList>
	
	/**
	 * Gets a raw list of all registered resources processed by the resource processor.
	 */
	fun getRawResources(): List
	
	/**
	 * Recalculates the resources of this plugin.
	 */
	fun updateResources() {
		val raw = getRawResources()
		if (raw.isEmpty())
			return
		
		resources.clear()
		resources.addAll(
			raw.map {
				val clazz = classOf(it.className).kotlin
				val instance = clazz.objectInstance ?: clazz.createInstance()
				instance to it
			}
		)
	}
	
	/**
	 * Trigger's all resources to be called by the specified [load].
	 */
	fun triggerResource(load: Load) {
		for ((resource, _) in resources.sortedBy { it.second.priority }) {
			for (function in resource.getComponentsSorted(load)) {
				function.call(resource)
			}
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy