1 #ifndef SCRIPT_OBJECT_H
2 #define SCRIPT_OBJECT_H
15 class ScriptingSystem;
23 std::string class_name;
26 unsigned int num_saved_fields;
27 std::vector<std::string> serialized_var_names;
29 std::shared_ptr<chaiscript::dispatch::Dynamic_Object> script_object;
31 std::function<void (std::shared_ptr<chaiscript::dispatch::Dynamic_Object>)> script_on_start;
32 std::function<void (std::shared_ptr<chaiscript::dispatch::Dynamic_Object>,
const float)> script_on_update;
33 std::function<void (std::shared_ptr<chaiscript::dispatch::Dynamic_Object>)> script_on_destroy;
34 std::function<void (std::shared_ptr<chaiscript::dispatch::Dynamic_Object>, std::shared_ptr<ScriptObject>)> script_set_obj_handle;
37 typename std::enable_if<std::is_base_of<Events::Event, T>::value, std::function<void(std::shared_ptr<chaiscript::dispatch::Dynamic_Object>, std::shared_ptr<T>)>>::type selectEventHandler();
39 void invokeScriptFunction(
const std::function<
void ()>& func);
41 void setSerializable(
const std::string& name);
44 void sendThisToScript();
98 virtual
void onNotifyNow(std::shared_ptr<Events::Event> event) override;
virtual void handleQueuedEvent(std::shared_ptr< Events::Event > event) override
HandleQueuedEvent allows derived classes to define behaviour for when queuedEvents are received...
Definition: script_object.cpp:191
bool shouldBeSerialized() const noexcept
Definition: script_object.cpp:183
bool representsDynamicObject(const chaiscript::dispatch::Dynamic_Object &obj) const noexcept
Definition: script_object.cpp:165
virtual void onNotifyNow(std::shared_ptr< Events::Event > event) override
When receiving an event that is immediate, onNotifyNow is used. It acts as an interrupt to make sure ...
Definition: script_object.cpp:187
Class for script object.
Definition: script_object.h:19
Class for a subject that an observer would observe for changes.
Definition: subject.h:13
Class for scripting system.
Definition: scripting_system.h:10
Interface to be notified of an item's changes.
Definition: observer.h:13
~ScriptObject()=default
Destroys the object.
void onStart()
Calls onStart in the attached script object.
Definition: script_object.cpp:169
std::string getClassName() const noexcept
Definition: script_object.cpp:20
void onUpdate(const float delta)
Calls onUpdate in the attached script object.
Definition: script_object.cpp:173
Json::Value getSaveData() const noexcept
Definition: script_object.cpp:57
ScriptObject(const std::string &name)
ScriptObject constructor.
Definition: script_object.cpp:7
void onDestroy()
Calls onDestroy in the attached script object.
Definition: script_object.cpp:178
void loadSavedData(Json::Value &save_data)
Definition: script_object.cpp:88
void setClassName(const std::string &name)
Sets the class name on the scripting object.
Definition: script_object.cpp:16