forked from libgdx/gdx-liftoff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextensions.kt
52 lines (46 loc) · 2.22 KB
/
extensions.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package gdx.liftoff.views
import com.badlogic.gdx.scenes.scene2d.ui.Button
import com.badlogic.gdx.utils.ObjectMap
import com.github.czyzby.autumn.annotation.Processor
import com.github.czyzby.autumn.context.Context
import com.github.czyzby.autumn.context.ContextDestroyer
import com.github.czyzby.autumn.context.ContextInitializer
import com.github.czyzby.autumn.processor.AbstractAnnotationProcessor
import com.github.czyzby.lml.annotation.LmlActor
import gdx.liftoff.config.inject
import gdx.liftoff.data.libraries.Library
/**
* Holds data about official and third-party extensions.
*/
@Processor
class ExtensionsData : AbstractAnnotationProcessor<Extension>() {
val extensionsById = mutableMapOf<String, Library>()
val official = mutableListOf<Library>()
val thirdParty = mutableListOf<Library>()
@LmlActor("\$officialExtensions") private val officialButtons: ObjectMap<String, Button> = inject()
@LmlActor("\$thirdPartyExtensions") private val thirdPartyButtons: ObjectMap<String, Button> = inject()
fun getSelectedOfficialExtensions(): Array<Library> = official.filter { officialButtons.get(it.id).isChecked }.toTypedArray()
fun getSelectedThirdPartyExtensions(): Array<Library> = thirdParty.filter { thirdPartyButtons.get(it.id).isChecked }.toTypedArray()
fun hasExtensionSelected(id: String): Boolean = (officialButtons.containsKey(id) && officialButtons.get(id).isChecked) || (thirdPartyButtons.containsKey(id) && thirdPartyButtons.get(id).isChecked)
// Automatic scanning of extensions:
override fun getSupportedAnnotationType(): Class<Extension> = Extension::class.java
override fun isSupportingTypes(): Boolean = true
override fun processType(
type: Class<*>,
annotation: Extension,
component: Any,
context: Context,
initializer: ContextInitializer,
contextDestroyer: ContextDestroyer
) {
val library = component as Library
if (annotation.official) { official } else { thirdParty }.add(library)
extensionsById[library.id] = library
}
}
/**
* Should annotate all third-party extensions.
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class Extension(val official: Boolean = false)