aboutsummaryrefslogtreecommitdiff
path: root/game/menus/ButtonReplaySubScript.cpp
blob: 55e718d27d2b86ea31090d58e3b0a85ca84dd958 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "ButtonReplaySubScript.h"
#include "Config.h"
#include "MenusConfig.h"

#include "../Events.h"
#include <crepe/api/AudioSource.h>
#include <crepe/types.h>

using namespace crepe;
using namespace std;

void ButtonReplaySubScript::init() {
	IButtonScript::init();
	this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) {
		return this->on_button_press(e);
	});
	this->subscribe<EndGameEvent>([this](const EndGameEvent & e) {
		return this->set_recording();
	});
	this->subscribe<DeleteRecordingEvent>([this](const DeleteRecordingEvent & e) {
		return this->delete_recording();
	});
	if(DISABLE_REPLAY)return;
	replay.record_start();
}

bool ButtonReplaySubScript::on_button_press(const ButtonPressEvent & e) {
	if(DISABLE_REPLAY)return false;
	replay.play(this->recording);
	return false;
}

bool ButtonReplaySubScript::set_recording() {
	if(DISABLE_REPLAY)return false;
	this->recording = replay.record_end();
	return false;
}

bool ButtonReplaySubScript::delete_recording() {
	if(DISABLE_REPLAY)return false;
	replay.release(this->recording);
	return false;
}