-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89a2dc5
commit cac251d
Showing
8 changed files
with
2,398 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <Geode/Geode.hpp> | ||
#include <Geode/modify/CCScale9Sprite.hpp> | ||
#include "Utils.h" | ||
|
||
using namespace geode::prelude; | ||
|
||
class $modify(CCScale9Sprite) { | ||
|
||
struct Fields { | ||
bool m_hasFixed = false; | ||
}; | ||
|
||
void visit() { | ||
CCScale9Sprite::visit(); | ||
if (!m_fields->m_hasFixed) { | ||
fixSprites(); | ||
m_fields->m_hasFixed = true; | ||
} | ||
} | ||
|
||
void transformSprite(CCSprite* sprite, CCSize transform, int idx) { | ||
auto tRect = sprite->getTextureRect(); | ||
|
||
tRect.size -= transform; | ||
|
||
if (idx == 0) | ||
sprite->setPosition(sprite->getPosition() + transform); | ||
else if (idx == 1 && (transform.width > 0 || transform.height > 0)) | ||
sprite->setVisible(false); | ||
else if (idx == 2) | ||
tRect.origin += transform; | ||
|
||
sprite->setTextureRect(tRect); | ||
} | ||
|
||
void fixSprites() { | ||
CCSprite* sprites[3][3] = { | ||
{_topLeft, _top, _topRight}, | ||
{_left, _centre, _right}, | ||
{_bottomLeft, _bottom, _bottomRight} | ||
}; | ||
|
||
auto halfSize = getContentSize() / 2; | ||
|
||
for (int i = 0; i < 3; ++i) { | ||
for (int j = 0; j < 3; ++j) { | ||
auto sprite = sprites[i][j]; | ||
|
||
auto tRect = sprite->getTextureRect(); | ||
auto diff = tRect.size - halfSize; | ||
diff = CCSize(fmax(0, diff.width), fmax(0, diff.height)); | ||
|
||
transformSprite(sprite, CCSize(diff.width, 0), j); | ||
transformSprite(sprite, CCSize(0, diff.height), i); | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
#include <chrono> | ||
#include <thread> | ||
#include <unordered_map> | ||
#include <string> | ||
#include <functional> | ||
|
||
/** | ||
* https://github.com/sol-prog/cpp17-filewatcher/blob/master/FileWatcher.h | ||
*/ | ||
|
||
// Define available file changes | ||
enum class FileStatus {created, modified, erased}; | ||
|
||
class FileWatcher { | ||
public: | ||
std::string path_to_watch; | ||
// Time interval at which we check the base folder for changes | ||
std::chrono::duration<int, std::milli> delay; | ||
|
||
// Keep a record of files from the base directory and their last modification time | ||
FileWatcher(std::string path_to_watch, std::chrono::duration<int, std::milli> delay) : path_to_watch{path_to_watch}, delay{delay} { | ||
for(auto &file : std::filesystem::recursive_directory_iterator(path_to_watch)) { | ||
paths_[file.path().string()] = std::filesystem::last_write_time(file); | ||
} | ||
} | ||
|
||
// Monitor "path_to_watch" for changes and in case of a change execute the user supplied "action" function | ||
void start(const std::function<void (std::string, FileStatus)> &action) { | ||
while(running_) { | ||
// Wait for "delay" milliseconds | ||
std::this_thread::sleep_for(delay); | ||
|
||
auto it = paths_.begin(); | ||
while (it != paths_.end()) { | ||
if (!std::filesystem::exists(it->first)) { | ||
action(it->first, FileStatus::erased); | ||
it = paths_.erase(it); | ||
} | ||
else { | ||
it++; | ||
} | ||
} | ||
|
||
// Check if a file was created or modified | ||
for(auto &file : std::filesystem::recursive_directory_iterator(path_to_watch)) { | ||
auto current_file_last_write_time = std::filesystem::last_write_time(file); | ||
|
||
// File creation | ||
if(!contains(file.path().string())) { | ||
paths_[file.path().string()] = current_file_last_write_time; | ||
action(file.path().string(), FileStatus::created); | ||
// File modification | ||
} else { | ||
if(paths_[file.path().string()] != current_file_last_write_time) { | ||
paths_[file.path().string()] = current_file_last_write_time; | ||
action(file.path().string(), FileStatus::modified); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
private: | ||
std::unordered_map<std::string, std::filesystem::file_time_type> paths_; | ||
bool running_ = true; | ||
|
||
// Check if "paths_" contains a given key | ||
// If your compiler supports C++20 use paths_.contains(key) instead of this function | ||
bool contains(const std::string &key) { | ||
auto el = paths_.find(key); | ||
return el != paths_.end(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <Geode/Geode.hpp> | ||
#include <Geode/modify/GameManager.hpp> | ||
#include <Geode/modify/CCLabelBMFont.hpp> | ||
#include <Geode/modify/GJBaseGameLayer.hpp> | ||
#include <Geode/modify/CCSpriteBatchNode.hpp> | ||
|
||
using namespace geode::prelude; | ||
|
||
bool s_isInCreateTextLayers = false; | ||
|
||
class $modify(GJBaseGameLayer) { | ||
|
||
void createTextLayers(){ | ||
|
||
s_isInCreateTextLayers = true; | ||
GJBaseGameLayer::createTextLayers(); | ||
s_isInCreateTextLayers = false; | ||
|
||
} | ||
}; | ||
|
||
class $modify(CCSpriteBatchNode) { | ||
|
||
bool initWithTexture(CCTexture2D* texture, unsigned int capacity){ | ||
|
||
if(s_isInCreateTextLayers && texture == CCTextureCache::sharedTextureCache()->addImage("bigFont.png", false)){ | ||
return CCSpriteBatchNode::initWithTexture(CCTextureCache::sharedTextureCache()->addImage("bigFont.png"_spr, false), capacity); | ||
} | ||
return CCSpriteBatchNode::initWithTexture(texture, capacity); | ||
} | ||
}; | ||
|
||
|
||
class $modify(CCLabelBMFont) { | ||
|
||
static CCLabelBMFont* createBatched(const char* str, const char* fntFile, CCArray* a, int a1){ | ||
|
||
if(strcmp(fntFile, "bigFont.fnt") == 0){ | ||
fntFile = "bigFont.fnt"_spr; | ||
} | ||
return CCLabelBMFont::createBatched(str, fntFile, a, a1); | ||
} | ||
}; | ||
|
||
class $modify(GameManager) { | ||
|
||
const char* getFontTexture(int val){ | ||
|
||
if(val > 58){ | ||
val = 59; | ||
} | ||
loadFont(val); | ||
if(val != 0){ | ||
CCString* str = CCString::createWithFormat("gjFont%02d.png", val); | ||
return str->getCString(); | ||
} | ||
|
||
return "bigFont.png"_spr; | ||
} | ||
|
||
void loadFont(int val){ | ||
|
||
if(val > 58){ | ||
val = 59; | ||
} | ||
|
||
if(val != m_loadedFont){ | ||
if(m_loadedFont != 0){ | ||
CCTextureCache::sharedTextureCache()->removeTextureForKey(CCString::createWithFormat("gjFont%02d.png", m_loadedFont)->getCString()); | ||
} | ||
if(val == 0){ | ||
CCTextureCache::sharedTextureCache()->addImage("bigFont.png"_spr, false); | ||
} | ||
else { | ||
CCTextureCache::sharedTextureCache()->addImage(CCString::createWithFormat("gjFont%02d.png", val)->getCString(), false); | ||
} | ||
} | ||
m_loadedFont = val; | ||
} | ||
|
||
}; |
Empty file.
Oops, something went wrong.