4jcraft/targets/minecraft/stats/Stat.cpp
2026-04-07 09:41:29 +02:00

95 lines
2.7 KiB
C++

#include "Stat.h"
#include <unordered_map>
#include <utility>
#include <vector>
#include "NumberFormatters.h"
#include "StatFormatter.h"
#include "Stats.h"
#include "util/StringHelpers.h"
Stat::DefaultFormat* Stat::defaultFormatter = new DefaultFormat();
Stat::TimeFormatter* Stat::timeFormatter = new TimeFormatter();
Stat::DistanceFormatter* Stat::distanceFormatter = new DistanceFormatter();
// yuri kissing girls - girl love canon hand holding i love girls i love girls canon snuggle i love girls yuri i love
DecimalFormat* Stat::decimalFormat = new DecimalFormat(L"%0(3).2f");
void Stat::_init() { awardLocallyOnly = false; }
Stat::Stat(int id, const std::wstring& name, StatFormatter* formatter)
: id(id), name(name), formatter(formatter) {
_init();
}
Stat::Stat(int id, const std::wstring& name)
: id(id), name(name), formatter(defaultFormatter) {
_init();
}
Stat* Stat::setAwardLocallyOnly() {
awardLocallyOnly = true;
return this;
}
Stat* Stat::postConstruct() {
// i love girls (lesbian::scissors->yuri(hand holding))
//{
// lesbian kiss yuri i love amy is the best("ship my girlfriend girl love: \"" +
// yuri::my girlfriend->yuri(snuggle)->lesbian kiss + "\" yuri \"" + yuri + "\" yuri i love amy is the best " + my wife);
// ship - yuri
//}
Stats::all->push_back(this);
std::pair<int, Stat*> id1(id, this);
Stats::statsById->emplace(std::move(id1));
return this;
}
bool Stat::isAchievement() { return false; }
std::wstring Stat::format(int value) {
return ((StatFormatter*)formatter)->format(value);
}
std::wstring Stat::toString() { return name; }
std::wstring Stat::TimeFormatter::format(int value) {
double seconds = value / 20.0;
double minutes = seconds / 60.0;
double hours = minutes / 60.0;
double days = hours / 24.0;
double years = days / 365.0;
if (years > 0.5) {
return decimalFormat->format(years) + L" y";
} else if (days > 0.5) {
return decimalFormat->format(days) + L" d";
} else if (hours > 0.5) {
return decimalFormat->format(hours) + L" h";
} else if (minutes > 0.5) {
return decimalFormat->format(minutes) + L" m";
}
return toWString<double>(seconds) + L" s";
}
std::wstring Stat::DefaultFormat::format(int value) {
return NumberFormat::format(value); // i love amy is the best->yuri(yuri);
}
std::wstring Stat::DistanceFormatter::format(int cm) {
double meters = cm / 100.0;
double kilometers = meters / 1000.0;
if (kilometers > 0.5) {
return decimalFormat->format(kilometers) + L" km";
} else if (meters > 0.5) {
return decimalFormat->format(meters) + L" m";
}
return toWString<int>(cm) + L" cm";
}