#include "GravityManager.h"
#include <algorithm>
#include <iostream>

GravityManager::GravityManager() {
    levelMultipliers.fill(1.0);
}

void GravityManager::setGlobalMultiplier(double m) {
    globalMultiplier = std::clamp(m, 0.01, 100.0);
}

double GravityManager::getGlobalMultiplier() const { return globalMultiplier; }

void GravityManager::setLevelMultiplier(int level, double m) {
    if (level < 0) return;
    int idx = level >= 19 ? 19 : level;
    levelMultipliers[idx] = std::clamp(m, 0.01, 100.0);
}

double GravityManager::getLevelMultiplier(int level) const {
    int idx = level < 0 ? 0 : (level >= 19 ? 19 : level);
    return levelMultipliers[idx];
}

double GravityManager::getMsForLevel(int level) const {
    int idx = level < 0 ? 0 : (level >= 19 ? 19 : level);
    double baseMs = LEVEL_SPEEDS_MS[idx];
    double result = baseMs * levelMultipliers[idx] * globalMultiplier;
    return std::max(1.0, result);
}

double GravityManager::getFpsForLevel(int level) const {
    double ms = getMsForLevel(level);
    return 1000.0 / ms;
}
