diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c1ae08..ed23842 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,9 @@ file(GLOB_RECURSE SOURCES src/*.cpp ) -add_library(${PROJECT_NAME} SHARED ${SOURCES}) +add_library(${PROJECT_NAME} SHARED ${SOURCES} + src/rainbow_trail.hpp + src/rainbow_trail.cpp) if (NOT DEFINED ENV{GEODE_SDK}) message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode") diff --git a/mod.json b/mod.json index d9d89b3..b0d0376 100644 --- a/mod.json +++ b/mod.json @@ -5,7 +5,7 @@ "mac": "2.200", "android": "2.205" }, - "version": "v1.0.12", + "version": "v1.0.13", "id": "the_bearodactyl.gay-wave-trail", "name": "Gay Wave Trail", "developer": "The Bearodactyl", diff --git a/src/main.cpp b/src/main.cpp index 2d84f37..623dba4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,123 +4,50 @@ #include #include #include +#include "rainbow_trail.hpp" using namespace geode::prelude; -// thanks to shadowforce78 -void HSVtoRGBbutDifferentIGuess(float &fR, float &fG, float &fB, float &fH, - float &fS, float &fV) { - float fC = fV * fS; // Chroma - float fHPrime = fmod(fH / 60.0, 6); - float fX = fC * (1 - fabs(fmod(fHPrime, 2) - 1)); - float fM = fV - fC; - - if (0 <= fHPrime && fHPrime < 1) { - fR = fC; - fG = fX; - fB = 0; - } else if (1 <= fHPrime && fHPrime < 2) { - fR = fX; - fG = fC; - fB = 0; - } else if (2 <= fHPrime && fHPrime < 3) { - fR = 0; - fG = fC; - fB = fX; - } else if (3 <= fHPrime && fHPrime < 4) { - fR = 0; - fG = fX; - fB = fC; - } else if (4 <= fHPrime && fHPrime < 5) { - fR = fX; - fG = 0; - fB = fC; - } else if (5 <= fHPrime && fHPrime < 6) { - fR = fC; - fG = 0; - fB = fX; - } else { - fR = 0; - fG = 0; - fB = 0; - } - - fR += fM; - fG += fM; - fB += fM; -} - -// thanks to shadowforce78 -float g = 0; - -cocos2d::_ccColor3B getRainbow(float offset, float saturation) { - float R; - float G; - float B; - - float hue = fmod(g + offset, 360); - float sat = saturation / 100.0; - float vc = 1; - HSVtoRGBbutDifferentIGuess(R, G, B, hue, sat, vc); - - cocos2d::_ccColor3B out; - out.r = R * 255; - out.g = G * 255; - out.b = B * 255; - return out; -} - class $modify(PlayerObject) { - void flashPlayer(float p0, float p1, cocos2d::ccColor3B mainColor, cocos2d::ccColor3B secondColor) { - } + void flashPlayer(float p0, float p1, cocos2d::ccColor3B mainColor, cocos2d::ccColor3B secondColor) {} }; class $modify(PlayLayer) { - void postUpdate(float p0) { - PlayLayer::postUpdate(p0); + void postUpdate(float p0) { + PlayLayer::postUpdate(p0); - float speed = Mod::get()->getSettingValue("speed"); - float saturation = Mod::get()->getSettingValue("saturation"); - bool mirror_players = Mod::get()->getSettingValue("mirror-players"); + float speed = Mod::get()->getSettingValue("speed"); + float saturation = Mod::get()->getSettingValue("saturation"); + bool mirror_players = Mod::get()->getSettingValue("mirror-players"); - if (g >= 360) { - g = 0; - } else { - g += speed / 10; - } - - auto rainbowColor = getRainbow(0, saturation); - auto rainbowColor2 = getRainbow(180, saturation); - auto rainbowColor3 = getRainbow(90, saturation); - bool enable = Mod::get()->getSettingValue("enable"); - bool noRegularTrail = Mod::get()->getSettingValue("no-reg-trail"); + if (RainbowTrail::g >= 360) { + RainbowTrail::g = 0; + } else { + RainbowTrail::g += speed / 10; + } - if (m_player1->m_isDart && noRegularTrail) { - m_player1->m_regularTrail->setVisible(false); - } + _ccColor3B rainbowColor = RainbowTrail::get_rainbow(0, saturation); + _ccColor3B rainbowColor2 = RainbowTrail::get_rainbow(180, saturation); + _ccColor3B rainbowColor3 = RainbowTrail::get_rainbow(90, saturation); + bool enable = Mod::get()->getSettingValue("enable"); + bool noRegularTrail = Mod::get()->getSettingValue("no-reg-trail"); - if (m_player2->m_isDart && noRegularTrail) { - m_player2->m_regularTrail->setVisible(false); - } - - if (enable == true) { - if (!mirror_players) { - if (m_player1->m_waveTrail) { - m_player1->m_waveTrail->setColor(rainbowColor); + if (m_player1->m_isDart && noRegularTrail) { + m_player1->m_regularTrail->setVisible(false); } - if (m_player2->m_waveTrail) { - m_player2->m_waveTrail->setColor(rainbowColor2); - } - } else { - if (m_player1->m_waveTrail) { - m_player1->m_waveTrail->setColor(rainbowColor); + if (m_player2->m_isDart && noRegularTrail) { + m_player2->m_regularTrail->setVisible(false); } - if (m_player2->m_waveTrail) { - m_player2->m_waveTrail->setColor(rainbowColor); + if (enable) { + if (m_player1->m_waveTrail) { + m_player1->m_waveTrail->setColor(rainbowColor); + } + + if (m_player2->m_waveTrail) { + m_player2->m_waveTrail->setColor(!mirror_players ? rainbowColor2 : rainbowColor); + } } - } } - } }; diff --git a/src/pause_button.cpp b/src/pause_button.cpp index 0336698..98c4fc7 100644 --- a/src/pause_button.cpp +++ b/src/pause_button.cpp @@ -30,7 +30,7 @@ struct GayPauseLayer : Modify { ); settingsBtn->setID("gay-settings-button"_spr); - settingsBtn->setPosition(CCPoint{ 30, 30 }); + settingsBtn->setPosition(CCPoint{ 40, 40 }); ccmenu->addChild(settingsBtn); this->addChild(ccmenu); diff --git a/src/rainbow_trail.cpp b/src/rainbow_trail.cpp new file mode 100644 index 0000000..e86a5ba --- /dev/null +++ b/src/rainbow_trail.cpp @@ -0,0 +1,72 @@ +#include "rainbow_trail.hpp" + +#include + +void RainbowTrail::hsv_to_rgb(float &fR, float &fG, float &fB, float &fH, float &fS, float &fV) { + float fC = fV * fS; // Chroma + float fHPrime = fmod(fH / 60.0, 6); + float fX = fC * (1 - fabs(fmod(fHPrime, 2) - 1)); + float fM = fV - fC; + + int hue_segment = static_cast(fHPrime); + switch (hue_segment) { + case 0: + fR = fC; + fG = fX; + fB = 0; + break; + case 1: + fR = fX; + fG = fC; + fB = 0; + break; + case 2: + fR = 0; + fG = fC; + fB = fX; + break; + case 3: + fR = 0; + fG = fX; + fB = fC; + break; + case 4: + fR = fX; + fG = 0; + fB = fC; + break; + case 5: + fR = fC; + fG = 0; + fB = fX; + break; + default: + fR = 0; + fG = 0; + fB = 0; + break; + } + + fR += fM; + fG += fM; + fB += fM; +} + +float RainbowTrail::g = 0; + +cocos2d::_ccColor3B RainbowTrail::get_rainbow(float offset, float saturation) { + float R; + float G; + float B; + + float hue = fmod(g + offset, 360); + float sat = saturation / 100.0; + float vc = 1; + hsv_to_rgb(R, G, B, hue, sat, vc); + + cocos2d::_ccColor3B out; + out.r = R * 255; + out.g = G * 255; + out.b = B * 255; + return out; +} diff --git a/src/rainbow_trail.hpp b/src/rainbow_trail.hpp new file mode 100644 index 0000000..46a3144 --- /dev/null +++ b/src/rainbow_trail.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include + +class RainbowTrail { +public: + static void hsv_to_rgb(float &fR, float &fG, float &fB, float &fH, float &fS, float &fV); + static cocos2d::_ccColor3B get_rainbow(float offset, float saturation); + static float g; +};