#include "Zoom.h"
#include "Utils/MathUtils.h"
#include "Client.h"

auto Zoom::onGetFov(float* fov) -> void {
	static float animatedfov = 1.f;
	if (smooth)
		animatedfov = Utils::Math::animate(enabled ? amount - lerpamount : 1.f, animatedfov, Client::deltaTime * (smoothspeed * 10.f));
	else
		animatedfov = enabled ? amount - lerpamount : 1.f;

	*fov *= animatedfov;
}

auto Zoom::onMouse(char button, char action, bool* cancel) -> void {
	if (!enabled) return;

	if (button == 4) {
		if (static_cast<int>(action) == 120) {
			if ((lerpamount + 0.02f) <= amount) {
				if (smooth)
					lerpamount = Utils::Math::animate(lerpamount + 0.25f, lerpamount, Client::deltaTime * (smoothspeed * 10.f));
				else
					lerpamount += 0.25f;
			}
		}
		else {
			if (lerpamount >= -(1.f - amount)) {
				if (smooth)
					lerpamount = Utils::Math::animate(lerpamount - 0.25f, lerpamount, Client::deltaTime * (smoothspeed * 10.f));
				else
					lerpamount -= 0.25f;
			}
		}
		*cancel = true;
	}
}

auto Zoom::onClient() -> void {
	for (Setting* setting : Client::findSetting(this, _("Smooth"))) {
		if (setting->name == _("Smooth")) continue;

		setting->visible = smooth;
	}
}
