summary refs log tree commit diff stats
path: root/src/script_system.h
blob: 7ef2dee097c4ad5344dd28a5ccf55f16c89bba78 (plain) (blame)
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
#ifndef SCRIPT_SYSTEM_H_FD8A95B3
#define SCRIPT_SYSTEM_H_FD8A95B3

#include <sol/sol.hpp>
#include <memory>
#include <set>
#include <list>
#include <string>
#include "system.h"

class Game;

class ScriptSystem : public System {
public:

  static constexpr SystemKey Key = SystemKey::Script;

  explicit ScriptSystem(Game& game);

  void tick(double dt) override;

  bool mapHasScript(std::string mapName, std::string scriptName);

  void runScript(std::string mapName, std::string scriptName);

  void runDebugScript(std::string script);

private:

  void loadMapScripts(std::string mapName);

  struct Script {
    std::unique_ptr<sol::thread> runner;
    std::unique_ptr<sol::coroutine> callable;
  };

  Game& game_;
  sol::state engine_;
  std::list<Script> scripts_;
  std::set<std::string> loadedScripts_;
};

#endif /* end of include guard: SCRIPT_SYSTEM_H_FD8A95B3 */