Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Displays <cr>**GDDL tiers**</c> below demon ratings.

![Example](resources/tier.png)

If there's no rating yet, it'll display a sad face :(
If the rating doesn't load, <cb>refresh</c> the level page.

## Known issues
Expand Down
5 changes: 3 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"geode": "2.0.0",
"version": "v1.0.0-beta.1",
"version": "v1.0.0-beta.2",
"gd": "2.204",
"id": "b1rtek.gddlintegration",
"name": "GDDL Integration",
Expand All @@ -9,7 +9,8 @@
"repository": "https://github.com/B1rtek/Geode-GDDLIntegration",
"resources": {
"sprites": [
"resources/tier.png"
"resources/tier.png",
"resources/tiers/*.png"
]
}
}
Binary file modified resources/tier.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_26.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_27.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_28.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_29.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_30.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tiers/tier_31.png
Binary file added resources/tiers/tier_32.png
Binary file added resources/tiers/tier_33.png
Binary file added resources/tiers/tier_34.png
Binary file added resources/tiers/tier_35.png
Binary file added resources/tiers/tier_4.png
Binary file added resources/tiers/tier_5.png
Binary file added resources/tiers/tier_6.png
Binary file added resources/tiers/tier_7.png
Binary file added resources/tiers/tier_8.png
Binary file added resources/tiers/tier_9.png
Binary file added resources/tiers/tier_unrated.png
82 changes: 63 additions & 19 deletions src/LevelInfoLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Geode/utils/web.hpp>

#include "RatingsManager.h"
#include "Utils.h"

using namespace geode::prelude;

Expand All @@ -16,19 +17,25 @@ class $modify(GDDLInfoLayer, LevelInfoLayer) {
bool isDemon = std::stoi(m_starsLabel->getString()) == 10;
if (starsLabel && isDemon) {
gddlTierUpdated = false;
auto tierLabel = CCLabelBMFont::create("Tier ??", "bigFont.fnt");
tierLabel->setID("gddl-rating"_spr);
float labelShiftRows = m_level->m_coins > 0 ? 2.0f : 1.0f;
float labelShift = starsLabel->getContentSize().height * 0.9f / (2.0f / labelShiftRows); // I'm really trying to make it perfect
tierLabel->setPosition({starsLabel->getPositionX(), starsLabel->getPositionY() - labelShift}); //160x185
tierLabel->setAnchorPoint({0.5f, 0.5f});
tierLabel->setScale(0.4f);
addChild(tierLabel);

auto diffPosition = m_difficultySprite->getPosition();
auto diffSize = m_difficultySprite->getContentSize();

auto menu = CCMenu::create();
menu->setPosition({diffPosition.x - 50 - diffSize.width/2, diffPosition.y - diffSize.height/2});
menu->setContentSize({50, 50});
menu->setID("rating-menu"_spr);
addChild(menu);

auto button = CCMenuItemSpriteExtra::create(getDefaultSprite(), this, menu_selector(GDDLInfoLayer::onGDDLInfo));
button->setPosition({25, 25});
button->setID("rating"_spr);
menu->addChild(button);

int levelID = m_level->m_levelID;
int tier = RatingsManager::getDemonTier(levelID);
if(tier != -1) {
setTierInformation(tier);
updateButton(tier);
gddlTierUpdated = true;
}
}
Expand All @@ -55,22 +62,59 @@ class $modify(GDDLInfoLayer, LevelInfoLayer) {
if(RatingsManager::addRatingFromResponse(levelID, response)) {
tier = RatingsManager::getDemonTier(levelID);
}
setTierInformation(tier);
updateButton(tier);
})
.expect([this](std::string const& error) {
setTierInformation(-1);
updateButton(-1);
});
}
}

void setTierInformation(int tier) {
std::string tierString = ":(";
if (tier != -1) {
tierString = std::to_string(tier);
void updateButton(int tier) {
auto menu = typeinfo_cast<CCMenu*>(getChildByID("rating-menu"_spr));
if (!menu) return;
auto tierButton = typeinfo_cast<CCMenuItemSpriteExtra*>(menu->getChildByID("rating"_spr));
if (!tierButton) return;
tierButton->removeAllChildren();

auto tierSprite = getSpriteFromTier(tier);
if (tierSprite) {
tierButton->addChild(tierSprite);
} else {
tierButton->addChild(getDefaultSprite());
}
std::string tierLabelText = "Tier " + tierString;
auto tierLabel = typeinfo_cast<CCLabelBMFont*>(getChildByID("gddl-rating"_spr));
tierLabel->setString(tierLabelText.c_str());
tierLabel->setColor(RatingsManager::getTierColor(tier));
}

CCSprite *getTierSpriteFromName(const char *name) {
auto textureName = Mod::get()->expandSpriteName(name);
auto sprite = CCSprite::create(textureName);
if (!sprite) return getDefaultSprite();

sprite->setScale(0.275f);
sprite->setAnchorPoint({0, 0});

return sprite;
}

CCSprite *getSpriteFromTier(int tier) {
if (tier == -1) return getDefaultSprite();
return getTierSpriteFromName(("tier_" + std::to_string(tier) + ".png").c_str());
}

CCSprite *getDefaultSprite() {
return getTierSpriteFromName("tier_unrated.png");
}

void onGDDLInfo(CCObject *sender) {
auto rating = RatingsManager::getRating(m_level->m_levelID);
if (!rating) return;
auto info = rating.value();

std::string tier = info.rating == -1 ? "N/A" : Utils::floatToString(info.rating, 2);
std::string enjoyment = info.enjoyment == -1 ? "N/A" : Utils::floatToString(info.enjoyment, 2);
std::string submissionCount = info.submissionCount == -1 ? "N/A" : std::to_string(info.submissionCount);

auto layer = FLAlertLayer::create("GDDL Information", "Tier: " + tier + "\nEnjoyment: " + enjoyment + "\nTotal submissions: " + submissionCount, "Close");
layer->show();
}
};
5 changes: 5 additions & 0 deletions src/RatingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ int RatingsManager::getDemonTier(int id) {
return !demonMap.contains(id) ? -1 : demonMap[id].roundedRating;
}

std::optional<GDDLRating> RatingsManager::getRating(int id) {
if (!demonMap.contains(id)) return {};
return demonMap[id];
}

std::string RatingsManager::getRequestUrl(int id) {
std::string requestURL = "https://gdladder.com/api/level?levelID=" + std::to_string(id);
return requestURL;
Expand Down
1 change: 1 addition & 0 deletions src/RatingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RatingsManager {

public:
static int getDemonTier(int id);
static std::optional<GDDLRating> getRating(int id);

static std::string getRequestUrl(int id);

Expand Down
10 changes: 10 additions & 0 deletions src/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <string>

class Utils {
public:
static std::string floatToString(float number, int precision) {
std::stringstream stream;
stream << std::fixed << std::setprecision(precision) << number;
return stream.str();
}
};