Skip to content

Commit

Permalink
move chaos code to trail_customization
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBearodactyl committed Jul 4, 2024
1 parent 0a21f5c commit c0a9e86
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 61 deletions.
61 changes: 0 additions & 61 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <Geode/modify/PlayerObject.hpp>
#include <cmath>
#include <cocos2d.h>
#include <random>

#include "Geode/loader/ModEvent.hpp"
#include "Geode/modify/Modify.hpp"
Expand Down Expand Up @@ -153,66 +152,6 @@ struct MyPlayLayer : Modify<MyPlayLayer, PlayLayer> {
}
};

struct MyHardStreak : Modify<MyHardStreak, HardStreak> {
void addPoint(CCPoint p0) {
float max_wave_pulse_size = Mod::get()->getSettingValue<double>("max-wave-pulse-size");
float min_wave_pulse_size = Mod::get()->getSettingValue<double>("min-wave-pulse-size");
float max_wave_trail_size = Mod::get()->getSettingValue<double>("max-wave-trail-size");
float min_wave_trail_size = Mod::get()->getSettingValue<double>("min-wave-trail-size");
float min_y_pos_offset = Mod::get()->getSettingValue<double>("min-y-pos-offset");
float max_y_pos_offset = Mod::get()->getSettingValue<double>("max-y-pos-offset");
float min_x_pos_offset = Mod::get()->getSettingValue<double>("min-x-pos-offset");
float max_x_pos_offset = Mod::get()->getSettingValue<double>("max-x-pos-offset");
float skip_chance = Mod::get()->getSettingValue<double>("skip-chance");

bool chaos = Mod::get()->getSettingValue<bool>("chaos");

if (chaos) {
std::mt19937 rng(std::time(nullptr));
std::uniform_real_distribution<float> dist_pulse(min_wave_pulse_size, max_wave_pulse_size);
std::uniform_real_distribution<float> dist_trail(min_wave_trail_size, max_wave_trail_size);

auto random_float_pulse = [&]() { return dist_pulse(rng); };
auto random_float_trail = [&]() { return dist_trail(rng); };

std::vector<std::function<void()>> operations = {
[&]() { p0.x += random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.x -= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.x *= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.x /= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.y += random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.y -= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.y *= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.y /= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { m_waveSize += random_float_trail(); },
[&]() { m_waveSize -= random_float_trail(); },
[&]() { m_waveSize *= random_float_trail(); },
[&]() { m_waveSize /= random_float_trail(); },
[&]() { m_pulseSize += random_float_trail(); },
[&]() { m_pulseSize -= random_float_trail(); },
[&]() { m_pulseSize *= random_float_trail(); },
[&]() { m_pulseSize /= random_float_trail(); }};

std::bernoulli_distribution enable_op(skip_chance);

for (auto &op: operations) {
if (enable_op(rng)) {
op();
}
}
}

HardStreak::addPoint(p0);
}

float random_float(float min = -25.f, float max = 25.f) {
static std::random_device rd;
static std::mt19937 gen(rd());
std::uniform_real_distribution<float> dis(min, max);
return dis(gen);
}
};

$on_mod(Loaded) {
Mod::get()->addCustomSetting<SettingSectionValue>("gaydient-section", "none");
Mod::get()->addCustomSetting<SettingSectionValue>("chaos-section", "none");
Expand Down
64 changes: 64 additions & 0 deletions src/trail_customization/chaos_trail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <Geode/Geode.hpp>
#include <random>

using namespace geode::prelude;

struct MyHardStreak : Modify<MyHardStreak, HardStreak> {
void addPoint(CCPoint p0) {
float max_wave_pulse_size = Mod::get()->getSettingValue<double>("max-wave-pulse-size");
float min_wave_pulse_size = Mod::get()->getSettingValue<double>("min-wave-pulse-size");
float max_wave_trail_size = Mod::get()->getSettingValue<double>("max-wave-trail-size");
float min_wave_trail_size = Mod::get()->getSettingValue<double>("min-wave-trail-size");
float min_y_pos_offset = Mod::get()->getSettingValue<double>("min-y-pos-offset");
float max_y_pos_offset = Mod::get()->getSettingValue<double>("max-y-pos-offset");
float min_x_pos_offset = Mod::get()->getSettingValue<double>("min-x-pos-offset");
float max_x_pos_offset = Mod::get()->getSettingValue<double>("max-x-pos-offset");
float skip_chance = Mod::get()->getSettingValue<double>("skip-chance");

bool chaos = Mod::get()->getSettingValue<bool>("chaos");

if (chaos) {
std::mt19937 rng(std::time(nullptr));
std::uniform_real_distribution<float> dist_pulse(min_wave_pulse_size, max_wave_pulse_size);
std::uniform_real_distribution<float> dist_trail(min_wave_trail_size, max_wave_trail_size);

auto random_float_pulse = [&]() { return dist_pulse(rng); };
auto random_float_trail = [&]() { return dist_trail(rng); };

std::vector<std::function<void()>> operations = {
[&]() { p0.x += random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.x -= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.x *= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.x /= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.y += random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.y -= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.y *= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { p0.y /= random_float(min_x_pos_offset, max_y_pos_offset); },
[&]() { m_waveSize += random_float_trail(); },
[&]() { m_waveSize -= random_float_trail(); },
[&]() { m_waveSize *= random_float_trail(); },
[&]() { m_waveSize /= random_float_trail(); },
[&]() { m_pulseSize += random_float_trail(); },
[&]() { m_pulseSize -= random_float_trail(); },
[&]() { m_pulseSize *= random_float_trail(); },
[&]() { m_pulseSize /= random_float_trail(); }};

std::bernoulli_distribution enable_op(skip_chance);

for (auto &op: operations) {
if (enable_op(rng)) {
op();
}
}
}

HardStreak::addPoint(p0);
}

float random_float(float min = -25.f, float max = 25.f) {
static std::random_device rd;
static std::mt19937 gen(rd());
std::uniform_real_distribution<float> dis(min, max);
return dis(gen);
}
};

0 comments on commit c0a9e86

Please sign in to comment.