Skip to content

Commit

Permalink
LayerManager progress 4 (ig)
Browse files Browse the repository at this point in the history
Literally just waiting for mac binding to be accepted
  • Loading branch information
CattoDev committed Oct 13, 2023
1 parent 28ee9ef commit e6510bd
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 68 deletions.
77 changes: 76 additions & 1 deletion src/features/LayerManager/EditorLayerInput.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "EditorLayerInput.hpp"
#include "LayerManager.hpp"

#include <Geode/modify/LevelEditorLayer.hpp>
#include <Geode/modify/EditorUI.hpp>

void updateEditorLayerButtons(EditorUI* editorUI) {
if(!editorUI)
return;
Expand Down Expand Up @@ -87,4 +90,76 @@ void EUITextDelegate::textChanged(CCTextInputNode* input) {

updateEditorLayerButtons(editor->m_editorUI);
}
}
}

/*
HOOKS
*/
void filterObjects(CCArray* objs) {
size_t i = 0;
size_t maxCount = objs->count();

while(i < maxCount) {
auto obj = as<GameObject*>(objs->objectAtIndex(i));

auto layer = LayerManager::get()->getLayer(obj->m_editorLayer);
if(layer && layer->m_locked) {
objs->removeObjectAtIndex(i, false);

if(obj->m_isSelected) {
obj->deselectObject();
}

maxCount--;
}
else {
i++;
}
}
}

class $modify(LMEditorLayer, LevelEditorLayer) {
GameObject* objectAtPosition(CCPoint position) {
auto obj = LevelEditorLayer::objectAtPosition(position);

if(obj != nullptr) {
if(auto layer = LayerManager::get()->getLayer(obj->m_editorLayer)) {
if(layer->m_locked) {
obj = nullptr;
}
}
}

return obj;
}

CCArray* objectsAtPosition(CCPoint position) {
auto objs = LevelEditorLayer::objectsAtPosition(position);

filterObjects(objs);

return objs;
}

CCArray* objectsInRect(CCRect rect, bool ignoreLayer) {
auto objs = LevelEditorLayer::objectsInRect(rect, ignoreLayer);

filterObjects(objs);

return objs;
}
};

class $modify(EditorUI) {
void processSelectObjects(CCArray* objs) {
filterObjects(objs);

return EditorUI::processSelectObjects(objs);
}

void selectObjects(CCArray* objs, bool ignoreFilters) {
EditorUI::selectObjects(objs, ignoreFilters);

filterObjects(m_selectedObjects);
}
};
67 changes: 0 additions & 67 deletions src/features/LayerManager/LayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <Geode/modify/GJGameLevel.hpp>
#include <Geode/modify/GameObject.hpp>
#include <Geode/modify/LevelEditorLayer.hpp>
#include <Geode/modify/EditorUI.hpp>

LayerManager* g_manager = nullptr;

Expand Down Expand Up @@ -151,71 +149,6 @@ class $modify(LMGameObject, GameObject) {
}
};

void filterObjects(CCArray* objs) {
size_t i = 0;
size_t maxCount = objs->count();

while(i < maxCount) {
auto obj = as<LMGameObject*>(objs->objectAtIndex(i));

auto layer = LayerManager::get()->getLayer(obj->m_editorLayer);
if(layer && layer->m_locked) {
objs->removeObjectAtIndex(i, false);
obj->deselectObject();
maxCount--;
}
else {
i++;
}
}
}

class $modify(LMEditorLayer, LevelEditorLayer) {
GameObject* objectAtPosition(CCPoint position) {
auto obj = LevelEditorLayer::objectAtPosition(position);

if(obj != nullptr) {
if(auto layer = LayerManager::get()->getLayer(obj->m_editorLayer)) {
if(layer->m_locked) {
obj = nullptr;
}
}
}

return obj;
}

CCArray* objectsAtPosition(CCPoint position) {
auto objs = LevelEditorLayer::objectsAtPosition(position);

filterObjects(objs);

return objs;
}

CCArray* objectsInRect(CCRect rect, bool ignoreLayer) {
auto objs = LevelEditorLayer::objectsInRect(rect, ignoreLayer);

filterObjects(objs);

return objs;
}
};

class $modify(EditorUI) {
void processSelectObjects(CCArray* objs) {
filterObjects(objs);

return EditorUI::processSelectObjects(objs);
}

void selectObjects(CCArray* objs, bool ignoreFilters) {
EditorUI::selectObjects(objs, ignoreFilters);

filterObjects(m_selectedObjects);
}
};

// needa put this here cuz of LMGJGameLevel
LayerManager::Level * LayerManager::getLevel() {
auto lvl = as<LMGJGameLevel*>(LevelEditorLayer::get()->m_level);
Expand Down

0 comments on commit e6510bd

Please sign in to comment.