From 6be4ca76d9aa4c65f38fc134c41cd0477a019c1e Mon Sep 17 00:00:00 2001 From: undefined06855 <98057141+undefined06855@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:33:34 +0000 Subject: [PATCH] log stuff + other stuff (v1.2.2) --- CMakeLists.txt | 2 +- TODO.txt | 2 +- about.md | 2 +- changelog.md | 3 +++ mod.json | 11 +++++++++-- src/CCAnimatedSprite.cpp | 3 ++- src/NinjaSwipeLayer.cpp | 27 ++++++++++++++------------- src/NinjaSwipeLayer.hpp | 2 +- src/utils/log.hpp | 29 +++++++++++++++++++++++++++++ src/utils/random.cpp | 3 ++- src/utils/random.hpp | 4 +--- 11 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 src/utils/log.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 085c9e6..c776ae0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64") set(CMAKE_CXX_VISIBILITY_PRESET hidden) -# add_definitions( -DDEBUG ) +# add_definitions( -DDEBUG_DRAW_NODE ) project(IconNinja VERSION 1.0.0) diff --git a/TODO.txt b/TODO.txt index 3638061..8af49a3 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,3 +1,3 @@ - Customisable swords (based on player colours, perhaps) - leaderboards??????????? -- screen shake + window shake if in windowed \ No newline at end of file +- window shake if in windowed \ No newline at end of file diff --git a/about.md b/about.md index 2b455a1..451f8a4 100644 --- a/about.md +++ b/about.md @@ -14,7 +14,7 @@ Planned Features: - Leaderboards Suggest features and report bugs at the github link in the bottom left! -This mod now has Known Players compatibility! Install the mod to be able to slice up your favourite GD players! +This mod has Known Players compatibility! Install the mod to be able to slice up your favourite GD players! --- diff --git a/changelog.md b/changelog.md index dfcd31d..6512dad 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,7 @@ # Icon Ninja Changelog +## v1.2.2 +- Added option to disable logging +- (Internal) Renamed debug flag to `-DDEBUG_DRAW_NODE` to prevent conflicts that may have been happening ## v1.2.1 - Made robots and spiders not animate while being flung - Made swing fire show all fires instead of the two by default diff --git a/mod.json b/mod.json index e063db3..8548e09 100644 --- a/mod.json +++ b/mod.json @@ -1,5 +1,5 @@ { - "geode": "4.0.1", + "geode": "4.1.0", "gd": { "win": "2.2074", "android": "2.2074" @@ -7,7 +7,7 @@ "id": "undefined0.icon_ninja", "name": "Icon Ninja", - "version": "v1.2.1", + "version": "v1.2.2", "developer": "undefined0", "description": "Makes killing icons like Fruit Ninja!", "tags": [ "joke", "offline", "modtober24" ], @@ -47,6 +47,7 @@ }, "particles": { "name": "Enable bomb particles", + "description": "Can be buggy at times, so has been disabled by default. Made by flingus!", "type": "bool", "default": false }, @@ -74,6 +75,12 @@ "arrows": true, "input": true } + }, + "enable-log": { + "name": "Enable logging", + "description": "Enables logging to help debugging the mod.", + "type": "bool", + "default": false } } } diff --git a/src/CCAnimatedSprite.cpp b/src/CCAnimatedSprite.cpp index 5ef3a87..cadad80 100644 --- a/src/CCAnimatedSprite.cpp +++ b/src/CCAnimatedSprite.cpp @@ -1,8 +1,9 @@ #include "CCAnimatedSprite.hpp" +#include "utils/log.hpp" void HookedCCAnimatedSprite::runAnimation(gd::string animID) { std::string replacement = getReplacementAnimID(animID); - geode::log::info("convert anim {} -> {}", animID, replacement); + ninja::log::info("convert anim {} -> {}", animID, replacement); CCAnimatedSprite::runAnimation(replacement); } diff --git a/src/NinjaSwipeLayer.cpp b/src/NinjaSwipeLayer.cpp index f6c8d58..6854820 100644 --- a/src/NinjaSwipeLayer.cpp +++ b/src/NinjaSwipeLayer.cpp @@ -1,6 +1,7 @@ #include "NinjaSwipeLayer.hpp" #include "MenuLayer.hpp" #include "utils/random.hpp" +#include "utils/log.hpp" #include "FlashbangLayer.hpp" NinjaSwipeLayer* NinjaSwipeLayer::create() { @@ -74,7 +75,7 @@ bool NinjaSwipeLayer::init() { scheduleUpdate(); -#ifdef DEBUG +#ifdef DEBUG_DRAW_NODE m_debugNode = cocos2d::CCDrawNode::create(); m_debugNode->init(); m_debugNode->setZOrder(999999); @@ -114,14 +115,14 @@ void NinjaSwipeLayer::checkSwipeIntersection(const cocos2d::CCPoint& from, const if (from.getDistanceSq(to) < .5f) return; if (m_isBombCurrentlyExploding) return; -#ifdef DEBUG +#ifdef DEBUG_DRAW_NODE m_debugLastCheckFrom = from; m_debugLastCheckTo = to; #endif for (auto player : m_players) { if (!player || player->retainCount() == 0) { - geode::log::warn("player is nullptr!"); + ninja::log::warn("player is nullptr!"); continue; } @@ -171,7 +172,7 @@ bool NinjaSwipeLayer::lineIntersectsCircle(const cocos2d::CCPoint& circleCenter, void NinjaSwipeLayer::killPlayer(MenuIcon* player) { if (player->m_type == MenuIconType::Bomb) { - geode::log::info("bomb!"); + ninja::log::info("bomb!"); m_isBombCurrentlyExploding = true; player->m_isBombExploding = true; if (geode::Mod::get()->getSettingValue("particles")) player->m_particles->removeFromParent(); @@ -242,7 +243,7 @@ void NinjaSwipeLayer::killPlayer(MenuIcon* player) { // auto skibidi = cocos2d::CCNode::create(); // skibidi->release(); // geode::Loader::get()->queueInMainThread([=]{ - // geode::log::info("{}", skibidi); + // ninja::log::info("{}", skibidi); // }); }) ) @@ -294,7 +295,7 @@ void NinjaSwipeLayer::update(float dt) { auto dir = cocos2d::CCDirector::sharedDirector(); if (player->getPositionY() <= -50.f || player->getPositionX() <= -50.f || player->getPositionX() >= dir->getScreenRight() + 50.f) { - geode::log::info("icon fell offscreen :broken_heart:"); + ninja::log::info("icon fell offscreen :broken_heart:"); playersToRemove.push_back(player); // offscreen, below starting point, remove and reset combo @@ -309,7 +310,7 @@ void NinjaSwipeLayer::update(float dt) { } if (m_players.size() == 0 && !m_waitingForNextSpawn && !m_isSendingOutSpree && !m_isBombCurrentlyExploding) { - geode::log::info("ran out! wait 1.5 secs, ill spawn some more"); + ninja::log::info("ran out! wait 1.5 secs, ill spawn some more"); // ran out! auto action = cocos2d::CCSequence::createWithTwoActions( cocos2d::CCDelayTime::create(1.5f), @@ -322,7 +323,7 @@ void NinjaSwipeLayer::update(float dt) { m_waitingForNextSpawn = true; } -#ifdef DEBUG +#ifdef DEBUG_DRAW_NODE m_debugNode->clear(); for (auto player : m_players) { float radius = player->getRadius(); @@ -378,7 +379,7 @@ void NinjaSwipeLayer::startShake() { // I shake it off, I shake it off (hoo-hoo-hoo) m_shakeTick = m_maxShakeTick; - geode::log::info("shakey bakey"); + ninja::log::info("shakey bakey"); } void NinjaSwipeLayer::removePlayer(MenuIcon* player) { @@ -392,7 +393,7 @@ void NinjaSwipeLayer::enterGameplay() { if (m_state == State::Gameplay) return; m_state = State::Gameplay; - geode::log::info("NINJA TIME BABY"); + ninja::log::info("NINJA TIME BABY"); auto menuLayer = static_cast(MenuLayer::get()); menuLayer->runEnterGameplayAnimations(); @@ -410,7 +411,7 @@ void NinjaSwipeLayer::exitGameplay(cocos2d::CCObject* sender) { if (m_state == State::Default) return; m_state = State::Default; - geode::log::info("no more ninja time :broken_heart:"); + ninja::log::info("no more ninja time :broken_heart:"); auto menuLayer = static_cast(MenuLayer::get()); menuLayer->runExitGameplayAnimations(); @@ -471,7 +472,7 @@ void NinjaSwipeLayer::spawnPlayers() { type = ninja::random::spawnTypeDistribution(ninja::random::gen); } while (type == m_lastSpawnType); - geode::log::info("spawning players (type: {})", type); + ninja::log::info("spawning players (type: {})", type); m_lastSpawnType = type; switch(type) { case 0: { @@ -550,5 +551,5 @@ void NinjaSwipeLayer::spawnPlayers() { } $on_mod(Loaded) { - geode::log::info("hi spaghettdev"); + ninja::log::info("hi spaghettdev"); } diff --git a/src/NinjaSwipeLayer.hpp b/src/NinjaSwipeLayer.hpp index 33edd5f..e08a207 100644 --- a/src/NinjaSwipeLayer.hpp +++ b/src/NinjaSwipeLayer.hpp @@ -12,7 +12,7 @@ class NinjaSwipeLayer : public cocos2d::CCLayer { static NinjaSwipeLayer* create(); bool init() override; -#ifdef DEBUG +#ifdef DEBUG_DRAW_NODE cocos2d::CCDrawNode* m_debugNode; cocos2d::CCPoint m_debugLastCheckFrom = {0, 0}; cocos2d::CCPoint m_debugLastCheckTo = {0, 0}; diff --git a/src/utils/log.hpp b/src/utils/log.hpp new file mode 100644 index 0000000..9f03588 --- /dev/null +++ b/src/utils/log.hpp @@ -0,0 +1,29 @@ +#pragma once +#include + +// lazy +#define LOG_ENABLE_CHECK geode::Mod::get()->getSettingValue("enable-log") + +namespace ninja::log { + +template +inline void debug(geode::log::impl::FmtStr str, Args&&... args) { + if (LOG_ENABLE_CHECK) geode::log::debug(str, std::forward(args)...); +} + +template +inline void info(geode::log::impl::FmtStr str, Args&&... args) { + if (LOG_ENABLE_CHECK) geode::log::info(str, std::forward(args)...); +} + +template +inline void warn(geode::log::impl::FmtStr str, Args&&... args) { + if (LOG_ENABLE_CHECK) geode::log::warn(str, std::forward(args)...); +} + +template +inline void error(geode::log::impl::FmtStr str, Args&&... args) { + if (LOG_ENABLE_CHECK) geode::log::error(str, std::forward(args)...); +} + +} diff --git a/src/utils/random.cpp b/src/utils/random.cpp index f3b6031..0f38660 100644 --- a/src/utils/random.cpp +++ b/src/utils/random.cpp @@ -1,5 +1,6 @@ #include #include "random.hpp" +#include "log.hpp" #include "../external/KnownPlayers.h" namespace ninja { @@ -29,7 +30,7 @@ PlayerObject* createRandomPlayerObject() { event.post(); if (!event.done) { - geode::log::warn("Known Players did not return event! Switching to fallback..."); + ninja::log::warn("Known Players did not return event! Switching to fallback..."); randomisePlayerObject(ret); } } else { diff --git a/src/utils/random.hpp b/src/utils/random.hpp index 6746a9b..8a1439c 100644 --- a/src/utils/random.hpp +++ b/src/utils/random.hpp @@ -1,8 +1,7 @@ #pragma once #include -namespace ninja { -namespace random { +namespace ninja::random { extern std::mt19937 gen; extern std::uniform_real_distribution startXDistribution; @@ -21,4 +20,3 @@ PlayerObject* createRandomPlayerObject(); void randomisePlayerObject(PlayerObject* player); } -}