Skip to content

Commit

Permalink
Nvm no early-load :)
Browse files Browse the repository at this point in the history
  • Loading branch information
CattoDev committed Oct 16, 2023
1 parent 8ab4bc2 commit 6a047d5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 50 deletions.
3 changes: 1 addition & 2 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,5 @@
"version": "v1.0.0",
"required": true
}
],
"early-load": true
]
}
74 changes: 29 additions & 45 deletions src/features/LayerManager/LayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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()) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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<LMGJGameLevel*>(LevelEditorLayer::get()->m_level);

if(!lvl->m_fields->associatedLevel) {
lvl->m_fields->associatedLevel = new Level();
}

return lvl->m_fields->associatedLevel;
}
};
5 changes: 5 additions & 0 deletions src/features/LayerManager/LayerManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ class LayerManager {
void encodeWithCoder(DS_Dictionary*);
};

using LevelName = std::string;

protected:
std::map<LevelName, Level*> m_levels {};

bool init();

public:
LevelName getLevelName();
Layer * getLayer(int number);
Level* getLevel();

Expand Down
4 changes: 1 addition & 3 deletions src/features/LayerManager/LayerViewPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6a047d5

Please sign in to comment.