Skip to content

Commit

Permalink
add game ver estimation based on object ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Dec 2, 2024
1 parent a34474b commit cfea8c3
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/layers/ExtendedLevelInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ void ExtendedLevelInfo::refreshInfoTexts() {
infoText.str("");
if(!ServerUtils::isGDPS()) infoText << "\n<cj>Uploaded</c>: " << TimeUtils::isoTimeToString(m_uploadDateEstimated);
infoText << "\n<cg>Objects</c>: " << LevelMetadata::zeroIfNA(m_level->m_objectCount)
<< "\n<cg>Objects (est.)</c>: " << LevelMetadata::zeroIfNA(m_objectsEstimated) //i have no idea what the 0 and 11 mean, i just copied them from PlayLayer::init
<< "\n<cg>Objects (est.)</c>: " << LevelMetadata::zeroIfNA(m_objectsEstimated)
<< "\n<cy>Feature Score</c>: " << LevelMetadata::zeroIfNA(m_level->m_featured)
<< "\n<co>Two-player</c>: " << LevelMetadata::boolString(m_level->m_twoPlayerMode)
<< "\n<cp>Game Ver (est.)</c>: " << m_maxGameVersion
<< "\n<cr>Size</c>: " << m_fileSizeCompressed << " / " << m_fileSizeUncompressed;
;

Expand Down Expand Up @@ -123,6 +124,7 @@ void ExtendedLevelInfo::setupAdditionalInfo() {
m_objectsEstimated = std::count(levelString.begin(), levelString.end(), ';');
m_fileSizeCompressed = BetterInfo::fileSize(m_level->m_levelString.size());
m_fileSizeUncompressed = BetterInfo::fileSize(levelString.size());
m_maxGameVersion = BetterInfo::gameVerForDecompressedLevelString(levelString);
refreshInfoTexts();
Loader::get()->queueInMainThread([this]() {
this->loadPage(this->m_page);
Expand Down
1 change: 1 addition & 0 deletions src/layers/ExtendedLevelInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BI_DLL ExtendedLevelInfo : public CvoltonAlertLayerStub, public UploadDate
std::string m_secondary;
std::string m_fileSizeCompressed = "NA";
std::string m_fileSizeUncompressed = "NA";
std::string m_maxGameVersion = "NA";
std::string m_uploadDateEstimated = "NA";
Ref<GJGameLevel> m_level;
TextArea* m_info;
Expand Down
62 changes: 59 additions & 3 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ uint64_t BetterInfo::timeInMs() {
}

float BetterInfo::timeForLevelString(const std::string& levelString) {
std::string epicString;
try {
auto a = timeInMs();

Expand Down Expand Up @@ -571,8 +570,6 @@ float BetterInfo::timeForLevelString(const std::string& levelString) {
objectStream.seekg(0);*/
std::stringstream objectStream(currentObject);
while(getline(objectStream, currentKey, ',')) {
epicString += currentKey + "\n";

if(i % 2 == 0) keyID = currentKey;
else {
if(keyID == "1") objID = BetterInfo::stoi(currentKey);
Expand Down Expand Up @@ -603,6 +600,65 @@ float BetterInfo::timeForLevelString(const std::string& levelString) {
}
}

int BetterInfo::maxObjectIDForDecompressedLevelString(const std::string& levelString) {
try {
std::stringstream responseStream(levelString);
std::string currentObject;
std::string currentKey;
std::string keyID;

int maxID = 0;

while(getline(responseStream, currentObject, ';')){
size_t i = 0;
int objID = 0;
float xPos = 0;

std::stringstream objectStream(currentObject);
while(getline(objectStream, currentKey, ',')) {
if(i % 2 == 0) keyID = currentKey;
else {
if(keyID == "1") objID = BetterInfo::stoi(currentKey);
}
i++;

if(objID != 0) break;
}

if(objID > maxID) maxID = objID;
}

return maxID;
} catch(std::exception e) {
log::error("An exception has occured while calculating time for levelString: {}", e.what());
return 0;
}
}

std::string BetterInfo::gameVerForDecompressedLevelString(const std::string& levelString) {
const std::map<int, const char*> maximums = {
{43, "1.0"},
{46, "1.1"},
{47, "1.2"},
{84, "1.3"},
{104, "1.4"},
{141, "1.5"},
{199, "1.6"},
{285, "1.7"},
{505, "1.8"},
{744, "1.9"},
{1329, "2.0"},
{1911, "2.1"},
{4539, "2.2"}
};

for(const auto& [key, value] : maximums) {
if(maxObjectIDForDecompressedLevelString(levelString) <= key) return value;
}

return "2.3+";
}

bool BetterInfo::controllerConnected() {
return PlatformToolbox::isControllerConnected();
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace BetterInfo {

BI_DLL uint64_t timeInMs();
BI_DLL float timeForLevelString(const std::string& levelString);
BI_DLL int maxObjectIDForDecompressedLevelString(const std::string& levelString);
BI_DLL std::string gameVerForDecompressedLevelString(const std::string& levelString);

BI_DLL bool controllerConnected();

Expand Down

0 comments on commit cfea8c3

Please sign in to comment.