diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-10 14:50:50 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-10 14:50:50 +0100 |
commit | 7aa07561a52016007ff852acefa4db68260f0f1e (patch) | |
tree | ac438e906e581ee68f9d065dea90a2cbb8436d15 /game/preview/PreviewReplaySubScript.cpp | |
parent | d7c8cc30e1d37526cf142f950038500b96760514 (diff) | |
parent | 0f8bf257d86b5532f3d6f559e5368668c255af7c (diff) |
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/game-improvements
Diffstat (limited to 'game/preview/PreviewReplaySubScript.cpp')
-rw-r--r-- | game/preview/PreviewReplaySubScript.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/game/preview/PreviewReplaySubScript.cpp b/game/preview/PreviewReplaySubScript.cpp new file mode 100644 index 0000000..580a608 --- /dev/null +++ b/game/preview/PreviewReplaySubScript.cpp @@ -0,0 +1,55 @@ +#include "PreviewReplaySubScript.h" +#include "Config.h" +#include "menus/ButtonReplaySubScript.h" +#include <crepe/api/AudioSource.h> +#include <crepe/types.h> + +using namespace crepe; +using namespace std; + +void PreviewReplaySubScript::init() { + IButtonScript::init(); + this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + this->subscribe<StopPreviewRecording>([this](const StopPreviewRecording & e) { + return this->stop_recording(); + }); + this->subscribe<DeleteRecordingEvent>([this](const DeleteRecordingEvent & e) { + return this->delete_recording(); + }); + this->subscribe<StartPreviewRecording>([this](const StartPreviewRecording & e) { + return this->start_recording(); + }); +} + +bool PreviewReplaySubScript::on_button_press(const ButtonPressEvent & e) { + if (DISABLE_REPLAY) return false; + replay.play(this->recording); + return false; +} +bool PreviewReplaySubScript::start_recording() { + if (DISABLE_REPLAY) return false; + if (record_saved) { + this->stop_recording(); + this->delete_recording(); + } + replay.record_start(); + this->record_started = true; + return false; +} + +bool PreviewReplaySubScript::stop_recording() { + if (DISABLE_REPLAY) return false; + if (this->record_started) this->recording = replay.record_end(); + this->record_saved = true; + return false; +} + +bool PreviewReplaySubScript::delete_recording() { + if (DISABLE_REPLAY) return false; + if (this->record_started) this->stop_recording(); + if (this->record_saved) replay.release(this->recording); + this->record_saved = false; + return false; +} |