// by VienDesu! Poring Team 2023

function create_fps_button() {
    // Remove in release 
    const FPSBtn = document.createElement("div");
    FPSBtn.className = "fps-button";
    FPSBtn.id = "buttonF2";
    document.body.appendChild(FPSBtn);

    console.log(`Setting up the FPS key...`);

    FPSBtn.addEventListener("pointerdown", (event) => {
        console.log(`Pointer down for F2`); //Remove in release
        event.stopImmediatePropagation();
        event.preventDefault();
        sendEvent(false, 113);
    });

    FPSBtn.addEventListener("pointerup", () => {
        sendEvent(true, 113);
    });
}

function sendEvent(isUp, keycode) {
    document.getElementById("GameCanvas").focus();
    document.dispatchEvent(new KeyboardEvent(isUp ? 'keyup' : 'keydown', { 'key': '', keyCode: keycode }))
}

window.addEventListener('load', () => {
    create_fps_button(); // Remove in release 
});