1515 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1616 */
1717
18- package com.lambda.core
18+ package com.lambda.core.loader
1919
2020import com.lambda.Lambda
2121import com.lambda.Lambda.LOG
22+ import com.lambda.graphics.renderer.gui.font.FontRenderer
2223import com.lambda.util.Communication.ascii
2324import com.lambda.util.reflections.getInstances
25+ import kotlin.reflect.full.findAnnotation
2426import kotlin.system.measureTimeMillis
2527import kotlin.time.DurationUnit
2628import kotlin.time.toDuration
@@ -31,16 +33,22 @@ object Loader {
3133 val runtime: String
3234 get() = " ${(System .currentTimeMillis() - started).toDuration(DurationUnit .MILLISECONDS )} "
3335
34- private val loadables = getInstances<Loadable > { forPackages(" com.lambda" ) }
36+ private val loadables =
37+ getInstances<Loadable > { forPackages(" com.lambda" ) }
38+ .associateWith { it::class .findAnnotation<LoaderOrder >() }
39+ .toList()
40+ .sortedBy { (_, annotation) -> annotation?.phase }
41+ .sortedByDescending { (_, annotation) -> annotation?.priority }
42+ .map { it.first }
3543
3644 fun initialize () {
3745 ascii.split(" \n " ).forEach { LOG .info(it) }
3846 LOG .info(" Initializing ${Lambda .MOD_NAME } ${Lambda .VERSION } " )
3947
40- val initTime = measureTimeMillis {
48+ val time = measureTimeMillis {
4149 loadables.forEach { LOG .info(it.load()) }
4250 }
4351
44- LOG .info(" ${Lambda .MOD_NAME } ${Lambda .VERSION } was successfully initialized ( ${initTime} ms) " )
52+ LOG .info(" ${Lambda .MOD_NAME } ${Lambda .VERSION } was successfully initialized in $time ms " )
4553 }
4654}
0 commit comments