From d2ae53b2c35c59e3a3bd124fb17351220857459d Mon Sep 17 00:00:00 2001 From: profezzorn Date: Sun, 13 Oct 2024 22:17:46 -0500 Subject: [PATCH] add color playing to sound queue --- sound/sound_queue.h | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/sound/sound_queue.h b/sound/sound_queue.h index d911c3786..2a2dd0106 100644 --- a/sound/sound_queue.h +++ b/sound/sound_queue.h @@ -6,17 +6,33 @@ struct SoundToPlay { Effect* effect_; int selection_; - SoundToPlay() :filename_(nullptr), effect_(nullptr) {} - explicit SoundToPlay(const char* file) : filename_(file){ } + SoundToPlay() :filename_(nullptr), effect_(nullptr), selection_(-1) {} + explicit SoundToPlay(const char* file) : filename_(file) { } SoundToPlay(Effect* effect, int selection = -1) : filename_(nullptr), effect_(effect), selection_(selection) {} + SoundToPlay(uint8_t R, uint8_t G, uint8_t B) :filename_(nullptr), effect_(nullptr), selection_((R << 16) + (G << 8) + B) {} bool Play(BufferedWavPlayer* player) { - if (filename_) return player->PlayInCurrentDir(filename_); - effect_->Select(selection_); - player->PlayOnce(effect_); - return true; - } + if (filename_) { + return player->PlayInCurrentDir(filename_); + } + if (effect_) { + effect_->Select(selection_); + player->PlayOnce(effect_); + return true; + } + // color + char filename[32]; + strcpy(filename, "colors/"); + char* tmp = filename + strlen(filename); + int N = selection_; + for (int j = 0; j < 6; j++) { + *(tmp++) = "0123456789abcdef"[(N >> 20) & 0xf]; + N <<= 4; + } + strcpy(tmp, ".wav"); + return player->PlayInCurrentDir(filename); + } bool isSet() { - return filename_ != nullptr || effect_ != nullptr; + return filename_ != nullptr || effect_ != nullptr || selection_ != -1; } };