Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scripting_system.h
Go to the documentation of this file.
1 #ifndef SCRIPTING_SYSTEM_H
2 #define SCRIPTING_SYSTEM_H
3 #include <json/json.h>
4 #include "script_object.h"
5 
6 namespace Script {
11  private:
12  std::string scripts_location;
13  std::vector<std::string> getFileList(const std::string& location);
14 
15  std::vector<std::shared_ptr<ScriptObject>> scripts;
16 
17  std::string filenameToTitleCase(std::string s);
18  public:
19  ScriptingSystem() = delete;
25  ScriptingSystem(const std::string scripts_location);
31  void registerModule(chaiscript::ModulePtr module);
37  void loadScript(const std::string& name);
41  void loadScripts();
42 
51  template<class T>
52  void addObject(std::shared_ptr<T> object, const std::string& name) {
53  ChaiscriptWrapper::getInstance()->add(chaiscript::var(object), name);
54  }
55 
64  template<class T>
65  void addGlobalObject(std::shared_ptr<T> object, const std::string& name) {
66  ChaiscriptWrapper::getInstance()->add_global(chaiscript::var(object), name);
67  }
68 
69  void save(const std::string& file);
70 
71  void load(const std::string& file);
72 
76  void start();
82  void update(const float delta);
86  void destroy();
87  };
88 }
89 
90 #endif
void addObject(std::shared_ptr< T > object, const std::string &name)
Adds an object of type to chaiscript.
Definition: scripting_system.h:52
void save(const std::string &file)
Definition: scripting_system.cpp:106
Class for scripting system.
Definition: scripting_system.h:10
void loadScripts()
Loads all scripts in scripts location, recursively.
Definition: scripting_system.cpp:90
void update(const float delta)
Calls onUpdate in all scripts.
Definition: scripting_system.cpp:162
static std::shared_ptr< chaiscript::ChaiScript > getInstance()
Definition: chaiscript_wrapper.cpp:22
void registerModule(chaiscript::ModulePtr module)
Registers a chaiscript module.
Definition: scripting_system.cpp:41
void addGlobalObject(std::shared_ptr< T > object, const std::string &name)
Adds a global object of type to chaiscript.
Definition: scripting_system.h:65
void start()
Calls onStart in all scripts.
Definition: scripting_system.cpp:141
void destroy()
Calls onDestroy in all scripts.
Definition: scripting_system.cpp:175
void load(const std::string &file)
Definition: scripting_system.cpp:121
void loadScript(const std::string &name)
Loads a script.
Definition: scripting_system.cpp:45