Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMC9730 committed Apr 29, 2024
1 parent 1578acc commit dba666f
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 34 deletions.
23 changes: 23 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# v1.0.2
## GDHistory Provider
- Fixed typo
- Feature score is now parsed properly
## UI
- Fixed button placement in the Online layer
- 'Play Level' is now faded if level/record does not have level data
- 'Copy ID' button now is not shown on Android (due to crashes)
- Level thumbnails are now removed automatically
- Level ratings are now removed automatically
## Error Handlers
- '`gmd api error`' now also dumps level string
### GDHistory Provider
- Added error handler for specific private level records

# v1.0.1
### GDHistory
- Fixed HTTP bug
### Base
- Initial release on Android

# v1.0.0
- Initial release for Windows
4 changes: 2 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"android": "2.205",
"win": "2.204"
},
"version": "v1.0.1",
"version": "v1.0.2",
"id": "dogotrigger.level_history",
"name": "Level History",
"developer": "dogotrigger",
"description": "Look through deleted and outdated levels using GDHistory or other sources!",
"description": "Look and play through deleted and outdated levels using GDHistory or other sources!",
"dependencies": [
{"id": "hjfod.gmd-api", "importance": "required", "version": "*"},
{"id": "geode.node-ids", "importance": "required", "version": "*"}
Expand Down
44 changes: 32 additions & 12 deletions src/GDHistoryProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void GDHistoryProvider::downloadLevel(std::function<void(LevelProvider *, GJGame
PARSE_STRING(level->m_sfxIDs, data["sfx_ids"]);
PARSE_INT(level->m_audioTrack, leveljson["official_song"]);
PARSE_INT(level->m_gameVersion, leveljson["game_version"]);
PARSE_INT(level->m_ratings, leveljson["raiting"]);
PARSE_INT(level->m_ratingsSum, leveljson["raiting_sum"]);
PARSE_INT(level->m_ratings, leveljson["rating"]);
PARSE_INT(level->m_ratingsSum, leveljson["rating_sum"]);
PARSE_INT(level->m_downloads, leveljson["downloads"]);
PARSE_INT(level->m_likes, leveljson["likes"]);
PARSE_INT(level->m_levelLength, leveljson["length"]);
Expand All @@ -73,15 +73,22 @@ void GDHistoryProvider::downloadLevel(std::function<void(LevelProvider *, GJGame
PARSE_BOOL(level->m_isEditable, leveljson["level_string_available"]);
PARSE_INT(level->m_demonDifficulty, leveljson["demon_type"]);
PARSE_INT(level->m_demonVotes, leveljson["id"]);
if (!leveljson["feature_score"].is_null() && leveljson["feature_score"].get<int>() > 0) {
level->m_featured = 1;
PARSE_INT(level->m_rateFeature, leveljson["feature_score"]);
}
PARSE_INT(level->m_featured, leveljson["feature_score"]);

if (!leveljson["song"].is_null()) {
PARSE_INT(level->m_songID, leveljson["song"]["online_id"]);
}
PARSE_INT(level->m_isEpic, leveljson["epic"]);

bool has_leveldata = false;
PARSE_BOOL(has_leveldata, leveljson["level_string_available"]);
if (has_leveldata) {
level->m_dislikes = 1;
level->m_likes++;
} else {
level->m_dislikes = 0;
}

level->retain();

this->_serverResponseParsed.push_back(level);
Expand Down Expand Up @@ -174,12 +181,18 @@ void GDHistoryProvider::downloadLevel(std::function<void(LevelProvider *, GJGame
PARSE_INT(level->m_rateStars, leveljson["cache_stars"]);
PARSE_INT(level->m_levelID, leveljson["online_id"]);
PARSE_INT(level->m_demonVotes, leveljson["id"]);
if (!leveljson["cache_featured"].is_null() && leveljson["cache_featured"].get<int>() > 0) {
level->m_featured = 1;
PARSE_INT(level->m_rateFeature, leveljson["cache_featured"]);
}
PARSE_INT(level->m_featured, leveljson["cache_featured"]);
PARSE_INT(level->m_isEpic, leveljson["cache_epic"]);

bool has_leveldata = false;
PARSE_BOOL(has_leveldata, leveljson["cache_level_string_available"]);
if (has_leveldata) {
level->m_dislikes = 1;
level->m_likes++;
} else {
level->m_dislikes = 0;
}

level->retain();

this->_serverResponseParsed.push_back(level);
Expand Down Expand Up @@ -321,6 +334,11 @@ void GDHistoryProvider::getLevelData(int id, std::function<void(LevelProvider *,

return;
}
if (catgirl.find("You do not have the rights to download this record") != std::string::npos) {
onComplete(this, "-6", info);

return;
}

std::ofstream gmdfile;

Expand All @@ -341,7 +359,8 @@ void GDHistoryProvider::getLevelData(int id, std::function<void(LevelProvider *,

if (result.isErr() || !result.isOk()) {
log::info("(GDHistoryProvider) error: {}", result.unwrapErr());

log::info("(GDHistoryProvider) level string: {}", catgirl);

onComplete(this, "-2", info);

return;
Expand Down Expand Up @@ -380,7 +399,8 @@ std::string GDHistoryProvider::getErrorCodeDescription(std::string err) {
{"-2", "gmd api error. (dumped into console)"},
{"-3", "invalid record id."},
{"-4", "level not found."},
{"-5", "level data cannot be downloaded for this level. Note that this issue will be fixed if level would have downloadable link for it in the future."}
{"-5", "level data cannot be downloaded for this level. Note that this issue will be fixed if level would have downloadable link for it in the future."},
{"-6", "insufficient rights to download this level."}
};

if (errors.count(err)) {
Expand Down
111 changes: 98 additions & 13 deletions src/ProviderPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,15 @@ void ProviderPopup::setupLevelIDPage(CCLayer *providerBox) {
TextInput *in = TextInput::create(100, "Enter level ID...", "chatFont.fnt");
in->setPosition(0, 0);
in->setAnchorPoint({0.5f, 0.5f});
in->setCallback([this](const std::string &value) {
ProviderPopup::get()->_enterLevelID = value;
});

auto popup = ProviderPopup::get();

if (!popup->_enterLevelID.empty()) {
in->setString(popup->_enterLevelID);
}

int sz = 0;
auto prev_page = static_cast<CCMenuItemSpriteExtra *>(providerBox->getChildByIDRecursive("prev-page"));
Expand Down Expand Up @@ -524,8 +533,7 @@ void ProviderPopup::setupLevelIDPage(CCLayer *providerBox) {
circle->m_pCircle->setOpacity(0);

page->addChild(circle);

auto popup = ProviderPopup::get();

popup->_levelPage._cells.clear();
}

Expand Down Expand Up @@ -713,6 +721,20 @@ void ProviderPopup::onLevelPage(CCObject *sender) {
for (auto cell : popup->_levelPage._cells) {
cell->setVisible(false);
}

if (level->m_dislikes == 0) {
auto spr = dynamic_cast<ButtonSprite *>(getChildByIDRecursive("play-level-spr"));
auto btn = dynamic_cast<CCMenuItemSpriteExtra *>(getChildByIDRecursive("play-level-btn"));

btn->setEnabled(false);
spr->setColor({64, 64, 64});
} else {
auto spr = dynamic_cast<ButtonSprite *>(getChildByIDRecursive("play-level-spr"));
auto btn = dynamic_cast<CCMenuItemSpriteExtra *>(getChildByIDRecursive("play-level-btn"));

btn->setEnabled(true);
spr->setColor({255, 255, 255});
}

// int id = level->m_levelID.value();
// if (id == 0) {
Expand All @@ -723,6 +745,8 @@ void ProviderPopup::onLevelPage(CCObject *sender) {
// CCNode *_cell = popup->_levelPage.page->getChildByID(cellname);

popup->_levelPage._cells[popup->_levelPage._currentLevelsIndex]->setVisible(true);

ProviderPopup::removeThumbnailForCell(popup->_levelPage._cells[popup->_levelPage._currentLevelsIndex]);
}

void ProviderPopup::lambdaOnDownloadLevel(SearchInstance *si, LoadingCircleLayer *existingCircle, ProviderPopup *popup, LevelProvider *prov, GJGameLevel *level) {
Expand Down Expand Up @@ -825,7 +849,8 @@ void ProviderPopup::lambdaOnDownloadLevel(SearchInstance *si, LoadingCircleLayer

si->_page->addChild(menu);

applyBottomButtons(si->_page);
popup->applyBottomButtons(si->_page);
popup->removeLevelRatings();
}

void ProviderPopup::setupSettingsPage(CCLayer *providerBox) {
Expand Down Expand Up @@ -907,6 +932,15 @@ void ProviderPopup::setupGenericSearchPage(CCLayer *providerBox) {
TextInput *in = TextInput::create(150, "Enter level ID/level name/etc...", "chatFont.fnt");
in->setPosition(0, 0);
in->setAnchorPoint({0.5f, 0.5f});
in->setCallback([this](const std::string &value) {
ProviderPopup::get()->_enterQuery = value;
});

auto popup = ProviderPopup::get();

if (!popup->_enterLevelID.empty()) {
in->setString(popup->_enterQuery);
}

int sz = 0;
auto prev_page = static_cast<CCMenuItemSpriteExtra *>(providerBox->getChildByIDRecursive("prev-page"));
Expand Down Expand Up @@ -974,7 +1008,6 @@ void ProviderPopup::setupGenericSearchPage(CCLayer *providerBox) {

page->addChild(circle);

auto popup = ProviderPopup::get();
popup->_levelPage._cells.clear();
}

Expand Down Expand Up @@ -1085,6 +1118,7 @@ void ProviderPopup::lambdaOnDownloadLevelList(SearchInstance *si, LoadingCircleL
}

popup->_levelPage._cells[0]->setVisible(true);
popup->removeThumbnailForCell(popup->_levelPage._cells[0]);

popup->_levelPage._currentLevels = more;
popup->_levelPage._currentLevelsIndex = 0;
Expand Down Expand Up @@ -1297,25 +1331,32 @@ void ProviderPopup::applyBottomButtons(CCLayer *page) {
RowLayout *rLayout = RowLayout::create();
levelActionsMenu->setLayout(rLayout);

{
auto spr4 = ButtonSprite::create("Copy ID");
spr4->setScale(0.6f);

auto btn4 = CCMenuItemSpriteExtra::create(
spr4, this, menu_selector(ProviderPopup::onCopyID)
);
auto app = CCApplication::sharedApplication();
auto platform = app->getTargetPlatform();

levelActionsMenu->addChild(btn4);
levelActionsMenu->updateLayout();
if (platform != TargetPlatform::kTargetAndroid) {
{
auto spr4 = ButtonSprite::create("Copy ID");
spr4->setScale(0.6f);

auto btn4 = CCMenuItemSpriteExtra::create(
spr4, this, menu_selector(ProviderPopup::onCopyID)
);

levelActionsMenu->addChild(btn4);
levelActionsMenu->updateLayout();
}
}

{
auto spr4 = ButtonSprite::create("Play Level");
spr4->setScale(0.6f);
spr4->setID("play-level-spr");

auto btn4 = CCMenuItemSpriteExtra::create(
spr4, this, menu_selector(ProviderPopup::onPlayLevelDownload)
);
btn4->setID("play-level-btn");

levelActionsMenu->addChild(btn4);
levelActionsMenu->updateLayout();
Expand All @@ -1334,4 +1375,48 @@ void ProviderPopup::applyBottomButtons(CCLayer *page) {
levelActionsMenu->setPosition(csz1.width / 2, csz2.height);

page->addChild(levelActionsMenu);
}

void ProviderPopup::removeLevelRatings() {
for (auto cell : _levelPage._cells) {
CCObject *obj1 = cell->getChildByIDRecursive("Level-Ratings/ratings-label");
CCObject *obj2 = cell->getChildByIDRecursive("Level-Ratings/ratings-icon");

if (obj1 != nullptr) {
CCNode *as_node = dynamic_cast<CCNode *>(obj1);
if (as_node != nullptr) {
as_node->removeMeAndCleanup();
}
}
if (obj2 != nullptr) {
CCNode *as_node = dynamic_cast<CCNode *>(obj2);
if (as_node != nullptr) {
as_node->removeMeAndCleanup();
}
}
}
}

void ProviderPopup::removeThumbnailForCell(LevelCell *cell) {
CCArray *children = cell->getChildren();

for (int i = 0; i < children->count(); i++) {
CCObject *obj = children->objectAtIndex(i);

auto as_spr = dynamic_cast<CCSprite *>(obj);
if (as_spr != nullptr) {
as_spr->setPosition({1000.f, 1000.f});

continue;
}

auto as_clip = dynamic_cast<CCClippingNode *>(obj);
if (as_clip != nullptr) {
as_clip->setPosition({1000.f, 1000.f});

continue;
}
}

// children->release();
}
8 changes: 8 additions & 0 deletions src/ProviderPopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class LevelProvider;
class SearchInstance;
class LoadingCircleLayer;
class LevelCell;

class ProviderPopupInfo {
public:
Expand Down Expand Up @@ -49,6 +50,9 @@ class ProviderPopup : public FLAlertLayer {
std::string _levelArraySize = "";
std::string _levelPageStr = "";

std::string _enterLevelID = "";
std::string _enterQuery = "";

LevelCell *createLevelCell(GJGameLevel *level, CCLayer *page);

void lambdaOnDownloadLevel(SearchInstance *si, LoadingCircleLayer *existingCircle, ProviderPopup *popup, LevelProvider *prov, GJGameLevel *level);
Expand Down Expand Up @@ -79,5 +83,9 @@ class ProviderPopup : public FLAlertLayer {
void onPlayLevelDownload(CCObject *sender);

void applyBottomButtons(CCLayer *page);

static void removeThumbnailForCell(LevelCell *cell);
void removeLevelRatings();
// static void setButtonSpriteColor(ButtonSprite)
// bool ccTouchBegan(cocos2d::CCTouch *touch, cocos2d::CCEvent *event) override;
};
16 changes: 9 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@ class $modify(LHLevelSearchLayer, LevelSearchLayer) {

auto menu = (CCMenu *)this->getChildByID("other-filter-menu");

extrasearch->setID("provider-button"_spr);
// extrasearch->setID("provider-button"_spr);

auto children = menu->getChildren();
// auto children = menu->getChildren();

auto last_child = (CCNode *)children->lastObject();
auto pos = last_child->getPosition();
auto csz = last_child->getContentSize();
// auto last_child = (CCNode *)children->lastObject();
// auto pos = last_child->getPosition();
// auto csz = last_child->getContentSize();

pos.y -= csz.width + 10.f;
// pos.y -= csz.width + 10.f;

extrasearch->setPosition(pos);
// extrasearch->setPosition(pos);

menu->addChild(extrasearch);

menu->updateLayout();

return true;
}

Expand Down

0 comments on commit dba666f

Please sign in to comment.