summary refs log tree commit diff stats
path: root/src/systems/scripting.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-13 00:50:11 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-05-17 15:39:39 -0400
commit5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb (patch)
tree94a3f4ce0a0e54375cd2f27fb90d7c35295bda2e /src/systems/scripting.h
parent59808c86bf0e4d5cf0b6ab3d6ed1d8bdcd303a37 (diff)
downloadtherapy-5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb.tar.gz
therapy-5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb.tar.bz2
therapy-5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb.zip
Started event handlers
The AutomatingSystem has been renamed to the ScriptingSystem, since the automatic behavior script is just a special case of the scripts that an entity can exhibit. The AutomatableComponent has largely been moved to the new RunnableComponent (might not be the final name for it).

The Lua state object, previously living on the singleton RealizableComponent, is now a member of the ScriptingSystem itself, because it A) doesn't really belong on the realizable entity, and B) a singleton entity seems weird and like a cumbersome attempt to apply the ECS rules to places they don't apply. In a similar vein, the RealizableComponent itself will probably soon be integrated into the RealizingSystem too.

The attempt at using Lua environments in order to encapsulate the different behaviors that objects exhibit was scrapped in preference of just creating differently named Lua tables for each prototype.

The new PrototypableComponent contains some information about entities which were prototyped. It is partially used by the ScriptingSystem to figure out what event handlers are appropriate, which may not be the best approach. It also has some data about automatic behavior, which also maybe does not belong in this component.

The OnTouch event is raised by a player colliding with a physics body with the collider type "event", which may not be the best way to implement this.

The result of all of this is that checkpoints now work, although no sound is played, and the result is not persistent across exiting the game.
Diffstat (limited to 'src/systems/scripting.h')
-rw-r--r--src/systems/scripting.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/systems/scripting.h b/src/systems/scripting.h new file mode 100644 index 0000000..d5380f1 --- /dev/null +++ b/src/systems/scripting.h
@@ -0,0 +1,28 @@
1#ifndef AUTOMATING_H_E6E5D76E
2#define AUTOMATING_H_E6E5D76E
3
4#include "system.h"
5#include <sol.hpp>
6
7class ScriptingSystem : public System {
8public:
9
10 ScriptingSystem(Game& game);
11
12 void tick(double dt);
13
14 void killScript(id_type entity);
15
16 id_type runBehaviorScript(id_type entity);
17
18 void onTouch(id_type entity, id_type player);
19
20private:
21
22 template <typename... Args>
23 id_type runScript(std::string event, id_type entity, Args&&... args);
24
25 sol::state engine;
26};
27
28#endif /* end of include guard: AUTOMATING_H_E6E5D76E */