package net.moonleay.gimble.client.keybindings

import net.fabricmc.fabric.impl.client.keybinding.KeyBindingRegistryImpl
import net.minecraft.client.MinecraftClient
import net.moonleay.gimble.client.keybindings.impl.GimbleShortcut

object KeybindingManager {

    private val shortcuts = mutableListOf<GimbleShortcut>()

    /**
     * Register a shortcut. This will also register the keybinding.
     * */
    fun registerShortcut(shortcut: GimbleShortcut) {
        shortcuts.add(shortcut)
        KeyBindingRegistryImpl.registerKeyBinding(shortcut.keyBinding)
    }

    fun onClientTick(client: MinecraftClient){
        // Sadly, this cannot be done without iterating over all shortcuts :madge:
        for (shortcut in shortcuts)
            if (shortcut.keyBinding.wasPressed())
                shortcut.onPressed(client)
    }
}
