Skip to content

Commit

Permalink
add demon difficulty faces to daily history
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Dec 9, 2023
1 parent 676bd73 commit 70319c5
Show file tree
Hide file tree
Showing 5 changed files with 37 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 @@ -14,7 +14,7 @@ void DailyCell::loadFromLevel(GJGameLevel* level) {
auto GSM = gd::GameStatsManager::sharedState();
auto winSize = CCDirector::sharedDirector()->getWinSize();

auto diffSprite = CCSprite::createWithSpriteFrameName(ExtendedLevelInfo::getDifficultyIcon(level->stars));
auto diffSprite = CCSprite::createWithSpriteFrameName(level->stars == 10 ? ExtendedLevelInfo::getDemonDifficultyIcon(biCache->getDemonDifficulty(level->levelID)) : ExtendedLevelInfo::getDifficultyIcon(level->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 @@ -128,6 +128,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 @@ -23,6 +23,7 @@ class ExtendedLevelInfo : public CvoltonAlertLayerStub {
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
19 changes: 18 additions & 1 deletion src/managers/BetterInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ bool BetterInfoCache::init(){
m_coinCountDict = CCDictionary::create();
m_coinCountDict->retain();

m_demonDifficultyDict = CCDictionary::create();
m_demonDifficultyDict->retain();

this->setup();

checkDailies();
Expand All @@ -34,6 +37,7 @@ BetterInfoCache::BetterInfoCache(){}
void BetterInfoCache::encodeDataTo(DS_Dictionary* data) {
data->setDictForKey("levelNames", m_levelNameDict);
data->setDictForKey("coinCounts", m_coinCountDict);
data->setDictForKey("demonDifficulties", m_demonDifficultyDict);
}
void BetterInfoCache::dataLoaded(DS_Dictionary* data) {
auto levelNameDict = static_cast<CCDictionary*>(data->getObjectForKey("levelNames"));
Expand All @@ -43,14 +47,20 @@ void BetterInfoCache::dataLoaded(DS_Dictionary* data) {
m_levelNameDict->retain();
}


auto coinCounts = static_cast<CCDictionary*>(data->getObjectForKey("coinCounts"));
if(coinCounts) {
m_coinCountDict->release();
m_coinCountDict = coinCounts;
m_coinCountDict->retain();
}

auto demonDifficulties = static_cast<CCDictionary*>(data->getObjectForKey("demonDifficulties"));
if(demonDifficulties) {
m_demonDifficultyDict->release();
m_demonDifficultyDict = demonDifficulties;
m_demonDifficultyDict->retain();
}

this->save();
}
void BetterInfoCache::firstLoad() {
Expand Down Expand Up @@ -85,6 +95,7 @@ void BetterInfoCache::cacheLevel(GJGameLevel* level) {
auto idString = std::to_string(level->levelID);
m_levelNameDict->setObject(CCString::create(level->levelName.c_str()), idString);
m_coinCountDict->setObject(CCString::createWithFormat("%i", level->coins), idString);
m_demonDifficultyDict->setObject(CCString::createWithFormat("%i", level->demonDifficulty), idString);
}

void BetterInfoCache::cacheLevels(std::set<int> toDownload) {
Expand Down Expand Up @@ -129,6 +140,12 @@ int BetterInfoCache::getCoinCount(int levelID) {
return ret->intValue();
}

int BetterInfoCache::getDemonDifficulty(int levelID) {
auto ret = m_demonDifficultyDict->valueForKey(std::to_string(levelID));
if(std::string_view(ret->getCString()).empty()) return 3;
return ret->intValue();
}

void BetterInfoCache::loadListFinished(cocos2d::CCArray* levels, const char*) {
for(size_t i = 0; i < levels->count(); i++) {
auto level = static_cast<GJGameLevel*>(levels->objectAtIndex(i));
Expand Down
2 changes: 2 additions & 0 deletions src/managers/BetterInfoCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class BetterInfoCache : public gd::GManager, public gd::OnlineListDelegate {
public:
cocos2d::CCDictionary* m_levelNameDict;
cocos2d::CCDictionary* m_coinCountDict;
cocos2d::CCDictionary* m_demonDifficultyDict;

bool init();
void encodeDataTo(DS_Dictionary* data) override;
Expand All @@ -30,6 +31,7 @@ class BetterInfoCache : public gd::GManager, public gd::OnlineListDelegate {

const char* getLevelName(int levelID);
int getCoinCount(int levelID);
int getDemonDifficulty(int levelID);

void loadListFinished(cocos2d::CCArray*, const char*);
void loadListFailed(const char*);
Expand Down

0 comments on commit 70319c5

Please sign in to comment.