aboutsummaryrefslogtreecommitdiff
path: root/game/preview
diff options
context:
space:
mode:
Diffstat (limited to 'game/preview')
-rw-r--r--game/preview/PreviewReplaySubScript.cpp56
-rw-r--r--game/preview/PreviewReplaySubScript.h23
-rw-r--r--game/preview/PreviewStartRecSubScript.cpp21
-rw-r--r--game/preview/PreviewStartRecSubScript.h11
-rw-r--r--game/preview/PreviewStopRecSubScript.cpp21
-rw-r--r--game/preview/PreviewStopRecSubScript.h11
6 files changed, 143 insertions, 0 deletions
diff --git a/game/preview/PreviewReplaySubScript.cpp b/game/preview/PreviewReplaySubScript.cpp
new file mode 100644
index 0000000..51c27aa
--- /dev/null
+++ b/game/preview/PreviewReplaySubScript.cpp
@@ -0,0 +1,56 @@
+#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..ca5bd08
--- /dev/null
+++ b/game/preview/PreviewReplaySubScript.h
@@ -0,0 +1,23 @@
+#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..194f849
--- /dev/null
+++ b/game/preview/PreviewStartRecSubScript.cpp
@@ -0,0 +1,21 @@
+#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..c674a8b
--- /dev/null
+++ b/game/preview/PreviewStopRecSubScript.cpp
@@ -0,0 +1,21 @@
+#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);
+};