Shkyera Engine
Easy to use, game engine for Python
ScriptComponent.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include "core/Filesystem.hpp"
10 #include "game/Component.hpp"
11 
12 namespace shkyera {
13 
17 typedef struct PublicFloat {
18  std::string name;
19  float value;
21 
25 typedef struct PublicInt {
26  std::string name;
27  int value;
29 
33 typedef struct PublicString {
34  std::string name;
35  std::string value;
37 
41 typedef struct PublicVec3 {
42  std::string name;
43  glm::vec3 value;
45 
52 class ScriptComponent : public Component {
53  public:
55 
61  void setFile(std::shared_ptr<File> file);
62 
66  void update();
67 
71  void moveScript();
72 
78  const std::shared_ptr<File> getFile() const;
79 
85  void addFloatVariable(std::string name);
86 
92  void addIntVariable(std::string name);
93 
99  void addStringVariable(std::string name);
100 
106  void addVec3Variable(std::string name);
107 
113  std::vector<PublicFloat> &getFloatVariables();
114 
120  std::vector<PublicInt> &getIntVariables();
121 
127  std::vector<PublicString> &getStringVariables();
128 
134  std::vector<PublicVec3> &getVec3Variables();
135 
143  static std::shared_ptr<ScriptComponent> addScript(std::shared_ptr<GameObject> object, std::shared_ptr<File> file);
144 
150  static void addScript(std::shared_ptr<ScriptComponent> script);
151 
157  static void removeScript(std::shared_ptr<ScriptComponent> script);
158 
164  static std::vector<std::shared_ptr<ScriptComponent>> getScripts();
165 
169  static void moveScripts();
170 
174  inline static std::string SCRIPT_DESTINATION = "src/python/shkyera";
175 
176  private:
180  static void verifyScripts();
181 
182  static std::vector<std::shared_ptr<ScriptComponent>> _scripts;
183 
184  std::shared_ptr<File> _file;
185  std::vector<PublicFloat> _floatVariables;
186  std::vector<PublicInt> _intVariables;
187  std::vector<PublicString> _stringVariables;
188  std::vector<PublicVec3> _vec3Variables;
189 };
190 
191 } // namespace shkyera
Contains the declaration of the Component class, a base class for game components.
A base class representing a component attached to a game object.
Definition: Component.hpp:20
Component(std::shared_ptr< GameObject > object)
Constructor to initialize a component with a shared pointer to a game object.
Definition: Component.cpp:5
A class representing a script component that can be attached to game objects.
Definition: ScriptComponent.hpp:52
static std::string SCRIPT_DESTINATION
The destination directory for scripts (static member).
Definition: ScriptComponent.hpp:174
static std::vector< std::shared_ptr< ScriptComponent > > getScripts()
Get a list of all managed script components.
Definition: ScriptComponent.cpp:63
static std::vector< std::shared_ptr< ScriptComponent > > _scripts
List of managed script components.
Definition: ScriptComponent.hpp:182
static void removeScript(std::shared_ptr< ScriptComponent > script)
Remove a script component from the list of managed scripts.
Definition: ScriptComponent.cpp:61
std::vector< PublicInt > _intVariables
List of public integer variables.
Definition: ScriptComponent.hpp:186
void setFile(std::shared_ptr< File > file)
Set the script file associated with this script component.
Definition: ScriptComponent.cpp:9
void update()
Update the script component.
Definition: ScriptComponent.cpp:14
std::shared_ptr< File > _file
The associated script file.
Definition: ScriptComponent.hpp:184
static void verifyScripts()
Verify the existence of script files and components.
Definition: ScriptComponent.cpp:81
std::vector< PublicVec3 > _vec3Variables
List of public glm::vec3 variables.
Definition: ScriptComponent.hpp:188
void addFloatVariable(std::string name)
Add a public float variable to the script component.
Definition: ScriptComponent.cpp:43
static std::shared_ptr< ScriptComponent > addScript(std::shared_ptr< GameObject > object, std::shared_ptr< File > file)
Add a script component to a game object and attach a script file.
Definition: ScriptComponent.cpp:53
std::vector< PublicInt > & getIntVariables()
Get a reference to the vector of public integer variables.
Definition: ScriptComponent.cpp:49
static void moveScripts()
Move all scripts to their respective destinations.
Definition: ScriptComponent.cpp:65
std::vector< PublicFloat > & getFloatVariables()
Get a reference to the vector of public float variables.
Definition: ScriptComponent.cpp:48
void moveScript()
Move the script associated with this component.
Definition: ScriptComponent.cpp:72
void addIntVariable(std::string name)
Add a public integer variable to the script component.
Definition: ScriptComponent.cpp:44
std::vector< PublicFloat > _floatVariables
List of public float variables.
Definition: ScriptComponent.hpp:185
const std::shared_ptr< File > getFile() const
Get the script file associated with this script component.
Definition: ScriptComponent.cpp:41
std::vector< PublicString > & getStringVariables()
Get a reference to the vector of public string variables.
Definition: ScriptComponent.cpp:50
void addStringVariable(std::string name)
Add a public string variable to the script component.
Definition: ScriptComponent.cpp:45
std::vector< PublicString > _stringVariables
List of public string variables.
Definition: ScriptComponent.hpp:187
void addVec3Variable(std::string name)
Add a public glm::vec3 variable to the script component.
Definition: ScriptComponent.cpp:46
std::vector< PublicVec3 > & getVec3Variables()
Get a reference to the vector of public glm::vec3 variables.
Definition: ScriptComponent.cpp:51
Definition: Entity.cpp:3
struct shkyera::PublicInt PublicInt
Structure to represent a public integer variable for use in scripts.
struct shkyera::PublicVec3 PublicVec3
Structure to represent a public glm::vec3 variable for use in scripts.
struct shkyera::PublicString PublicString
Structure to represent a public string variable for use in scripts.
struct shkyera::PublicFloat PublicFloat
Structure to represent a public float variable for use in scripts.
Structure to represent a public float variable for use in scripts.
Definition: ScriptComponent.hpp:17
std::string name
The name of the variable.
Definition: ScriptComponent.hpp:18
float value
The value of the variable.
Definition: ScriptComponent.hpp:19
Structure to represent a public integer variable for use in scripts.
Definition: ScriptComponent.hpp:25
std::string name
The name of the variable.
Definition: ScriptComponent.hpp:26
int value
The value of the variable.
Definition: ScriptComponent.hpp:27
Structure to represent a public string variable for use in scripts.
Definition: ScriptComponent.hpp:33
std::string value
The value of the variable.
Definition: ScriptComponent.hpp:35
std::string name
The name of the variable.
Definition: ScriptComponent.hpp:34
Structure to represent a public glm::vec3 variable for use in scripts.
Definition: ScriptComponent.hpp:41
std::string name
The name of the variable.
Definition: ScriptComponent.hpp:42
glm::vec3 value
The value of the variable.
Definition: ScriptComponent.hpp:43