Skip to content

Commit

Permalink
I am so done with this on God
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Oct 11, 2024
1 parent cb57078 commit 8331c40
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 59 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

project(MoreIcons VERSION 1.2.6)
project(MoreIcons VERSION 1.2.7)

add_library(${PROJECT_NAME} SHARED
src/classes/DummyNode.cpp
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# More Icons Changelog
## v1.2.7 (2024-10-10)
- Fixed plist icons changing names

## v1.2.6 (2024-10-10)
- Fixed robots and spiders sometimes crashing the game
- Fixed icons with individual images being added multiple times
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"win": "2.206",
"mac": "2.206"
},
"version": "v1.2.6",
"version": "v1.2.7",
"id": "hiimjustin000.more_icons",
"name": "More Icons",
"developer": "hiimjustin000",
Expand Down
126 changes: 69 additions & 57 deletions src/MoreIcons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,37 +204,43 @@ void MoreIcons::loadIcon(const std::filesystem::path& path, IconType type) {

auto pathFilename = subEntryPath.filename().string();
auto fileQuality = kTextureQualityLow;
if (pathFilename.find("-uhd.png") != std::string::npos) {
auto hdExists = std::filesystem::exists(string::replace(subEntryPath.string(), "-uhd.png", "-hd.png"));
if (hdExists || textureQuality != kTextureQualityHigh) {
if (!hdExists) log::warn("Ignoring too high quality PNG file: {}", path.filename() / pathFilename);
if (pathFilename.ends_with("-uhd.png")) {
if (textureQuality != kTextureQualityHigh) {
log::warn("Ignoring too high quality PNG file: {}", subEntryPath.parent_path().filename() / pathFilename);
continue;
}
else fileQuality = kTextureQualityHigh;

fileQuality = kTextureQualityHigh;
}
else if (pathFilename.find("-hd.png") != std::string::npos) {
auto sdExists = std::filesystem::exists(string::replace(subEntryPath.string(), "-hd.png", ".png"));
if (sdExists || (textureQuality != kTextureQualityHigh && textureQuality != kTextureQualityMedium)) {
if (!sdExists) log::warn("Ignoring too high quality PNG file: {}", path.filename() / pathFilename);
else if (pathFilename.ends_with("-hd.png")) {
if (textureQuality != kTextureQualityHigh && textureQuality != kTextureQualityMedium) {
log::warn("Ignoring too high quality PNG file: {}", subEntryPath.parent_path().filename() / pathFilename);
continue;
}
else fileQuality = kTextureQualityMedium;
}

auto pngPath = subEntryPath.string();
auto noGraphicPngPath = string::replace(string::replace(pngPath, "-uhd.png", ".png"), "-hd.png", ".png");
auto possibleUHD = string::replace(noGraphicPngPath, ".png", "-uhd.png");
auto possibleHD = string::replace(noGraphicPngPath, ".png", "-hd.png");
auto usedTextureQuality = kTextureQualityLow;
if (textureQuality == kTextureQualityHigh && (fileQuality == kTextureQualityHigh || std::filesystem::exists(possibleUHD))) {
pngPath = possibleUHD;
usedTextureQuality = kTextureQualityHigh;
if (
std::filesystem::exists(replaceEnd(subEntryPath.string(), "-hd.png", "-uhd.png")) &&
textureQuality == kTextureQualityHigh
) continue;
else fileQuality = kTextureQualityMedium;
}
else if (textureQuality == kTextureQualityMedium && (fileQuality == kTextureQualityMedium || std::filesystem::exists(possibleHD))) {
pngPath = possibleHD;
usedTextureQuality = kTextureQualityMedium;
else {
if (
std::filesystem::exists(replaceEnd(subEntryPath.string(), ".png", "-uhd.png")) &&
textureQuality == kTextureQualityHigh
) continue;
else if (
std::filesystem::exists(replaceEnd(subEntryPath.string(), ".png", "-hd.png")) &&
(textureQuality == kTextureQualityMedium || textureQuality == kTextureQualityHigh)
) continue;
else fileQuality = kTextureQualityLow;
}

auto pngPath = subEntryPath.string();
std::string noGraphicPngPath;
if (fileQuality == kTextureQualityHigh) noGraphicPngPath = replaceEnd(pngPath, "-uhd.png", ".png");
else if (fileQuality == kTextureQualityMedium) noGraphicPngPath = replaceEnd(pngPath, "-hd.png", ".png");
else noGraphicPngPath = pngPath;
auto image = new CCImage();
if (image->initWithImageFileThreadSafe(pngPath.c_str())) {
std::lock_guard lock(IMAGE_MUTEX);
Expand All @@ -257,47 +263,53 @@ void MoreIcons::loadIcon(const std::filesystem::path& path, IconType type) {
else if (std::filesystem::is_regular_file(path)) {
if (path.extension() != ".plist") return;

auto name = string::replace(string::replace(path.filename().string(), "-uhd.plist", ""), "-hd.plist", "");
auto pathFilename = path.filename().string();
auto fileQuality = kTextureQualityLow;
if (pathFilename.ends_with("-uhd.plist")) {
if (textureQuality != kTextureQualityHigh) {
log::warn("Ignoring too high quality plist file: {}", pathFilename);
return;
}

fileQuality = kTextureQualityHigh;
}
else if (pathFilename.ends_with("-hd.plist")) {
if (textureQuality != kTextureQualityHigh && textureQuality != kTextureQualityMedium) {
log::warn("Ignoring too high quality plist file: {}", pathFilename);
return;
}

if (
std::filesystem::exists(replaceEnd(path.string(), "-hd.plist", "-uhd.plist")) &&
textureQuality == kTextureQualityHigh
) return;
else fileQuality = kTextureQualityMedium;
}
else {
if (
std::filesystem::exists(replaceEnd(path.string(), ".plist", "-uhd.plist")) &&
textureQuality == kTextureQualityHigh
) return;
else if (
std::filesystem::exists(replaceEnd(path.string(), ".plist", "-hd.plist")) &&
(textureQuality == kTextureQualityMedium || textureQuality == kTextureQualityHigh)
) return;
else fileQuality = kTextureQualityLow;
}

auto plistPath = path.string();
std::string noGraphicPlistPath;
if (fileQuality == kTextureQualityHigh) noGraphicPlistPath = replaceEnd(plistPath, "-uhd.plist", ".plist");
else if (fileQuality == kTextureQualityMedium) noGraphicPlistPath = replaceEnd(plistPath, "-hd.plist", ".plist");
else noGraphicPlistPath = plistPath;
auto name = std::filesystem::path(noGraphicPlistPath).stem().string();
if (std::find(ALL.begin(), ALL.end(), name) != ALL.end()) {
DUPLICATES.push_back(name);
name += fmt::format("_{:02}", std::count(DUPLICATES.begin(), DUPLICATES.end(), name));
}
ALL.push_back(name);

sharedPool().detach_task([path, textureQuality, name, type] {
auto pathFilename = path.filename().string();
auto fileQuality = kTextureQualityLow;
if (pathFilename.find("-uhd.plist") != std::string::npos) {
auto hdExists = std::filesystem::exists(string::replace(path.string(), "-uhd.plist", "-hd.plist"));
if (hdExists || textureQuality != kTextureQualityHigh) {
if (!hdExists) log::warn("Ignoring too high quality plist file: {}", pathFilename);
return;
}
else fileQuality = kTextureQualityHigh;
}
else if (pathFilename.find("-hd.plist") != std::string::npos) {
auto sdExists = std::filesystem::exists(string::replace(path.string(), "-hd.plist", ".plist"));
if (sdExists || (textureQuality != kTextureQualityHigh && textureQuality != kTextureQualityMedium)) {
if (!sdExists) log::warn("Ignoring too high quality plist file: {}", pathFilename);
return;
}
else fileQuality = kTextureQualityMedium;
}

auto plistPath = path.string();
auto noGraphicPlistPath = string::replace(string::replace(plistPath, "-uhd.plist", ".plist"), "-hd.plist", ".plist");
auto possibleUHD = string::replace(noGraphicPlistPath, ".plist", "-uhd.plist");
auto possibleHD = string::replace(noGraphicPlistPath, ".plist", "-hd.plist");
auto usedTextureQuality = kTextureQualityLow;
if (textureQuality == kTextureQualityHigh && (fileQuality == kTextureQualityHigh || std::filesystem::exists(possibleUHD))) {
plistPath = possibleUHD;
usedTextureQuality = kTextureQualityHigh;
}
else if (textureQuality == kTextureQualityMedium && (fileQuality == kTextureQualityMedium || std::filesystem::exists(possibleHD))) {
plistPath = possibleHD;
usedTextureQuality = kTextureQualityMedium;
}

sharedPool().detach_task([path, textureQuality, name, plistPath, type] {
auto dict = CCDictionary::createWithContentsOfFileThreadSafe(plistPath.c_str());
auto frames = new CCDictionary();
for (auto [frameName, frame] : CCDictionaryExt<std::string, CCDictionary*>(static_cast<CCDictionary*>(dict->objectForKey("frames")))) {
Expand Down
5 changes: 5 additions & 0 deletions src/MoreIcons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ class MoreIcons {

static std::vector<std::filesystem::path> getTexturePacks();

static std::string replaceEnd(const std::string& str, const std::string& end, const std::string& replace, bool check = false) {
if (!check || str.ends_with(end)) return str.substr(0, str.size() - end.size()) + replace;
return str;
}

static void loadIcons(
const std::vector<std::filesystem::path>& packs, const std::string& suffix, IconType type
);
Expand Down

0 comments on commit 8331c40

Please sign in to comment.