Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
- Move the rainbow trail shit to its own header/source file combo
- Use a ternary for mirroring the players instead of if/else
- Use a switch statement for HSVtoRGB instead of if/else if/else
- Use snake_case in some places
  • Loading branch information
mrcryostat committed Apr 25, 2024
1 parent 31176a2 commit de46cd9
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 105 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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 @@
"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",
Expand Down
131 changes: 29 additions & 102 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,123 +4,50 @@
#include <Geode/modify/CCMotionStreak.hpp>
#include <Geode/modify/PlayLayer.hpp>
#include <Geode/modify/PlayerObject.hpp>
#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<double>("speed");
float saturation = Mod::get()->getSettingValue<double>("saturation");
bool mirror_players = Mod::get()->getSettingValue<bool>("mirror-players");
float speed = Mod::get()->getSettingValue<double>("speed");
float saturation = Mod::get()->getSettingValue<double>("saturation");
bool mirror_players = Mod::get()->getSettingValue<bool>("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<bool>("enable");
bool noRegularTrail = Mod::get()->getSettingValue<bool>("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<bool>("enable");
bool noRegularTrail = Mod::get()->getSettingValue<bool>("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);
}
}
}
}
}
};
2 changes: 1 addition & 1 deletion src/pause_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct GayPauseLayer : Modify<GayPauseLayer, PauseLayer> {
);

settingsBtn->setID("gay-settings-button"_spr);
settingsBtn->setPosition(CCPoint{ 30, 30 });
settingsBtn->setPosition(CCPoint{ 40, 40 });
ccmenu->addChild(settingsBtn);

this->addChild(ccmenu);
Expand Down
72 changes: 72 additions & 0 deletions src/rainbow_trail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "rainbow_trail.hpp"

#include <cmath>

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<int>(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;
}
10 changes: 10 additions & 0 deletions src/rainbow_trail.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <Geode/cocos/include/ccTypes.h>

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;
};

0 comments on commit de46cd9

Please sign in to comment.