diff --git a/mod.json b/mod.json index c28ddb66..5712fc02 100644 --- a/mod.json +++ b/mod.json @@ -169,6 +169,5 @@ "version": "v1.0.0", "required": true } - ], - "early-load": true + ] } \ No newline at end of file diff --git a/src/features/LayerManager/LayerManager.cpp b/src/features/LayerManager/LayerManager.cpp index 994801eb..078a525b 100644 --- a/src/features/LayerManager/LayerManager.cpp +++ b/src/features/LayerManager/LayerManager.cpp @@ -5,6 +5,14 @@ LayerManager* g_manager = nullptr; +LayerManager::LevelName LayerManager::getLevelName() { + if (!LevelEditorLayer::get()) { + return ""; + } + + return LevelEditorLayer::get()->m_level->m_levelName; +} + LayerManager::Layer* LayerManager::getLayer(int number) { if (number < 0) { return nullptr; @@ -27,6 +35,20 @@ LayerManager::Layer* LayerManager::getLayer(int number) { return lvl->m_layers[number]; } +LayerManager::Level * LayerManager::getLevel() { + auto lvl = this->getLevelName(); // temp until LevelAPI becomes a thing + + if (!lvl.size()) { + return nullptr; + } + + if (!m_levels.count(lvl)) { + m_levels.insert({ lvl, new Level() }); + } + + return m_levels[lvl]; +} + bool LayerManager::init() { return true; } @@ -44,7 +66,7 @@ LayerManager* LayerManager::get() { } LayerManager::Level* LayerManager::Level::createWithCoder(DS_Dictionary* dict) { - auto level = new Level(); + /*auto level = new Level(); if(dict->stepIntoSubDictWithKey("layers")) { for(auto& key : dict->getAllKeys()) { @@ -67,12 +89,14 @@ LayerManager::Level* LayerManager::Level::createWithCoder(DS_Dictionary* dict) { dict->stepOutOfSubDict(); } - return level; + return level;*/ + + return new Level(); } void LayerManager::Level::encodeWithCoder(DS_Dictionary* dict) { // layers - dict->setSubDictForKey("layers"); + /*dict->setSubDictForKey("layers"); dict->stepIntoSubDictWithKey("layers"); for(auto& layer : m_layers) { if(layer) { @@ -90,41 +114,12 @@ void LayerManager::Level::encodeWithCoder(DS_Dictionary* dict) { dict->stepOutOfSubDict(); } } - dict->stepOutOfSubDict(); // layers + dict->stepOutOfSubDict(); // layers*/ } /* HOOKS */ -class $modify(LMGJGameLevel, GJGameLevel) { - LayerManager::Level* associatedLevel = nullptr; - - void dataLoaded(DS_Dictionary* dict) { - // level defined - if(dict->stepIntoSubDictWithKey("BE_LMlevel")) { - if(!m_fields->associatedLevel) - m_fields->associatedLevel = LayerManager::Level::createWithCoder(dict); - - dict->stepOutOfSubDict(); - } - - GJGameLevel::dataLoaded(dict); - } - - void encodeWithCoder(DS_Dictionary* dict) { - if(m_fields->associatedLevel) { - dict->setSubDictForKey("BE_LMlevel"); - dict->stepIntoSubDictWithKey("BE_LMlevel"); - - m_fields->associatedLevel->encodeWithCoder(dict); - - dict->stepOutOfSubDict(); - } - - GJGameLevel::encodeWithCoder(dict); - } -}; - class $modify(LMGameObject, GameObject) { void setOpacity(GLubyte opacity) { if(m_editor && opacity < 255) { @@ -147,15 +142,4 @@ class $modify(LMGameObject, GameObject) { GameObject::setOpacity(opacity); } -}; - -// needa put this here cuz of LMGJGameLevel -LayerManager::Level * LayerManager::getLevel() { - auto lvl = as(LevelEditorLayer::get()->m_level); - - if(!lvl->m_fields->associatedLevel) { - lvl->m_fields->associatedLevel = new Level(); - } - - return lvl->m_fields->associatedLevel; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/features/LayerManager/LayerManager.hpp b/src/features/LayerManager/LayerManager.hpp index 7eabe7f6..11a08f74 100644 --- a/src/features/LayerManager/LayerManager.hpp +++ b/src/features/LayerManager/LayerManager.hpp @@ -50,10 +50,15 @@ class LayerManager { void encodeWithCoder(DS_Dictionary*); }; + using LevelName = std::string; + protected: + std::map m_levels {}; + bool init(); public: + LevelName getLevelName(); Layer * getLayer(int number); Level* getLevel(); diff --git a/src/features/LayerManager/LayerViewPopup.cpp b/src/features/LayerManager/LayerViewPopup.cpp index c4fd73c9..c4b7fd8e 100644 --- a/src/features/LayerManager/LayerViewPopup.cpp +++ b/src/features/LayerManager/LayerViewPopup.cpp @@ -14,8 +14,6 @@ bool g_hideEmptyLayers = false; var ? "GJ_button_02.png" : "GJ_button_01.png" #define VIEWTYPE_TO_BG(type) \ BOOL_TO_BG(this->m_viewType == kViewType##type) -#define GRIDVIEW_TO_BG(type) \ - BOOL_TO_BG(this->m_gridView == kGridView##type) #define GDML_FILE(...) @@ -193,7 +191,7 @@ void LayerViewPopup::setup() { for(int i = 0; i < sprites.size(); i++) { auto spr = sprites[i]; - const char* tex = m_viewType == i ? "GJ_button_02.png" : "GJ_button_01.png"; + const char* tex = m_gridView == i ? "GJ_button_02.png" : "GJ_button_01.png"; auto btnSpr = ButtonSprite::create(spr, 0x20, 1, 32.f, 1.f, false, tex, true); btnSpr->setScale(.5f); btnSpr->m_spritePosition = CCPoint(0, -1.f);