Fling Engine  0.00.1
Fling Engine is a game engine written in Vulkan
ScriptComponent.h
Go to the documentation of this file.
1 #if WITH_LUA
2 
3 #pragma once
4 #include "File.h"
5 #include "Serilization.h"
6 
7 namespace Fling
8 {
12  class ScriptComponent
13  {
14  public:
15 
21  ScriptComponent(const std::string t_FilePath);
22 
24  ScriptComponent() = default;
25 
29  ~ScriptComponent() = default;
30 
36  inline File* GetScriptFile() { return m_ScriptFile; }
37 
38  template<class Archive>
39  void save(Archive& t_Archive) const;
40 
41  template<class Archive>
42  void load(Archive& t_Archive);
43 
44  private:
45 
46  //A reference to the script file
47  File* m_ScriptFile = nullptr;
48  };
49 
51  template<class Archive>
52  inline void ScriptComponent::save(Archive& t_Archive) const
53  {
54  std::string ScriptPath = "INVALID_LUA_PATH";
55 
56  if (m_ScriptFile)
57  {
58  ScriptPath = m_ScriptFile->GetGuidString();
59  }
60 
61  t_Archive(
62  cereal::make_nvp("SCRIPT_PATH", ScriptPath)
63  );
64  }
65 
66  template<class Archive>
67  inline void ScriptComponent::load(Archive& t_Archive)
68  {
69  std::string ScriptPath = "";
70 
71  t_Archive(
72  cereal::make_nvp("SCRIPT_PATH", ScriptPath)
73  );
74 
75  m_ScriptFile = File::Create(HS(ScriptPath.c_str())).get();
76  }
77 }
78 
79 #endif // WITH_LUA
#define HS(str)
Definition: FlingTypes.h:21
static std::shared_ptr< Fling::File > Create(Guid t_ID)
Definition: File.cpp:7
Definition: Engine.h:29