aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/macros/KeyComboTrie.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/features/macros/KeyComboTrie.kt')
-rw-r--r--src/main/kotlin/features/macros/KeyComboTrie.kt27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/main/kotlin/features/macros/KeyComboTrie.kt b/src/main/kotlin/features/macros/KeyComboTrie.kt
index 57ff289..2701ac1 100644
--- a/src/main/kotlin/features/macros/KeyComboTrie.kt
+++ b/src/main/kotlin/features/macros/KeyComboTrie.kt
@@ -1,12 +1,12 @@
package moe.nea.firmament.features.macros
import kotlinx.serialization.Serializable
-import net.minecraft.text.Text
+import net.minecraft.network.chat.Component
import moe.nea.firmament.keybindings.SavedKeyBinding
import moe.nea.firmament.util.ErrorUtil
sealed interface KeyComboTrie {
- val label: Text
+ val label: Component
companion object {
fun fromComboList(
@@ -15,15 +15,15 @@ sealed interface KeyComboTrie {
val root = Branch(mutableMapOf())
for (combo in combos) {
var p = root
- if (combo.keys.isEmpty()) {
+ if (combo.keySequence.isEmpty()) {
ErrorUtil.softUserError("Key Combo for ${combo.action.label.string} is empty")
continue
}
- for ((index, key) in combo.keys.withIndex()) {
+ for ((index, key) in combo.keySequence.withIndex()) {
val m = (p.nodes as MutableMap)
- if (index == combo.keys.lastIndex) {
+ if (index == combo.keySequence.lastIndex) {
if (key in m) {
- ErrorUtil.softUserError("Overlapping actions found for ${combo.keys.joinToString(" > ")} (another action ${m[key]} already exists).")
+ ErrorUtil.softUserError("Overlapping actions found for ${combo.keySequence.joinToString(" > ")} (another action ${m[key]} already exists).")
break
}
@@ -31,7 +31,7 @@ sealed interface KeyComboTrie {
} else {
val c = m.getOrPut(key) { Branch(mutableMapOf()) }
if (c !is Branch) {
- ErrorUtil.softUserError("Overlapping actions found for ${combo.keys} (final node exists at index $index) through another action already")
+ ErrorUtil.softUserError("Overlapping actions found for ${combo.keySequence} (final node exists at index $index) through another action already")
break
} else {
p = c
@@ -44,15 +44,20 @@ sealed interface KeyComboTrie {
}
}
+@Serializable
+data class MacroWheel(
+ val keyBinding: SavedKeyBinding = SavedKeyBinding.unbound(),
+ val options: List<HotkeyAction>
+)
@Serializable
data class ComboKeyAction(
val action: HotkeyAction,
- val keys: List<SavedKeyBinding>,
+ val keySequence: List<SavedKeyBinding> = listOf(),
)
data class Leaf(val action: HotkeyAction) : KeyComboTrie {
- override val label: Text
+ override val label: Component
get() = action.label
fun execute() {
@@ -63,6 +68,6 @@ data class Leaf(val action: HotkeyAction) : KeyComboTrie {
data class Branch(
val nodes: Map<SavedKeyBinding, KeyComboTrie>
) : KeyComboTrie {
- override val label: Text
- get() = Text.literal("...") // TODO: better labels
+ override val label: Component
+ get() = Component.literal("...") // TODO: better labels
}