Use a Map instead of a list in AddKeyMaps.kt.

This commit is contained in:
Username404-59 2021-04-09 13:53:14 +02:00
parent 51662011b8
commit 42b48f7065
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 9 additions and 12 deletions

View File

@ -14,13 +14,11 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.io.File; import java.io.File;
import java.util.List; import java.util.*;
import java.util.Map;
import java.util.Optional;
@Mixin(Options.class) @Mixin(Options.class)
class KeyMappings { class KeyMappings {
private static final List<KeyMapping> keysToAdd = AddKeyMaps.INSTANCE.getList(); private static final Collection<KeyMapping> keysToAdd = AddKeyMaps.INSTANCE.getList().keySet();
@Mutable @Shadow @Final public KeyMapping[] keyMappings; @Mutable @Shadow @Final public KeyMapping[] keyMappings;

View File

@ -5,18 +5,17 @@ import net.minecraft.client.KeyMapping
import org.lwjgl.glfw.GLFW.GLFW_KEY_U import org.lwjgl.glfw.GLFW.GLFW_KEY_U
import org.lwjgl.glfw.GLFW.GLFW_KEY_Y import org.lwjgl.glfw.GLFW.GLFW_KEY_Y
private typealias privLambda = (() -> Unit)?
object AddKeyMaps { object AddKeyMaps {
private const val prefix = "snowy" private const val prefix = "snowy"
private fun mkMap(translationSuffix: String, key: Int, category: String = "keycategory"): KeyMapping { private fun mkMap(translationSuffix: String, key: Int, category: String = "keycategory", lambda: privLambda = null): Pair<KeyMapping, privLambda> {
return KeyMapping( return KeyMapping(
"key.$prefix.$translationSuffix", InputConstants.Type.KEYSYM, "key.$prefix.$translationSuffix", InputConstants.Type.KEYSYM,
key, "category.$prefix.$category" key, "category.$prefix.$category"
) ) to lambda
}
fun getList(): List<KeyMapping> {
return listOf(
mkMap("opengui", GLFW_KEY_Y),
mkMap("configkey", GLFW_KEY_U)
)
} }
val list: Map<KeyMapping, (() -> Unit)?> = mutableMapOf(
mkMap("opengui", GLFW_KEY_Y),
mkMap("configkey", GLFW_KEY_U)
)
} }