import { BC_CAMERA, BC_VIEWPORT } from "../GlobalVariables/GlobalVariables";
import { UICameraInfo } from "../UIPipes/UIPipes";

export function moveVertically(tick, keyCode) {
    BC_CAMERA.position.y += (tick.deltaMS / 1000) * 800 * (keyCode === "KeyS" ? 1 : -1);
    UICameraInfo.update((s) => {
        s.position.y = BC_CAMERA.position.y;
    });
}

export function moveHorizontally(tick, keyCode) {
    BC_CAMERA.position.x += (tick.deltaMS / 1000) * 800 * (keyCode === "KeyD" ? 1 : -1);
    UICameraInfo.update((s) => {
        s.position.x = BC_CAMERA.position.x;
    });
}

export function calculateViewportFromCamera() {
    // BC_VIEWPORT.pivot.set(0.5, 0.5);
    BC_VIEWPORT.position.set(
        Math.floor(((window.innerWidth / 2.0 / BC_CAMERA.zoom) - BC_CAMERA.position.x) * BC_CAMERA.zoom),
        Math.floor(((window.innerHeight / 2.0 / BC_CAMERA.zoom) - BC_CAMERA.position.y) * BC_CAMERA.zoom)
    );
    BC_VIEWPORT.scale.set(BC_CAMERA.zoom, BC_CAMERA.zoom);
}

/**
 * 
 * @param {Number} x 
 * @param {Number} y 
 */
export function screenToWorldCoordinates(x, y) {
    return {
        x: (((x - window.innerWidth / 2.0) / BC_CAMERA.zoom) + BC_CAMERA.position.x),
        y: (((y - window.innerHeight / 2.0) / BC_CAMERA.zoom) + BC_CAMERA.position.y)
    }
}