Skip to content

Commit

Permalink
edit main levels
Browse files Browse the repository at this point in the history
  • Loading branch information
user95401 committed Mar 30, 2024
1 parent 334b096 commit 9ff83ae
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 20 deletions.
3 changes: 2 additions & 1 deletion _Headers/Header1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <string>
std::string FilePathFromModFolder(std::string fname);
GJGameLevel* processOutLevelByConfig(int id, GJGameLevel* pGJGameLevel);
std::string saveLevel(int id, GJGameLevel* pGJGameLevel);
std::string saveToMainLevel(int id, GJGameLevel* pGJGameLevel);
void saveLevelData(GJGameLevel* pGJGameLevel);
auto read_file(std::string_view path) -> std::string;
std::vector<std::string> explode(const std::string& str, const char& ch);
std::string framePath(CCNode* node);
Expand Down
3 changes: 2 additions & 1 deletion _Src/_controllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class $modify(PlayLayer) {
auto levelDataPath = FilePathFromModFolder(fmt::format("levels/{}.txt", level->m_levelID.value()));
if (ghc::filesystem::exists(levelDataPath)) {
level->m_levelString = read_file(levelDataPath);
};
}
else level->m_levelString = LocalLevelManager::get()->getMainLevelString(level->m_levelID.value());
};
if (level->m_levelType == GJLevelType::Saved) {
auto levelDataPath = FilePathFromModFolder(fmt::format("levels/{}.txt", level->m_levelID.value()));
Expand Down
21 changes: 20 additions & 1 deletion _Src/_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ GJGameLevel* processOutLevelByConfig(int id, GJGameLevel* pGJGameLevel) {
}

#include <regex>
std::string saveLevel(int id, GJGameLevel* pGJGameLevel) {
std::string saveToMainLevel(int id, GJGameLevel* pGJGameLevel) {
auto resultstr = gd::string("The <cy>level</c> was <co>copied</c>...");
//grab level
GJGameLevel* pLevel = pGJGameLevel;
Expand Down Expand Up @@ -333,6 +333,25 @@ std::string saveLevel(int id, GJGameLevel* pGJGameLevel) {
//set result string for text area
return resultstr;
};
void saveLevelData(GJGameLevel* pGJGameLevel) {
GJGameLevel* pLevel = pGJGameLevel;
//data store
{
//levelString
std::string level_data = pGJGameLevel->m_levelString;
std::string decompressed = ZipUtils::decompressString(level_data, false, 0);
//user coin id 1329, 142 golden coin
decompressed = std::regex_replace(decompressed, std::regex(",1329,"), ",142,");
level_data = ZipUtils::compressString(decompressed, false, 0);
//save
std::string levelDataPath = FilePathFromModFolder(fmt::format("levels/{}.txt", pGJGameLevel->m_levelID.value()));
std::ofstream levelData;
levelData.open(levelDataPath);
levelData.clear();
levelData << level_data.data();
levelData.close();
};
}

std::string truncate(std::string str, size_t width, bool show_ellipsis)
{
Expand Down
172 changes: 158 additions & 14 deletions _Src/_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using namespace geode::prelude;//cocos2d and all Geode namespaces
#define GetKeyState(asd) (short)asd
#endif

#include <regex>
//funny layers
class MainLevelsEditorLayer : public CCLayer {
public:
Expand Down Expand Up @@ -76,7 +77,11 @@ class MainLevelsEditorLayer : public CCLayer {
}
//LevelEditor
void editorSave(CCObject*) {
geode::createQuickPopup("Save By Inputs?", "Values u had wrote will be saved in ini file of this level", "No", "Yes", [this](void*, bool asd) {
geode::createQuickPopup(
"Save By Inputs?",
"Values u had wrote will be saved in ini file of this level",
"No", "Yes",
[this](void*, bool asd) {
if (!asd) return;
//nodes
auto levelNameInput = dynamic_cast<InputNode*>(this->getChildByIDRecursive("levelNameInput"));
Expand All @@ -98,6 +103,7 @@ class MainLevelsEditorLayer : public CCLayer {
levelNameInput->getString().c_str(),
"; Level Name"
);
m_tar->m_levelName = difficultyInput->getString();
Ini.SetValue(
MainSection.c_str(),
"difficulty",
Expand All @@ -111,18 +117,21 @@ class MainLevelsEditorLayer : public CCLayer {
"; Insane = 5,\n"
"; Demon = 6"
);
m_tar->m_difficulty = (GJDifficulty)stoi(difficultyInput->getString());
Ini.SetValue(
MainSection.c_str(),
"stars",
starsInput->getString().c_str(),
"; Stars"
);
m_tar->m_stars = stoi(starsInput->getString());
Ini.SetValue(
MainSection.c_str(),
"audioTrack",
audioTrackInput->getString().c_str(),
"; Audio Track ID"
);
m_tar->m_audioTrack = stoi(audioTrackInput->getString());

Ini.SaveFile(IniPath.c_str());
auto ntfyUpdated = Notification::create("Saved...", NotificationIcon::None);
Expand All @@ -131,7 +140,12 @@ class MainLevelsEditorLayer : public CCLayer {
});
}
void editorReset(CCObject* asd) {
auto pop = geode::createQuickPopup("Reset Inputs?", "Set inputs values by ini files\n<cr>i mean its not restore original level setup</c>", "No", "Yes", [this](void*, bool asd) {
auto pop = geode::createQuickPopup(
"Reset Inputs?",
"Set inputs values by ini files\n"
"<cr>i mean its not restore original level setup</c>",
"No", "Yes",
[this](void*, bool asd) {
if (!asd) return;

//nodes
Expand All @@ -157,24 +171,49 @@ class MainLevelsEditorLayer : public CCLayer {
if (!asd) pop->onBtn2(asd);
}
void editorEditLevel(CCObject* asd) {
auto editor = LevelEditorLayer::scene(PlayLayer::create(m_tar, 0, 0)->m_level, 0);
editor->addChild(CCNode::create(), 999, 1971);
editor->getChildByTag(1971)->setID("MainLevelEditorMark");
CCDirector::get()->pushScene(CCTransitionFade::create(0.5f, editor));
auto pop = geode::createQuickPopup(
"Main Level Editor Notice",
"Yea, u will get Main Level Editor...\n"
"Sooo saving here <cg>works</c> and <cr>actually writes level data in file</c>.\n"
"<co>User Coins</c> will be replaced by <cy>Gold Coins</c>\n"
"<cr>Audio Track doesn't saving!</c>",
"Let me go", nullptr,
460.f,
[this](void*, bool a) {
auto levelForEditor = PlayLayer::create(m_tar, 0, 0)->m_level;
//levelString
{
std::string level_data = levelForEditor->m_levelString;
std::string decompressed = ZipUtils::decompressString(level_data, false, 0);
//user coin id 1329, 142 golden coin
decompressed = std::regex_replace(decompressed, std::regex(",142,"), ",1329,");
level_data = ZipUtils::compressString(decompressed, false, 0);
levelForEditor->m_levelString = level_data;
};
auto scene = CCScene::create();
auto editor = LevelEditorLayer::create(levelForEditor, 0);
editor->addChild(CCNode::create(), 999, 1971);
editor->getChildByTag(1971)->setID("MainLevelEditorMark");
scene->addChild(editor);
CCDirector::get()->pushScene(CCTransitionFade::create(0.5f, scene));
}
);
}
void editorOnBack(CCObject* object) {
CCDirector::get()->pushScene(CCTransitionFade::create(0.5f, LevelSelectLayer::scene(m_tar->m_levelID.value() - 1)));
auto emptyScene = CCScene::create();
auto scene = LevelSelectLayer::scene(this->getTag() - 1);
if (this->getTag() >= 5000 and this->getTag() < 5100) {
emptyScene->addChild(LevelAreaInnerLayer::create(1));
scene = emptyScene;
};
CCDirector::get()->pushScene(CCTransitionFade::create(0.5f, scene));
}
static void openLevelEditor(GJGameLevel* tar) {
auto scene = CCScene::create();
auto me = create();
me->m_tar = tar;
dynamic_cast<CCMenuItemSpriteExtra*>(me->getChildByIDRecursive("backBtn"))
->setTarget(me, menu_selector(MainLevelsEditorLayer::editorOnBack));
auto asd2 = ButtonSprite::create("editt");
auto kfc2 = CCMenuItemSpriteExtra::create(asd2, me, menu_selector(MainLevelsEditorLayer::editorEditLevel));
kfc2->setPositionX(50.f);
me->getChildByIDRecursive("backBtn")->getParent()->addChild(kfc2);
{
//create menu
auto inputsContainer = CCMenu::create();
Expand Down Expand Up @@ -223,7 +262,7 @@ class MainLevelsEditorLayer : public CCLayer {
audioTrackInput->getInput()->setAllowedChars("1234567890");
inputsContainer->addChild(audioTrackInput);
};
//controll btns
//con troll btns
{
auto asd = ButtonSprite::create("Reset");
auto kfc = CCMenuItemSpriteExtra::create(asd, me, menu_selector(MainLevelsEditorLayer::editorReset));
Expand All @@ -232,6 +271,19 @@ class MainLevelsEditorLayer : public CCLayer {
auto container = CCMenu::create(kfc, kfc2, nullptr);
container->setContentHeight(32.f);
container->alignItemsHorizontallyWithPadding(12.f);
CCMenuItemSpriteExtra* editLevel;
{
auto hi = geode::AccountButtonSprite::create(
CCSprite::createWithSpriteFrameName("GJ_hammerIcon_001.png"),
AccountBaseColor::Gray
);
hi->setScale(0.8f);
typeinfo_cast<CCSprite*>(hi->getChildren()->objectAtIndex(0))->setScale(1.1f);
editLevel = CCMenuItemSpriteExtra::create(hi, me, menu_selector(MainLevelsEditorLayer::editorEditLevel));
editLevel->setPositionX(208.f);
editLevel->setPositionY(-10.f);
container->addChild(editLevel);
}
inputsContainer->addChild(container);
}
//update and add menu
Expand All @@ -249,10 +301,46 @@ class MainLevelsEditorLayer : public CCLayer {
//yea setup inputs
me->editorReset(nullptr);//nullptr is means click on btn2 instatnly
}
scene->addChild(me, 0, 3228);
scene->addChild(me, 0, tar->m_levelID);
CCDirector::sharedDirector()->pushScene(CCTransitionFade::create(0.5f, scene));
}
};
#include <Geode/modify/EditorPauseLayer.hpp>
class $modify(EditorPauseLayerExt, EditorPauseLayer) {
bool isMainLevelEditor() {
return this->m_editorLayer->getChildByIDRecursive("MainLevelEditorMark");
}
void onSave(cocos2d::CCObject* sender) {
if (isMainLevelEditor()) {
this->saveLevel();
Notification::create("Saving level")->show();
saveLevelData(this->m_editorLayer->m_level);
return;
}
EditorPauseLayer::onSave(sender);
};
void onSaveAndExit(cocos2d::CCObject* sender) {
if (isMainLevelEditor()) {
MainLevelsEditorLayer::openLevelEditor(this->m_editorLayer->m_level);
this->saveLevel();
Notification::create("Saving level")->show();
saveLevelData(this->m_editorLayer->m_level);
return;
}
EditorPauseLayer::onSaveAndExit(sender);
};
void onSaveAndPlay(cocos2d::CCObject* sender) {
if (isMainLevelEditor()) if(auto node = dynamic_cast<CCMenuItemSpriteExtra*>(sender)) {
node->setNormalImage(CCLabelTTF::create("No", "Courier New", 16.f));
return;
}
EditorPauseLayer::onSaveAndPlay(sender);
};
void FLAlert_Clicked(FLAlertLayer* p0, bool p1) {
if (isMainLevelEditor() and p1) return MainLevelsEditorLayer::openLevelEditor(this->m_editorLayer->m_level);
EditorPauseLayer::FLAlert_Clicked(p0, p1);
};
};

#include <Geode/modify/LevelInfoLayer.hpp>
class $modify(LevelInfoLayerExt, LevelInfoLayer) {
Expand Down Expand Up @@ -439,6 +527,7 @@ class $modify(LevelPageExt, LevelPage) {
hi->setScale(0.8f);
typeinfo_cast<CCSprite*>(hi->getChildren()->objectAtIndex(0))->setScale(1.1f);
typeinfo_cast<CCSprite*>(hi->getChildren()->objectAtIndex(0))->setColor({ 20, 20, 20 });
hi->addChild(typeinfo_cast<CCSprite*>(hi->getChildren()->objectAtIndex(0)));
editLevel = CCMenuItemSpriteExtra::create(hi, rtn, menu_selector(LevelPageExt::editLevel));
};
auto pCCMenu = CCMenu::create(deleteLevel, editLevel, nullptr);
Expand All @@ -455,4 +544,59 @@ class $modify(LevelPageExt, LevelPage) {
return rtn;
};
};
/**/

#include <Geode/modify/LevelAreaInnerLayer.hpp>
class $modify(LevelAreaInnerLayerExt, LevelAreaInnerLayer) {
class EditBtn : public CCMenuItemSpriteExtra {
public:
void editLevel(CCObject* asneeeeder) {
MainLevelsEditorLayer::openLevelEditor(
PlayLayer::create(
LevelTools::getLevel(asneeeeder->getTag(), false),
0, 0
)->m_level
);
}
static auto createAndSetup(CCNode* door) {
//Node
auto hi = geode::AccountButtonSprite::create(
CCSprite::createWithSpriteFrameName("d_cogwheel_04_001.png"),
AccountBaseColor::Gray
);
hi->setScale(0.4f);
typeinfo_cast<CCSprite*>(hi->getChildren()->objectAtIndex(0))->setScale(1.1f);
typeinfo_cast<CCSprite*>(hi->getChildren()->objectAtIndex(0))->setColor({ 20, 20, 20 });
hi->addChild(typeinfo_cast<CCSprite*>(hi->getChildren()->objectAtIndex(0)));
//create
auto me = (EditBtn*)create(hi, door, menu_selector(EditBtn::editLevel));
me->setTag(door->getTag());
door->getParent()->addChild(me, 999);
me->setPositionX(door->getPosition().x + 40);
me->setPositionY(door->getPosition().y + 45);
return me;
}
};
static LevelAreaInnerLayer* create(bool p0) {
auto rtn = LevelAreaInnerLayer::create(p0);
if (Mod::get()->getSettingValue<bool>("UI")) {
auto mainnode = dynamic_cast<CCNode*>(rtn->getChildren()->objectAtIndex(1));
if (mainnode) {
for (int index = 0; index < mainnode->getChildrenCount(); ++index) {
auto obj = mainnode->getChildren()->objectAtIndex(index);
if (obj) {
auto menu = dynamic_cast<CCMenu*>(obj);
if (menu) {
if (menu->getChildByTag(5001)) {
EditBtn::createAndSetup(menu->getChildByTag(5001));
EditBtn::createAndSetup(menu->getChildByTag(5002));
EditBtn::createAndSetup(menu->getChildByTag(5003));
EditBtn::createAndSetup(menu->getChildByTag(5004));
};
};
};
};
}
}
return rtn;
}
};
2 changes: 1 addition & 1 deletion bindings/bindings/2.204/GeometryDash.bro
Original file line number Diff line number Diff line change
Expand Up @@ -9870,7 +9870,7 @@ class LocalLevelManager : GManager {
TodoReturn getCreatedLevels(int);
TodoReturn getCreatedLists(int) = win 0x2784f0;
TodoReturn getLevelsInNameGroups();
TodoReturn getMainLevelString(int) = win 0x277a90;
gd::string getMainLevelString(int tarLevelID) = win 0x277a90;
TodoReturn markLevelsAsUnmodified();
TodoReturn moveLevelToTop(GJGameLevel*);
TodoReturn reorderLevels();
Expand Down
4 changes: 2 additions & 2 deletions bindings/bindings/2.205/GeometryDash.bro
Original file line number Diff line number Diff line change
Expand Up @@ -9795,12 +9795,12 @@ class LocalLevelManager : GManager {
TodoReturn getCreatedLevels(int);
TodoReturn getCreatedLists(int);
TodoReturn getLevelsInNameGroups();
TodoReturn getMainLevelString(int);
gd::string getMainLevelString(int tarLevelID);
TodoReturn markLevelsAsUnmodified();
TodoReturn moveLevelToTop(GJGameLevel*);
TodoReturn reorderLevels();
TodoReturn reorderLists();
TodoReturn tryLoadMainLevelString(int);
gd::string tryLoadMainLevelString(int tarLevelID);
TodoReturn updateLevelOrder();
TodoReturn updateLevelRevision();
TodoReturn updateListOrder();
Expand Down

0 comments on commit 9ff83ae

Please sign in to comment.