package de.blight.editor;

import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;

/** Thread-safe Brücke: JavaFX-Events → JME3-Update-Schleife. */
public class SharedInput {

    // ── Kamerabewegung (WASD + QE) ──────────────────────────────────────────
    public volatile boolean forward, backward, left, right, up, down;

    // ── Kamerarotation (Maus-Drag mit mittlerer Taste) ───────────────────────
    private final AtomicInteger mouseDxAccum = new AtomicInteger();
    private final AtomicInteger mouseDyAccum = new AtomicInteger();

    public void addMouseDelta(int dx, int dy) {
        mouseDxAccum.addAndGet(dx);
        mouseDyAccum.addAndGet(dy);
    }

    /** Gibt akkumulierten Maus-Delta zurück und setzt ihn zurück. */
    public int[] consumeMouseDelta() {
        return new int[]{ mouseDxAccum.getAndSet(0), mouseDyAccum.getAndSet(0) };
    }

    // ── Terrain-Edits ────────────────────────────────────────────────────────
    public record TerrainEdit(float screenX, float screenY, int action) {}
    public final ConcurrentLinkedQueue<TerrainEdit> editQueue = new ConcurrentLinkedQueue<>();

    // ── Viewport-Skalierung (JavaFX-Pixel → JME3-Pixel) ─────────────────────
    public volatile double viewportScaleX = 1.0;
    public volatile double viewportScaleY = 1.0;
}
