Search annotations in a specific package, add a MACROS category and a GREEN color

This commit is contained in:
Username404 2021-05-18 18:23:35 +02:00
parent 5713dc2c6b
commit 8f16eae53b
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
7 changed files with 14 additions and 9 deletions

View File

@ -55,7 +55,8 @@ subprojects {
flattenpackagehierarchy("$group.snowygui")
allowaccessmodification()
adaptclassstrings()
"$group.**".also { dontwarn(it); dontnote(it) }
dontnote("$group.**")
dontwarn("java.**")
val homeDir = System.getProperty("java.home") as String
libraryjars(configurations.compileClasspath.get().filter { file ->
listOf(

View File

@ -10,6 +10,8 @@ import org.apache.logging.log4j.Logger
abstract class Snowy {
private val displayInitMessage: Boolean by obtained
companion object {
@JvmStatic
protected val FeaturePackage: String = "fr.username404.snowygui.gui.feature"
lateinit var annotatedButtons: Set<Class<*>>
fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda)
@JvmField

View File

@ -37,7 +37,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
}
}
}
private val info = this::class.findAnnotation<ButtonInfo>() ?: throw Exception("Missing @Button annotaton")
private val info = this::class.findAnnotation<ButtonInfo>() ?: throw Exception("Missing @ButtonInfo annotaton")
override var color = info.parent.categoryColor
val title = this@ButtonImpl::class.simpleName
protected open fun execAction() = Unit

View File

@ -19,6 +19,7 @@ annotation class ButtonInfo(
}
}; enum class Category(val translationKey: String, val categoryColor: Colors) {
MISC("snowy.clickbox.misc", Colors.BLUE),
RISKY("snowy.clickbox.risky", Colors.RED);
RISKY("snowy.clickbox.risky", Colors.RED),
MACROS("snowy.clickbox.macros", Colors.GREEN);
init { ClickGui.components.add(ClickBox(y = 4.0, name = TranslatableComponent(translationKey), color = categoryColor)) }
}

View File

@ -5,5 +5,6 @@ enum class Colors(val hexValue: Int) {
BLACK(0x000000),
GOLD(0xe69500),
BLUE(0x6C9E9D),
RED(0x660000);
RED(0x660000),
GREEN(0x00FF7F)
}

View File

@ -26,7 +26,7 @@ class FabricInit: Snowy(), ClientModInitializer {
init {
annotatedButtons = Reflections(
ConfigurationBuilder()
.setUrls(ClasspathHelper.forClassLoader())
.setUrls(ClasspathHelper.forPackage(FeaturePackage))
.setScanners(SubTypesScanner(false), TypeAnnotationsScanner())
.useParallelExecutor()
).getTypesAnnotatedWith(ButtonInfo::class.java)

View File

@ -39,12 +39,12 @@ class ForgeInit: Snowy() {
.map { obj: ModFileScanData -> obj.classes }
.flatMap { obj: Set<ModFileScanData.ClassData?> -> obj.stream() }
.filter { data: ModFileScanData.ClassData? ->
(data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let {
if (it.contains("fr.username404") && !it.contains("mixins")) {
Class.forName(it).declaredAnnotations.any { annotation ->
(data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { classname ->
classname.startsWith(FeaturePackage).let {
it && Class.forName(classname).declaredAnnotations.any { annotation ->
annotation is ButtonInfo
}
} else false
}
}
}
.map { Class.forName((it!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(it) as Type).className) }