aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Script.h
blob: d543df8f9099b37e8103be7379f71c8899aec78a (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
#pragma once

#include <vector>

namespace crepe {
class ScriptSystem;
}

namespace crepe {

class BehaviorScript;

class Script {
	//! ScriptSystem calls \c update()
	friend class crepe::ScriptSystem;

protected:
	virtual void init() {}
	virtual void update() {}
	// NOTE: additional *events* (like unity's OnDisable and OnEnable) should be
	// implemented as member methods in derivative user script classes and
	// registered in init(), otherwise this class will balloon in size with each
	// added event.

protected:
	//! Retrieve component from component manager (utility)
	template <typename T>
	T & get_component();

	//! Retrieve components from component manager (utility)
	template <typename T>
	std::vector<std::reference_wrapper<T>> get_components();

protected:
	// NOTE: Script must have a constructor without arguments so the game
	// programmer doesn't need to manually add `using Script::Script` to their
	// concrete script class.
	Script() = default;
	//! Only \c BehaviorScript instantiates Script
	friend class BehaviorScript;
	BehaviorScript * parent_ref = nullptr;
};

} // namespace crepe

#include "Script.hpp"