#include "Ambience.h"
#include "Client.h"

auto Ambience::onWorldTick(Player* _this) -> void {
	auto clientinstance = Client::clientinstance;
	if (!clientinstance) return;

	auto blocksource = clientinstance->getBlockSource();
	if (!blocksource) return;

	auto dimension = blocksource->getDimension();
	if (!dimension) return;

	auto weather = dimension->getWeather();
	if (!weather) return;

	switch (this->weather) {
	case 0:
		if (old != -1.f) {
			weather->setRain(old);

			old = -1.f;
		}
		break;
	case 1:
		if (old == -1.f) {
			old = weather->getRain();
		}
		weather->setRain(0.f);
		break;
	case 2:
		if (old == -1.f) {
			old = weather->getRain();
		}
		weather->setRain(1.f);
		break;
	}
}

auto Ambience::onGetTime(float* time) -> void {
	*time = this->time / 2;
}

auto Ambience::onGetGamma(float* gamma) -> void {
	*gamma = this->brightness * 25;
}

auto Ambience::onDisabled() -> void {
	auto clientinstance = Client::clientinstance;
	if (!clientinstance) return;

	auto blocksource = clientinstance->getBlockSource();
	if (!blocksource) return;

	auto dimension = blocksource->getDimension();
	if (!dimension) return;

	auto weather = dimension->getWeather();
	if (!weather) return;

	if (old != -1.f) {
		weather->setRain(old);
		old = -1.f;
	}
}

auto Ambience::getMode() -> std::string {
	switch (weather) {
	case 0:
		return _("Unchanged");
	case 1:
		return _("Clear");
	case 2:
		return _("Rain");
	}

	return _("Unknown");
}
