Skip to content

Commit

Permalink
EVENTS!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Oct 27, 2024
1 parent ded8542 commit d5d4e14
Show file tree
Hide file tree
Showing 13 changed files with 453 additions and 459 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

project(MoreIcons VERSION 1.3.4)
project(MoreIcons VERSION 1.4.0)

add_library(${PROJECT_NAME} SHARED
src/classes/DummyNode.cpp
src/api/MoreIconsAPI.cpp
src/classes/LogCell.cpp
src/classes/LogLayer.cpp
src/hooks/AppDelegate.cpp
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ To use a custom icon, you will need to go into the icon kit. In the icon kit, th

To deselect a custom icon, use the first row of dots to go back to the default icons, and click on one of the default icons to select it.

## Mod Support
Here are some examples of how to support More Icons in your mod.
```cpp
// Get the player's icon (The parameter is the gamemode or the gamemode plus "-dual" if Separate Dual Icons is enabled)
Loader::get()->getLoadedMod("hiimjustin000.more_icons")->getSavedValue<std::string>("icon");
// Get the list of icons (The parameter is the gamemode plus the letter "s")
Loader::get()->getLoadedMod("hiimjustin000.more_icons")->getSavedValue<std::vector<std::string>>("icons");
// Change a SimplePlayer to a custom icon
DispatchEvent<SimplePlayer*, const std::string&, IconType>("hiimjustin000.more_icons/simple-player", simplePlayer, "my-icon", IconType::Icon).post();
// Change a GJRobotSprite to a custom icon
DispatchEvent<GJRobotSprite*, const std::string&>("hiimjustin000.more_icons/robot-sprite", robotSprite, "my-icon").post(); // Determines the icon type
DispatchEvent<GJRobotSprite*, const std::string&, IconType>("hiimjustin000.more_icons/robot-sprite", robotSprite, "my-icon", IconType::Robot).post();
// Change a PlayerObject to a custom icon
DispatchEvent<PlayerObject*, const std::string&>("hiimjustin000.more_icons/player-object", playerObject, "my-icon").post(); // Determines the icon type
DispatchEvent<PlayerObject*, const std::string&, IconType>("hiimjustin000.more_icons/player-object", playerObject, "my-icon", IconType::Icon).post();
```
## Credits
- [DeepResonanceX](https://gdbrowser.com/u/5668656) - Idea for the mod
- [hiimjustin000](https://gdbrowser.com/u/7466002) - Creator of the mod
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# More Icons Changelog
## v1.4.0 (2024-10-27)
- Merged the More Icons API into the mod
- Added support for events for other mods to use
- Fixed texture pack credits only showing up for cubes ([[#14](https://github.com/hiimjustin000/MoreIcons/issues/14)])

## v1.3.4 (2024-10-21)
- Moved some logic to More Icons API
- Tweaked the logo to add drop shadow
Expand Down
7 changes: 1 addition & 6 deletions 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.3.4",
"version": "v1.4.0",
"id": "hiimjustin000.more_icons",
"name": "More Icons",
"developer": "hiimjustin000",
Expand All @@ -15,11 +15,6 @@
"id": "geode.node-ids",
"version": ">=v1.12.0",
"importance": "required"
},
{
"id": "hiimjustin000.more_icons_api",
"version": ">=v1.0.0",
"importance": "required"
}
],
"resources": {
Expand Down
60 changes: 47 additions & 13 deletions src/MoreIcons.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
#include "MoreIcons.hpp"
#include <Geode/loader/Dispatch.hpp>

using namespace geode::prelude;

using SimplePlayerFilter = DispatchFilter<SimplePlayer*, const std::string&, IconType>;
using RobotSpriteFilter = DispatchFilter<GJRobotSprite*, const std::string&>;
using RobotSpriteTypeFilter = DispatchFilter<GJRobotSprite*, const std::string&, IconType>;
using PlayerObjectFilter = DispatchFilter<PlayerObject*, const std::string&>;
using PlayerObjectTypeFilter = DispatchFilter<PlayerObject*, const std::string&, IconType>;

$execute {
new EventListener<SimplePlayerFilter>(+[](SimplePlayer* player, const std::string& icon, IconType type) {
MoreIconsAPI::updateSimplePlayer(player, icon, type);
return ListenerResult::Stop;
}, SimplePlayerFilter("simple-player"_spr));

new EventListener<RobotSpriteFilter>(+[](GJRobotSprite* sprite, const std::string& icon) {
MoreIconsAPI::updateRobotSprite(sprite, icon);
return ListenerResult::Stop;
}, RobotSpriteFilter("robot-sprite"_spr));

new EventListener<RobotSpriteTypeFilter>(+[](GJRobotSprite* sprite, const std::string& icon, IconType type) {
MoreIconsAPI::updateRobotSprite(sprite, icon, type);
return ListenerResult::Stop;
}, RobotSpriteTypeFilter("robot-sprite"_spr));

new EventListener<PlayerObjectFilter>(+[](PlayerObject* object, const std::string& icon) {
MoreIconsAPI::updatePlayerObject(object, icon);
return ListenerResult::Stop;
}, PlayerObjectFilter("player-object"_spr));

new EventListener<PlayerObjectTypeFilter>(+[](PlayerObject* object, const std::string& icon, IconType type) {
MoreIconsAPI::updatePlayerObject(object, icon, type);
return ListenerResult::Stop;
}, PlayerObjectTypeFilter("player-object"_spr));
}

$on_mod(DataSaved) {
MoreIcons::saveTrails();
}
Expand Down Expand Up @@ -125,7 +159,7 @@ void MoreIcons::load(LoadingLayer* layer) {
CC_SAFE_RELEASE(image.dict);
}
if (image.index == 0) {
vectorForType(image.type).push_back(image.name);
MoreIconsAPI::vectorForType(image.type).push_back(image.name);
if (image.type != IconType::Special) infoForType(image.type)[image.name] = image.pack;
}
if (image.type == IconType::Special) {
Expand All @@ -144,16 +178,16 @@ void MoreIcons::load(LoadingLayer* layer) {

IMAGES.clear();
restoreSaved();
naturalSort(ICONS);
naturalSort(SHIPS);
naturalSort(BALLS);
naturalSort(UFOS);
naturalSort(WAVES);
naturalSort(ROBOTS);
naturalSort(SPIDERS);
naturalSort(SWINGS);
naturalSort(JETPACKS);
naturalSort(TRAILS);
naturalSort(MoreIconsAPI::ICONS);
naturalSort(MoreIconsAPI::SHIPS);
naturalSort(MoreIconsAPI::BALLS);
naturalSort(MoreIconsAPI::UFOS);
naturalSort(MoreIconsAPI::WAVES);
naturalSort(MoreIconsAPI::ROBOTS);
naturalSort(MoreIconsAPI::SPIDERS);
naturalSort(MoreIconsAPI::SWINGS);
naturalSort(MoreIconsAPI::JETPACKS);
naturalSort(MoreIconsAPI::TRAILS);

if (auto smallLabel2 = static_cast<CCLabelBMFont*>(layer->getChildByID("geode-small-label-2")))
smallLabel2->setString("");
Expand All @@ -162,7 +196,7 @@ void MoreIcons::load(LoadingLayer* layer) {

void MoreIcons::loadIcons(const std::vector<std::filesystem::path>& packs, const std::string& suffix, IconType type) {
int i = 0;
for (auto& packPath : packs) {
for (auto& packPath : packs) {
std::string packName;
std::string packID;
if (i != 0) {
Expand Down Expand Up @@ -365,7 +399,7 @@ void MoreIcons::loadIcon(const std::filesystem::path& path, const TexturePack& p
if (!std::filesystem::exists(fullTexturePath)) {
auto fallbackTexturePath = std::filesystem::path(plistPath).replace_extension(".png").string();
if (!std::filesystem::exists((fallbackTexturePath))) {
auto logMessage = fmt::format("{}: Texture file {} not found, no fallback", path.string(), texturePath);
auto logMessage = fmt::format("{}: Texture file {} not found, no fallback", path.string(), texturePath);
log::warn("{}", logMessage);
{
std::lock_guard lock(LOG_MUTEX);
Expand Down
Loading

0 comments on commit d5d4e14

Please sign in to comment.