aboutsummaryrefslogtreecommitdiff
path: root/game/preview
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-10 14:50:50 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-10 14:50:50 +0100
commit7aa07561a52016007ff852acefa4db68260f0f1e (patch)
treeac438e906e581ee68f9d065dea90a2cbb8436d15 /game/preview
parentd7c8cc30e1d37526cf142f950038500b96760514 (diff)
parent0f8bf257d86b5532f3d6f559e5368668c255af7c (diff)
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/game-improvements
Diffstat (limited to 'game/preview')
-rw-r--r--game/preview/PreviewReplaySubScript.cpp55
-rw-r--r--game/preview/PreviewReplaySubScript.h24
-rw-r--r--game/preview/PreviewStartRecSubScript.cpp20
-rw-r--r--game/preview/PreviewStartRecSubScript.h11
-rw-r--r--game/preview/PreviewStopRecSubScript.cpp20
-rw-r--r--game/preview/PreviewStopRecSubScript.h11
6 files changed, 141 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;
+}
diff --git a/game/preview/PreviewReplaySubScript.h b/game/preview/PreviewReplaySubScript.h
new file mode 100644
index 0000000..59b78c3
--- /dev/null
+++ b/game/preview/PreviewReplaySubScript.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "menus/IButtonScript.h"
+
+#include <crepe/api/Script.h>
+
+struct StartPreviewRecording : public crepe::Event {};
+struct StopPreviewRecording : public crepe::Event {};
+
+class PreviewReplaySubScript : public IButtonScript {
+public:
+ void init() override;
+ bool on_button_press(const crepe::ButtonPressEvent & e);
+
+private:
+ crepe::recording_t recording = 0;
+ bool start_recording();
+ bool stop_recording();
+ bool delete_recording();
+
+private:
+ bool record_saved = false;
+ bool record_started = false;
+};
diff --git a/game/preview/PreviewStartRecSubScript.cpp b/game/preview/PreviewStartRecSubScript.cpp
new file mode 100644
index 0000000..8a2f54c
--- /dev/null
+++ b/game/preview/PreviewStartRecSubScript.cpp
@@ -0,0 +1,20 @@
+#include "PreviewStartRecSubScript.h"
+#include "PreviewReplaySubScript.h"
+
+#include <crepe/api/AudioSource.h>
+#include <crepe/types.h>
+
+using namespace crepe;
+using namespace std;
+
+void PreviewStartRecSubScript::init() {
+ IButtonScript::init();
+ this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) {
+ return this->on_button_press(e);
+ });
+}
+
+bool PreviewStartRecSubScript::on_button_press(const ButtonPressEvent & e) {
+ this->trigger_event<StartPreviewRecording>();
+ return false;
+}
diff --git a/game/preview/PreviewStartRecSubScript.h b/game/preview/PreviewStartRecSubScript.h
new file mode 100644
index 0000000..a54a085
--- /dev/null
+++ b/game/preview/PreviewStartRecSubScript.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "menus/IButtonScript.h"
+
+#include <crepe/api/Script.h>
+
+class PreviewStartRecSubScript : public IButtonScript {
+public:
+ void init() override;
+ bool on_button_press(const crepe::ButtonPressEvent & e);
+};
diff --git a/game/preview/PreviewStopRecSubScript.cpp b/game/preview/PreviewStopRecSubScript.cpp
new file mode 100644
index 0000000..a229da8
--- /dev/null
+++ b/game/preview/PreviewStopRecSubScript.cpp
@@ -0,0 +1,20 @@
+#include "PreviewStopRecSubScript.h"
+#include "PreviewReplaySubScript.h"
+
+#include <crepe/api/AudioSource.h>
+#include <crepe/types.h>
+
+using namespace crepe;
+using namespace std;
+
+void PreviewStopRecSubScript::init() {
+ IButtonScript::init();
+ this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) {
+ return this->on_button_press(e);
+ });
+}
+
+bool PreviewStopRecSubScript::on_button_press(const ButtonPressEvent & e) {
+ this->trigger_event<StopPreviewRecording>();
+ return false;
+}
diff --git a/game/preview/PreviewStopRecSubScript.h b/game/preview/PreviewStopRecSubScript.h
new file mode 100644
index 0000000..b2dd73b
--- /dev/null
+++ b/game/preview/PreviewStopRecSubScript.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "menus/IButtonScript.h"
+
+#include <crepe/api/Script.h>
+
+class PreviewStopRecSubScript : public IButtonScript {
+public:
+ void init() override;
+ bool on_button_press(const crepe::ButtonPressEvent & e);
+};