blob: 9dfb38db3996046219af8a02e2395012973ef436 (
plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
package at.hannibal2.skyhanni.utils.repopatterns
import at.hannibal2.skyhanni.SkyHanniMod
import io.github.notenoughupdates.moulconfig.common.MyResourceLocation
import io.github.notenoughupdates.moulconfig.gui.GuiComponentWrapper
import io.github.notenoughupdates.moulconfig.gui.GuiContext
import io.github.notenoughupdates.moulconfig.observer.ObservableList
import io.github.notenoughupdates.moulconfig.xml.Bind
import io.github.notenoughupdates.moulconfig.xml.XMLUniverse
/**
* Gui for analyzing [RepoPattern]s
*/
class RepoPatternGui private constructor() {
companion object {
/**
* Open the [RepoPatternGui]
*/
fun open() {
SkyHanniMod.screenToOpen = GuiComponentWrapper(
GuiContext(
XMLUniverse.getDefaultUniverse()
.load(RepoPatternGui(), MyResourceLocation("skyhanni", "gui/regexes.xml"))
)
)
}
}
@field:Bind
var search: String = ""
private var lastSearch = null as String?
private val allKeys = RepoPatternManager.allPatterns.toList()
.sortedBy { it.key }
.map { RepoPatternInfo(it) }
private var searchCache = ObservableList(mutableListOf<RepoPatternInfo>())
class RepoPatternInfo(
repoPatternImpl: RepoPatternImpl,
) {
@field:Bind
val key: String = repoPatternImpl.key
@field:Bind
val regex: String = repoPatternImpl.value.pattern()
@field:Bind
val hoverRegex: List<String> = if (repoPatternImpl.isLoadedRemotely) {
listOf(
"§aLoaded remotely",
"§7Remote: " + repoPatternImpl.compiledPattern.pattern(),
"§7Local: " + repoPatternImpl.defaultPattern,
)
} else {
listOf("§cLoaded locally", "§7Local: " + repoPatternImpl.defaultPattern)
}
@field:Bind
val keyW = listOf(key)
@field:Bind
val overriden: String =
if (repoPatternImpl.wasOverridden) "§9Overriden"
else if (repoPatternImpl.isLoadedRemotely) "§aRemote"
else "§cLocal"
}
@Bind
fun poll(): String {
if (search != lastSearch) {
searchCache.clear()
searchCache.addAll(allKeys.filter { search in it.key })
lastSearch = search
}
return ""
}
@Bind
fun searchResults(): ObservableList<RepoPatternInfo> {
return searchCache
}
}
|