|
4 | 4 |
|
5 | 5 | bool blockKeys = false; |
6 | 6 |
|
| 7 | +static std::mt19937 mt{ static_cast<std::mt19937::result_type>( |
| 8 | + std::chrono::steady_clock::now().time_since_epoch().count() |
| 9 | +) }; |
| 10 | + |
7 | 11 | float randomNumberInAGivenRangeThatGetsAddedOrRemovedFromADifferentNumber(float range) { // thanks cvolton for this amazing name |
8 | | - return static_cast<float>(rand() % static_cast<int>(range * 100 + 1)) / 100.f - (range / 2.f); |
| 12 | + return static_cast<float>(mt() % static_cast<int>(range * 100 + 1)) / 100.f - (range / 2.f); |
9 | 13 | } |
10 | 14 |
|
11 | 15 | void DeltaruneAlertLayer::initMaps() { |
@@ -491,6 +495,23 @@ void DeltaruneAlertLayer::progressText() { |
491 | 495 | schedule(schedule_selector(DeltaruneAlertLayer::rollText), pause / 30); |
492 | 496 | } |
493 | 497 |
|
| 498 | +void DeltaruneAlertLayer::handleAprilFools() { |
| 499 | + auto& nameToFile = m_fields->nameToFile; |
| 500 | + |
| 501 | + time_t t = time(nullptr); |
| 502 | + struct tm now; |
| 503 | + |
| 504 | + if (localtime_s(&now, &t) != 0) |
| 505 | + return; |
| 506 | + |
| 507 | + if (now.tm_mon != 3 || now.tm_mday != 1) |
| 508 | + return; |
| 509 | + |
| 510 | + auto randomSound = nameToFile.begin(); |
| 511 | + std::advance(randomSound, mt() % nameToFile.size()); |
| 512 | + m_fields->textSound = randomSound->first; |
| 513 | +} |
| 514 | + |
494 | 515 | void DeltaruneAlertLayer::rollText(float dt) { |
495 | 516 | int& waitQueue = m_fields->waitQueue; |
496 | 517 | int& linesProgressed = m_fields->linesProgressed; |
@@ -578,22 +599,25 @@ void DeltaruneAlertLayer::rollText(float dt) { |
578 | 599 | } |
579 | 600 | } |
580 | 601 | auto& nameToFile = m_fields->nameToFile; |
581 | | - auto const textSound = m_fields->textSound; |
| 602 | + auto& textSound = m_fields->textSound; |
582 | 603 | auto const resFolder = Mod::get()->getResourcesDir(); |
583 | | - auto path = resFolder / fmt::format("{}.wav", nameToFile[textSound]); |
584 | 604 |
|
585 | 605 | if (nameToFile.find(textSound) == nameToFile.end()) return; |
586 | 606 |
|
587 | 607 | if (!playSound || playedSound) { |
588 | 608 | playedSound = false; |
589 | 609 | return; |
590 | 610 | } |
| 611 | + |
| 612 | + handleAprilFools(); |
| 613 | + |
591 | 614 | float pitch = 1.f; |
592 | 615 | playedSound = true; |
593 | 616 |
|
594 | 617 | auto& system = m_fields->system; |
595 | 618 | auto& channel = m_fields->channel; |
596 | 619 | auto& sound = m_fields->sound; |
| 620 | + auto path = resFolder / fmt::format("{}.wav", nameToFile[textSound]); |
597 | 621 |
|
598 | 622 | if (textSound == "Queen") |
599 | 623 | pitch = 1 + randomNumberInAGivenRangeThatGetsAddedOrRemovedFromADifferentNumber(0.2f); |
|
0 commit comments