aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/BehaviorScript.h
blob: 8d21a7229e1a20d49b6f57e2f7bea88c9d154487 (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
44
45
46
47
48
#pragma once

#include <memory>

#include "../Component.h"

namespace crepe {

class ScriptSystem;
class ComponentManager;
class Script;

class BehaviorScript : public Component {
protected:
	using Component::Component;
	//! Only ComponentManager is allowed to instantiate BehaviorScript
	friend class ComponentManager;

public:
	virtual ~BehaviorScript() = default;

public:
	/**
	 * \brief Set the concrete script of this component
	 *
	 * \tparam T Concrete script type (derived from \c crepe::Script)
	 *
	 * \returns Reference to BehaviorScript component (`*this`)
	 */
	template <class T>
	BehaviorScript & set_script();

protected:
	//! ScriptSystem needs direct access to the script instance
	friend class ScriptSystem;
	//! Flag to indicate if script->init() has been called already
	bool initialized = false;
	std::unique_ptr<Script> script = nullptr;

private:
	//! Script accesses the component manager directly via its parent
	// (BehaviorScript) reference
	friend class Script;
};

} // namespace crepe

#include "BehaviorScript.hpp"