mirror of https://github.com/kami-blue/client
Have Macros store keycodes properly, and avoid unnecessary conversion
This commit is contained in:
parent
d1f88c08c3
commit
68603c2e6e
|
@ -36,7 +36,7 @@ class MacroCommand : Command("macro", ChunkBuilder().append("key|list").append("
|
|||
}
|
||||
sendChatMessage("You have the following macros: ")
|
||||
for ((key1, value) in Macros.macros) {
|
||||
sendRawChatMessage(Wrapper.getKeyName(key1.toInt()) + ": $value")
|
||||
sendRawChatMessage(Wrapper.getKeyName(key1) + ": $value")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class MacroCommand : Command("macro", ChunkBuilder().append("key|list").append("
|
|||
return
|
||||
}
|
||||
args[1] == "clear" -> {
|
||||
Macro.removeMacro(key.toString())
|
||||
Macro.removeMacro(key)
|
||||
MacroManager.saveMacros()
|
||||
MacroManager.registerMacros()
|
||||
sendChatMessage("Cleared macros for '&7$rKey&f'")
|
||||
|
@ -61,7 +61,7 @@ class MacroCommand : Command("macro", ChunkBuilder().append("key|list").append("
|
|||
return
|
||||
}
|
||||
else -> {
|
||||
Macro.addMacroToKey(key.toString(), macro)
|
||||
Macro.addMacroToKey(key, macro)
|
||||
MacroManager.saveMacros()
|
||||
sendChatMessage("Added macro '&7$macro&f' for key '&7$rKey&f'")
|
||||
}
|
||||
|
|
|
@ -13,5 +13,5 @@ public class Macros {
|
|||
* Map of all the macros.
|
||||
* KeyCode, Actions
|
||||
*/
|
||||
public static Map<String, List<String>> macros = new LinkedHashMap<>();
|
||||
public static Map<Integer, List<String>> macros = new LinkedHashMap<>();
|
||||
}
|
||||
|
|
|
@ -29,30 +29,30 @@ object Macro {
|
|||
|
||||
fun readFileToMemory() {
|
||||
try {
|
||||
Macros.macros = gson.fromJson(FileReader(file), object : TypeToken<HashMap<String?, List<String?>?>?>() {}.type)
|
||||
Macros.macros = gson.fromJson(FileReader(file), object : TypeToken<HashMap<Int?, List<String?>?>?>() {}.type)
|
||||
} catch (e: FileNotFoundException) {
|
||||
KamiMod.log.warn("Could not find file $configName, clearing the macros list")
|
||||
Macros.macros.clear()
|
||||
}
|
||||
}
|
||||
|
||||
fun getMacrosForKey(keyCode: Int): List<String?>? {
|
||||
fun getMacrosForKey(keycode: Int): List<String?>? {
|
||||
for ((key, value) in Macros.macros) {
|
||||
if (keyCode == key.toInt()) {
|
||||
if (keycode == key.toInt()) {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun addMacroToKey(keyCode: String?, macro: String?) {
|
||||
fun addMacroToKey(keycode: Int?, macro: String?) {
|
||||
if (macro == null) return // prevent trying to add a null macro
|
||||
Macros.macros.getOrPut(keyCode, ::mutableListOf).add(macro)
|
||||
Macros.macros.getOrPut(keycode, ::mutableListOf).add(macro)
|
||||
}
|
||||
|
||||
fun removeMacro(keyCode: String) {
|
||||
fun removeMacro(keycode: Int) {
|
||||
for (entry in Macros.macros.entries) {
|
||||
if (entry.key == keyCode) {
|
||||
if (entry.key == keycode) {
|
||||
entry.setValue(null)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue