Skip to content

Commit

Permalink
Merge branch 'master' into handle
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Dec 12, 2023
2 parents d6ae8b0 + e03802c commit ee5eb0c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 23 deletions.
88 changes: 66 additions & 22 deletions VortexEngine/src/Menus/MenuList/Randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,51 +138,95 @@ void Randomizer::onLongClick()

bool Randomizer::reRoll()
{
#if VORTEX_SLIM == 0
if (m_targetLeds == MAP_LED(LED_MULTI)) {
if (!reRollMulti()) {
return false;
}
}
#endif
if (!reRollSingles()) {
return false;
}
// initialize the mode with the new pattern and colorset
m_previewMode.init();
return true;
}

void Randomizer::showRandomizationSelect()
{
// show iterating rainbow if they are randomizing color, otherwise 0 sat if they
// are only randomizing the pattern
Leds::setAll(HSVColor(m_displayHue++, (m_flags & RANDOMIZE_COLORSET) * 255, 84));
if (m_flags & RANDOMIZE_PATTERN) {
// this is blinking the light to off so the params are switched but still effectively correct
Leds::blinkAll(DOPS_ON_DURATION, DOPS_OFF_DURATION);
}
// render the click selection blink
Menus::showSelection();
}

#if VORTEX_SLIM == 0
bool Randomizer::reRollMulti()
{
if (m_flags & RANDOMIZE_PATTERN) {
// TODO: Roll custom multi pattern?
//if (m_advanced) {
// if (!rollCustomPattern(ctx, &m_previewMode, pos)) {
// ERROR_LOG("Failed to roll custom pattern");
// return false;
// }
//}
if (!m_previewMode.setPattern(rollMultiLedPatternID(m_multiRandCtx), LED_MULTI)) {
ERROR_LOG("Failed to select pattern");
return false;
}
}
if (m_flags & RANDOMIZE_COLORSET) {
if (!m_previewMode.setColorset(rollColorset(m_multiRandCtx), LED_MULTI)) {
ERROR_LOG("Failed to roll new colorset");
return false;
}
}
return true;
}

PatternID Randomizer::rollMultiLedPatternID(Random &ctx)
{
return (PatternID)ctx.next8(PATTERN_MULTI_FIRST, PATTERN_MULTI_LAST);
}
#endif

bool Randomizer::reRollSingles()
{
// re-roll each led position with it's respective random context
MAP_FOREACH_LED(m_targetLeds) {
// grab local reference to the target random context
Random &ctx = m_singlesRandCtx[pos];
if (m_flags & RANDOMIZE_PATTERN) {
// roll a new pattern
// in advanced mode, when not randomizing the multi position, use a
// special function to randomize totally custom led pattern timings
if (m_advanced) {
if (!rollCustomPattern(ctx, &m_previewMode, pos)) {
ERROR_LOG("Failed to roll new pattern");
ERROR_LOG("Failed to roll custom pattern");
return false;
}
} else {
if (!m_previewMode.setPattern(rollSingleLedPatternID(ctx), pos)) {
ERROR_LOG("Failed to roll new pattern");
ERROR_LOG("Failed to select pattern");
return false;
}
}
}
if (m_flags & RANDOMIZE_COLORSET) {
// roll a new colorset
if (!m_previewMode.setColorset(rollColorset(ctx), pos)) {
ERROR_LOG("Failed to roll new colorset");
return false;
}
}
}
// initialize the mode with the new pattern and colorset
m_previewMode.init();
DEBUG_LOGF("Randomized Led %u set with randomization technique %u, %u colors, and Pattern number %u",
pos, randType, randomSet.numColors(), newPat);
return true;
}

void Randomizer::showRandomizationSelect()
{
// show iterating rainbow if they are randomizing color, otherwise 0 sat if they
// are only randomizing the pattern
Leds::setAll(HSVColor(m_displayHue++, (m_flags & RANDOMIZE_COLORSET) * 255, 84));
if (m_flags & RANDOMIZE_PATTERN) {
// this is blinking the light to off so the params are switched but still effectively correct
Leds::blinkAll(DOPS_ON_DURATION, DOPS_OFF_DURATION);
}
// render the click selection blink
Menus::showSelection();
}

PatternID Randomizer::rollSingleLedPatternID(Random &ctx)
{
PatternID newPat;
Expand Down
9 changes: 8 additions & 1 deletion VortexEngine/src/Menus/MenuList/Randomizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ class Randomizer : public Menu
bool reRoll();

private:
// random context for each led and led multi (LED_COUNT + 1)
// random context for each single led
Random m_singlesRandCtx[LED_COUNT];
#if VORTEX_SLIM == 0
// random context for the multi led position
Random m_multiRandCtx;
#endif

Expand Down Expand Up @@ -61,6 +62,12 @@ class Randomizer : public Menu
// show the randomization type selection
void showRandomizationSelect();

// main reRoll functions
#if VORTEX_SLIM == 0
bool reRollMulti();
PatternID rollMultiLedPatternID(Random &ctx);
#endif
bool reRollSingles();
PatternID rollSingleLedPatternID(Random &ctx);

// generate a random colorset with a random context
Expand Down

0 comments on commit ee5eb0c

Please sign in to comment.