BsScriptProjectLibrary.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEditorPrerequisites.h"
  5. #include "BsScriptObject.h"
  6. #include "BsProjectLibrary.h"
  7. #include "BsScriptResource.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Interop class between C++ & CLR for ProjectLibrary.
  12. */
  13. class BS_SCR_BED_EXPORT ScriptProjectLibrary : public ScriptObject<ScriptProjectLibrary>
  14. {
  15. public:
  16. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "ProjectLibrary")
  17. /**
  18. * @brief Initializes the project library callbacks. Must be called on library load.
  19. */
  20. void static startUp();
  21. /**
  22. * @brief Cleans up project library callbacks. Must be called before library shutdown.
  23. */
  24. void static shutDown();
  25. private:
  26. ScriptProjectLibrary(MonoObject* instance);
  27. /**
  28. * @brief Triggered when a new entry has been added to the library.
  29. *
  30. * @param path Absolute path to the new entry.
  31. */
  32. static void onEntryAdded(const Path& path);
  33. /**
  34. * @brief Triggered when a new entry has been removed to the library.
  35. *
  36. * @param path Absolute path to the removed entry.
  37. */
  38. static void onEntryRemoved(const Path& path);
  39. /**
  40. * @brief Triggered when an entry was (re) imported in the library.
  41. *
  42. * @param path Absolute path to the imported entry.
  43. */
  44. static void onEntryImported(const Path& path);
  45. static HEvent mOnEntryAddedConn;
  46. static HEvent mOnEntryRemovedConn;
  47. static HEvent mOnEntryImportedConn;
  48. /************************************************************************/
  49. /* CLR HOOKS */
  50. /************************************************************************/
  51. typedef void(__stdcall *OnEntryChangedThunkDef) (MonoString*, MonoException**);
  52. static OnEntryChangedThunkDef OnEntryAddedThunk;
  53. static OnEntryChangedThunkDef OnEntryRemovedThunk;
  54. static OnEntryChangedThunkDef OnEntryImportedThunk;
  55. static MonoArray* internal_Refresh(MonoString* path, bool import);
  56. static void internal_Create(MonoObject* resource, MonoString* path);
  57. static MonoObject* internal_Load(MonoString* path);
  58. static void internal_Save(MonoObject* resource);
  59. static MonoObject* internal_GetRoot();
  60. static void internal_Reimport(MonoString* path, MonoObject* options, bool force);
  61. static MonoObject* internal_GetEntry(MonoString* path);
  62. static MonoString* internal_GetPathFromUUID(MonoString* uuid);
  63. static MonoString* internal_GetPath(MonoObject* resource);
  64. static MonoArray* internal_Search(MonoString* pattern, MonoArray* types);
  65. static void internal_Delete(MonoString* path);
  66. static void internal_CreateFolder(MonoString* path);
  67. static void internal_Rename(MonoString* path, MonoString* name, bool overwrite);
  68. static void internal_Move(MonoString* oldPath, MonoString* newPath, bool overwrite);
  69. static void internal_Copy(MonoString* source, MonoString* destination, bool overwrite);
  70. static MonoString* internal_GetResourceFolder();
  71. static void internal_SetIncludeInBuild(MonoString* path, bool include);
  72. };
  73. /**
  74. * @brief Base class for C++/CLR interop objects used for wrapping
  75. * LibraryEntry implementations.
  76. */
  77. class BS_SCR_BED_EXPORT ScriptLibraryEntryBase : public ScriptObjectBase
  78. {
  79. public:
  80. /**
  81. * @brief Returns the asset path of the library entry.
  82. */
  83. const Path& getAssetPath() const { return mAssetPath; }
  84. protected:
  85. ScriptLibraryEntryBase(MonoObject* instance);
  86. virtual ~ScriptLibraryEntryBase() {}
  87. Path mAssetPath;
  88. };
  89. /**
  90. * @brief Interop class between C++ & CLR for LibraryEntry.
  91. */
  92. class BS_SCR_BED_EXPORT ScriptLibraryEntry : public ScriptObject <ScriptLibraryEntry>
  93. {
  94. public:
  95. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "LibraryEntry")
  96. private:
  97. /************************************************************************/
  98. /* CLR HOOKS */
  99. /************************************************************************/
  100. static MonoString* internal_GetPath(ScriptLibraryEntryBase* thisPtr);
  101. static MonoString* internal_GetName(ScriptLibraryEntryBase* thisPtr);
  102. static ProjectLibrary::LibraryEntryType internal_GetType(ScriptLibraryEntryBase* thisPtr);
  103. static MonoObject* internal_GetParent(ScriptLibraryEntryBase* thisPtr);
  104. };
  105. /**
  106. * @brief Interop class between C++ & CLR for DirectoryEntry.
  107. */
  108. class BS_SCR_BED_EXPORT ScriptDirectoryEntry : public ScriptObject <ScriptDirectoryEntry, ScriptLibraryEntryBase>
  109. {
  110. public:
  111. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "DirectoryEntry")
  112. ScriptDirectoryEntry(MonoObject* instance, const Path& assetPath);
  113. /**
  114. * @brief Creates a new interop object that wraps the provided
  115. * native directory entry object.
  116. */
  117. static MonoObject* create(const ProjectLibrary::DirectoryEntry* entry);
  118. private:
  119. /************************************************************************/
  120. /* CLR HOOKS */
  121. /************************************************************************/
  122. static MonoArray* internal_GetChildren(ScriptDirectoryEntry* thisPtr);
  123. };
  124. /**
  125. * @brief Interop class between C++ & CLR for ResourceEntry.
  126. */
  127. class BS_SCR_BED_EXPORT ScriptFileEntry : public ScriptObject <ScriptFileEntry, ScriptLibraryEntryBase>
  128. {
  129. public:
  130. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "FileEntry")
  131. ScriptFileEntry(MonoObject* instance, const Path& assetPath);
  132. /**
  133. * @brief Creates a new interop object that wraps the provided
  134. * native resource entry object.
  135. */
  136. static MonoObject* create(const ProjectLibrary::ResourceEntry* entry);
  137. private:
  138. /************************************************************************/
  139. /* CLR HOOKS */
  140. /************************************************************************/
  141. static MonoObject* internal_GetImportOptions(ScriptFileEntry* thisPtr);
  142. static MonoString* internal_GetUUID(ScriptFileEntry* thisPtr);
  143. static MonoObject* internal_GetIcon(ScriptFileEntry* thisPtr);
  144. static ScriptResourceType internal_GetResourceType(ScriptFileEntry* thisPtr);
  145. static bool internal_GetIncludeInBuild(ScriptFileEntry* thisPtr);
  146. };
  147. }