summary refs log tree commit diff stats
path: root/src/script_system.h
blob: 0718e90981eb4703eafca307e4310c4dec8ffedf (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
44
45
46
47
#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;

  void destroySprite(int spriteId) override;

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

  void runScript(std::string mapName, std::string scriptName, int linkedSprite = -1);

  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;
    std::string debugInfo;
    int linkedSprite = -1;
  };

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

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