package de.blight.game.config;

import com.jme3.input.KeyInput;

/** Speichert alle konfigurierbaren Tastenbelegungen als plain int-Felder (KeyInput-Codes). */
public class KeyBindings {

    public int forward  = KeyInput.KEY_W;
    public int backward = KeyInput.KEY_S;
    public int left     = KeyInput.KEY_A;
    public int right    = KeyInput.KEY_D;
    public int jump     = KeyInput.KEY_SPACE;
    public int sprint   = KeyInput.KEY_LSHIFT;

    /** Metadaten für die Config-UI: Feldname im Objekt + Anzeigename. */
    public static final String[][] ENTRIES = {
        {"forward",  "Vorwärts"},
        {"backward", "Rückwärts"},
        {"left",     "Links"},
        {"right",    "Rechts"},
        {"jump",     "Springen"},
        {"sprint",   "Rennen"},
    };

    public int get(String fieldName) {
        try { return (int) KeyBindings.class.getField(fieldName).get(this); }
        catch (Exception e) { return 0; }
    }

    public void set(String fieldName, int keyCode) {
        try { KeyBindings.class.getField(fieldName).setInt(this, keyCode); }
        catch (Exception ignored) {}
    }

    public KeyBindings copy() {
        KeyBindings c = new KeyBindings();
        for (String[] e : ENTRIES) c.set(e[0], get(e[0]));
        return c;
    }

    public void copyFrom(KeyBindings src) {
        for (String[] e : ENTRIES) set(e[0], src.get(e[0]));
    }
}
