Skip to content

Commit

Permalink
add demon difficulty to DailyCell
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Dec 6, 2023
1 parent 3e509af commit 355bf84
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/layers/DailyCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void DailyCell::loadFromLevel(GJGameLevel* level) {
auto GSM = GameStatsManager::sharedState();
auto winSize = CCDirector::sharedDirector()->getWinSize();

auto diffSprite = CCSprite::createWithSpriteFrameName(ExtendedLevelInfo::getDifficultyIcon(level->m_stars));
auto diffSprite = CCSprite::createWithSpriteFrameName(level->m_stars == 10 ? ExtendedLevelInfo::getDemonDifficultyIcon(biCache->getDemonDifficulty(level->m_levelID)) : ExtendedLevelInfo::getDifficultyIcon(level->m_stars));
diffSprite->setPosition({22.f, 32.f});
diffSprite->setScale(0.8f);
diffSprite->setZOrder(1);
Expand Down
15 changes: 15 additions & 0 deletions src/layers/ExtendedLevelInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ const char* ExtendedLevelInfo::getDifficultyIcon(int stars){
}
}

const char* ExtendedLevelInfo::getDemonDifficultyIcon(int demonDifficulty){
switch(demonDifficulty){
case 3:
return "difficulty_07_btn_001.png";
case 4:
return "difficulty_08_btn_001.png";
case 5:
return "difficulty_09_btn_001.png";
case 6:
return "difficulty_10_btn_001.png";
default:
return "difficulty_06_btn_001.png";
}
}

std::string ExtendedLevelInfo::passwordString(int password){
if(password == 0) return "NA";
if(password == 1) return "Free Copy";
Expand Down
1 change: 1 addition & 0 deletions src/layers/ExtendedLevelInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ExtendedLevelInfo : public CvoltonAlertLayerStub, public UploadDateDelegat
static std::string stringDate(std::string date);
static const char* boolString(bool value);
static const char* getDifficultyIcon(int stars);
static const char* getDemonDifficultyIcon(int demonDifficulty);
static std::string passwordString(int password);
static std::string zeroIfNA(int value);
static std::string workingTime(int value);
Expand Down
15 changes: 14 additions & 1 deletion src/managers/BetterInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bool BetterInfoCache::init(){
void BetterInfoCache::validateLoadedData() {
validateIsObject("level-name-dict");
validateIsObject("coin-count-dict");
validateIsObject("demon-difficulty-dict");
validateIsObject("username-dict");
validateIsObject("upload-date-dict");
validateIsObject("level-info-dict");
Expand All @@ -32,7 +33,7 @@ void BetterInfoCache::checkDailies() {
if(currentLvl == nullptr) continue;

auto idString = std::to_string(currentLvl->m_levelID);
if(objectExists("level-name-dict", idString) && objectExists("coin-count-dict", idString)) continue;
if(objectExists("level-name-dict", idString) && objectExists("coin-count-dict", idString) && objectExists("demon-difficulty-dict", idString)) continue;

auto levelFromSaved = static_cast<GJGameLevel*>(GLM->m_onlineLevels->objectForKey(std::to_string(currentLvl->m_levelID).c_str()));
if(levelFromSaved != nullptr) cacheLevel(levelFromSaved);
Expand All @@ -47,6 +48,7 @@ void BetterInfoCache::cacheLevel(GJGameLevel* level) {
auto idString = std::to_string(level->m_levelID);
m_json["level-name-dict"][idString] = std::string(level->m_levelName);
m_json["coin-count-dict"][idString] = level->m_coins;
m_json["demon-difficulty-dict"][idString] = level->m_demonDifficulty;
}

void BetterInfoCache::cacheLevels(std::set<int> toDownload) {
Expand Down Expand Up @@ -90,6 +92,17 @@ std::string BetterInfoCache::getLevelName(int levelID) {
}
}

int BetterInfoCache::getDemonDifficulty(int levelID) {
auto idString = std::to_string(levelID);
if(!objectExists("demon-difficulty-dict", idString)) return 0;

try {
return m_json["demon-difficulty-dict"][idString].as_int();
} catch(std::exception) {
return 0;
}
}

void BetterInfoCache::storeUserName(int userID, const std::string& username) {
if(username.empty()) {
log::info("Username empty, not storing");
Expand Down
1 change: 1 addition & 0 deletions src/managers/BetterInfoCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class BetterInfoCache : public BaseJsonManager, public OnlineListDelegate {
void storeDatesForLevel(GJGameLevel* level);

std::string getLevelName(int levelID);
int getDemonDifficulty(int levelID);
std::string getUserName(int userID, bool download = true);
int getCoinCount(int levelID);
std::string getLevelInfo(int levelID, const std::string& field);
Expand Down

0 comments on commit 355bf84

Please sign in to comment.