Skip to content

Commit

Permalink
LevelEditorLayer.cpp implemented and PlayLayer.cpp modified (#31)
Browse files Browse the repository at this point in the history
* LevelEditorLayer.cpp implemented

* Added background string ID to PlayLayer

* Improved getting method for ShaderLayer in LevelEditorLayer

* Revert change in PlayLayer
  • Loading branch information
Termantita authored Mar 10, 2024
1 parent a54b011 commit 022b566
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/LevelEditorLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <Geode/Bindings.hpp>
#include <Geode/modify/LevelEditorLayer.hpp>
#include <Geode/utils/cocos.hpp>
#include <Geode/utils/NodeIDs.hpp>

#include "IDCheck.hpp"

using namespace geode::prelude;
using namespace geode::node_ids;

$register_ids(LevelEditorLayer) {
setIDSafe<GJEffectManager>(this, 0, "effect-manager");

if (auto shaderLayer = getChildOfType<ShaderLayer>(this, 0)) {
setIDSafe(shaderLayer, 1, "main-node");
setIDSafe<CCSprite>(static_cast<CCNode*>(shaderLayer->getChildren()->objectAtIndex(1)), 0, "background");
} else {
setIDSafe(this, 1, "main-node");
setIDSafe<CCSprite>(static_cast<CCNode*>(this->getChildren()->objectAtIndex(1)), 0, "background");
}
}

struct LevelEditorLayerIDs : Modify<LevelEditorLayerIDs, LevelEditorLayer> {
static void onModify(auto& self) {
if (!self.setHookPriority("LevelEditorLayer::init", GEODE_ID_PRIORITY)) {
log::warn("Failed to set LevelEditorLayer::init hook priority, node IDs may not work properly");
}
}

bool init(GJGameLevel* level, bool p1) {
if (!LevelEditorLayer::init(level, p1)) return false;

NodeIDs::get()->provide(this);

return true;
}
};
2 changes: 2 additions & 0 deletions src/PlayLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ using namespace geode::node_ids;

$register_ids(PlayLayer) {
setIDSafe(this, 1, "main-node");
setIDSafe<CCSprite>(static_cast<CCNode*>(this->getChildren()->objectAtIndex(1)), 0, "background");

setIDSafe(this, 3, "hitbox-node");
setIDSafe<GJEffectManager>(this, 0, "effect-manager");
//setIDSafe<UILayer>(this, 0, "ui-layer"); //changing this id is unsafe because mods depend on "UILayer", which is actually fairly safe to do, since this is the only UILayer in the whole layer
Expand Down

0 comments on commit 022b566

Please sign in to comment.