aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/macros/KeyComboTrie.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-06-04 18:45:39 +0200
committerLinnea Gräf <nea@nea.moe>2025-06-04 18:45:39 +0200
commit3695589a47c7434f4c5abbe2ebead052c0d07ba6 (patch)
treea42301bac4000cd1f4f6a10d16dfb5a779f12d97 /src/main/kotlin/features/macros/KeyComboTrie.kt
parent9c32c6e824058181002b0518e7e12c3425715b4b (diff)
downloadFirmament-3695589a47c7434f4c5abbe2ebead052c0d07ba6.tar.gz
Firmament-3695589a47c7434f4c5abbe2ebead052c0d07ba6.tar.bz2
Firmament-3695589a47c7434f4c5abbe2ebead052c0d07ba6.zip
feat: Add macro editing UI
Diffstat (limited to 'src/main/kotlin/features/macros/KeyComboTrie.kt')
-rw-r--r--src/main/kotlin/features/macros/KeyComboTrie.kt23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/main/kotlin/features/macros/KeyComboTrie.kt b/src/main/kotlin/features/macros/KeyComboTrie.kt
index 5c14bcd..57ff289 100644
--- a/src/main/kotlin/features/macros/KeyComboTrie.kt
+++ b/src/main/kotlin/features/macros/KeyComboTrie.kt
@@ -1,7 +1,9 @@
package moe.nea.firmament.features.macros
+import kotlinx.serialization.Serializable
import net.minecraft.text.Text
import moe.nea.firmament.keybindings.SavedKeyBinding
+import moe.nea.firmament.util.ErrorUtil
sealed interface KeyComboTrie {
val label: Text
@@ -13,19 +15,27 @@ sealed interface KeyComboTrie {
val root = Branch(mutableMapOf())
for (combo in combos) {
var p = root
- require(combo.keys.isNotEmpty())
+ if (combo.keys.isEmpty()) {
+ ErrorUtil.softUserError("Key Combo for ${combo.action.label.string} is empty")
+ continue
+ }
for ((index, key) in combo.keys.withIndex()) {
val m = (p.nodes as MutableMap)
if (index == combo.keys.lastIndex) {
- if (key in m)
- error("Overlapping actions found for ${combo.keys} (another action ${m[key]} already exists).")
+ if (key in m) {
+ ErrorUtil.softUserError("Overlapping actions found for ${combo.keys.joinToString(" > ")} (another action ${m[key]} already exists).")
+ break
+ }
m[key] = Leaf(combo.action)
} else {
val c = m.getOrPut(key) { Branch(mutableMapOf()) }
- if (c !is Branch)
- error("Overlapping actions found for ${combo.keys} (final node exists at index $index) through another action already")
- p = c
+ if (c !is Branch) {
+ ErrorUtil.softUserError("Overlapping actions found for ${combo.keys} (final node exists at index $index) through another action already")
+ break
+ } else {
+ p = c
+ }
}
}
}
@@ -35,6 +45,7 @@ sealed interface KeyComboTrie {
}
+@Serializable
data class ComboKeyAction(
val action: HotkeyAction,
val keys: List<SavedKeyBinding>,