Hymn to Beauty
C++ 3D Engine
Script.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <map>
5#include <string.h>
6#include "SuperComponent.hpp"
7
8class ScriptFile;
9class asIScriptObject;
10
11namespace Component {
13class Script : public SuperComponent {
14 public:
16 Script();
17
19 ~Script() final;
20
21 void Serialize(Json::Value& node, bool load) override;
22
24 bool initialized = false;
25
28
30 asIScriptObject* instance = nullptr;
31
33
39 void AddToPropertyMap(const std::string& name, int type, int size, void* data);
40
42
46 void CopyDataFromPropertyMap(const std::string& name, void* target);
47
49
53 void* GetDataFromPropertyMap(const std::string& name);
54
56
61 bool IsInPropertyMap(const std::string& name, const int type);
62
64 void ClearPropertyMap();
65
66 private:
67 Script(const Script& other) = delete;
68
69 Json::Value Save() const;
70 void Load(Json::Value& node);
71
72 class Property {
73 public:
74 Property() {
75 typeID = -1;
76 size = -1;
77 data = nullptr;
78 }
79
80 Property(int _typeID, int _size, void* _data) {
81 typeID = _typeID;
82 size = _size;
83 data = malloc(size);
84 memcpy(data, _data, size);
85 }
86
87 ~Property() {
88 free(data);
89 }
90
91 int typeID;
92 int size;
93 void* data;
94 };
95
96 // Map containing the properties, maps a struct of a value, it's type, and size to a name.
97 std::map<std::string, Property*> propertyMap;
98};
99} // namespace Component
Component controlled by a script.
Definition: Script.hpp:13
void AddToPropertyMap(const std::string &name, int type, int size, void *data)
Add a property to the propertyMap.
Definition: Script.cpp:34
Script()
Create new script.
Definition: Script.cpp:14
void ClearPropertyMap()
Clears the property map.
Definition: Script.cpp:52
void * GetDataFromPropertyMap(const std::string &name)
Get the pointer to the data of a property in the map.
Definition: Script.cpp:43
~Script() final
Destructor.
Definition: Script.cpp:16
asIScriptObject * instance
The instance of the script class.
Definition: Script.hpp:30
void CopyDataFromPropertyMap(const std::string &name, void *target)
Copy the data from a property in the map.
Definition: Script.cpp:39
bool IsInPropertyMap(const std::string &name, const int type)
Is the property in the map?
Definition: Script.cpp:47
ScriptFile * scriptFile
The script file.
Definition: Script.hpp:27
void Serialize(Json::Value &node, bool load) override
Save or load component values to/from JSON.
Definition: Script.cpp:26
bool initialized
Whether the script component has been initialized.
Definition: Script.hpp:24
Component which all components inherit.
Definition: SuperComponent.hpp:9
Information about a file containing a script.
Definition: ScriptFile.hpp:8
Definition: BoxShapeEditor.hpp:5