Преглед изворни кода

Added a method for creating a new project
Split project unload into separate save() and unload() methods

Marko Pintera пре 10 година
родитељ
комит
6b2f3221c5

+ 2 - 0
BansheeEditor/Include/BsBuiltinEditorResources.h

@@ -124,6 +124,8 @@ namespace BansheeEngine
 		static const Path EditorShaderFolder;
 		static const Path EditorShaderIncludeFolder;
 
+		static const Path DefaultWidgetLayoutPath;
+
 	private:
 		/**
 		 * @brief	Imports all necessary resources and converts them to engine-ready format.

+ 14 - 0
BansheeEditor/Include/BsEditorApplication.h

@@ -72,6 +72,11 @@ namespace BansheeEngine
 		 */
 		void saveProjectSettings();
 
+		/**
+		 * @brief	Saves any project specific data, if a project is currently loaded.
+		 */
+		void saveProject();
+
 		/**
 		 * @brief	Unloads the currently loaded project, if any.
 		 */
@@ -85,6 +90,14 @@ namespace BansheeEngine
 		 */
 		void loadProject(const Path& path);
 
+		/**
+		 * @brief	Creates a new project at the specified path.
+		 *
+		 * @param	path	Path to the folder where to create the project in. Name of this
+		 *					folder will be the name of the project.
+		 */
+		void createProject(const Path& path);
+
 		/**
 		 * @brief	Checks is the provided folder a valid project.
 		 *
@@ -92,6 +105,7 @@ namespace BansheeEngine
 		 */
 		bool isValidProjectPath(const Path& path);
 
+		static const Path PROJECT_INTERNAL_DIR;
 	private:
 		/**
 		 * @copydoc	Module::onStartUp

+ 3 - 2
BansheeEditor/Include/BsProjectLibrary.h

@@ -262,6 +262,9 @@ namespace BansheeEngine
 
 		Event<void(const Path&)> onEntryRemoved; /**< Triggered whenever an entry is removed from the library. Path provided is absolute. */
 		Event<void(const Path&)> onEntryAdded; /**< Triggered whenever an entry is added to the library. Path provided is absolute. */
+
+		static const Path RESOURCES_DIR;
+		static const Path INTERNAL_RESOURCES_DIR;
 	private:
 		/**
 		 * @brief	Common code for adding a new resource entry to the library.
@@ -376,8 +379,6 @@ namespace BansheeEngine
 		 */
 		void queueDependantForReimport(const ResourceEntry* entry);
 
-		static const Path RESOURCES_DIR;
-		static const Path INTERNAL_RESOURCES_DIR;
 		static const WString LIBRARY_ENTRIES_FILENAME;
 		static const WString RESOURCE_MANIFEST_FILENAME;
 

+ 1 - 0
BansheeEditor/Source/BsBuiltinEditorResources.cpp

@@ -78,6 +78,7 @@ namespace BansheeEngine
 	const Path BuiltinEditorResources::EditorShaderIncludeFolder = BuiltinDataFolder + ShaderIncludeFolder;
 
 	const Path BuiltinEditorResources::ResourceManifestPath = BuiltinDataFolder + "ResourceManifest.asset";
+	const Path BuiltinEditorResources::DefaultWidgetLayoutPath = BuiltinDataFolder + "Layout.asset";
 
 	const WString BuiltinEditorResources::FolderIconTex = L"FolderIcon.psd";
 	const WString BuiltinEditorResources::MeshIconTex = L"MeshIcon.psd";

+ 37 - 6
BansheeEditor/Source/BsEditorApplication.cpp

@@ -22,6 +22,7 @@
 #include "BsProjectSettings.h"
 #include "BsEditorSettings.h"
 #include "BsScriptManager.h"
+#include "BsFileSystem.h"
 
 // DEBUG ONLY
 #include "BsResources.h"
@@ -48,10 +49,11 @@
 
 namespace BansheeEngine
 {
-	const Path EditorApplication::WIDGET_LAYOUT_PATH = L"Internal\\Layout.asset";
-	const Path EditorApplication::BUILD_DATA_PATH = L"Internal\\BuildData.asset";
+	const Path EditorApplication::PROJECT_INTERNAL_DIR = L"Internal\\";
+	const Path EditorApplication::WIDGET_LAYOUT_PATH = PROJECT_INTERNAL_DIR + L"Layout.asset";
+	const Path EditorApplication::BUILD_DATA_PATH = PROJECT_INTERNAL_DIR + L"BuildData.asset";
 	const Path EditorApplication::EDITOR_SETTINGS_PATH = RUNTIME_DATA_PATH + L"Settings.asset";
-	const Path EditorApplication::PROJECT_SETTINGS_PATH = L"Internal\\Settings.asset";
+	const Path EditorApplication::PROJECT_SETTINGS_PATH = PROJECT_INTERNAL_DIR + L"Settings.asset";
 
 	RENDER_WINDOW_DESC createRenderWindowDesc()
 	{
@@ -277,7 +279,7 @@ namespace BansheeEngine
 		return assemblyFolder;
 	}
 
-	void EditorApplication::unloadProject()
+	void EditorApplication::saveProject()
 	{
 		if (!isProjectLoaded())
 			return;
@@ -287,13 +289,21 @@ namespace BansheeEngine
 		saveEditorSettings();
 		saveProjectSettings();
 
+		ProjectLibrary::instance().saveLibrary();
+	}
+
+	void EditorApplication::unloadProject()
+	{
+		if (!isProjectLoaded())
+			return;
+
+		saveProject();
+
 		mProjectSettings = bs_shared_ptr_new<ProjectSettings>();
 		BuildManager::instance().clear();
 		UndoRedo::instance().clear();
 
-		ProjectLibrary::instance().saveLibrary();
 		ProjectLibrary::instance().unloadLibrary();
-
 		Resources::instance().unloadAllUnused();
 	}
 
@@ -316,6 +326,27 @@ namespace BansheeEngine
 		ScriptManager::instance().reload();
 	}
 
+	void EditorApplication::createProject(const Path& path)
+	{
+		Path resourceDir = Path::combine(path, ProjectLibrary::RESOURCES_DIR);
+		Path internalResourcesDir = Path::combine(path, ProjectLibrary::INTERNAL_RESOURCES_DIR);
+
+		if (!FileSystem::exists(resourceDir))
+			FileSystem::createDir(resourceDir);
+
+		if (!FileSystem::exists(internalResourcesDir))
+			FileSystem::createDir(internalResourcesDir);
+
+		Path defaultLayoutPath = FileSystem::getWorkingDirectoryPath();
+		defaultLayoutPath.append(BuiltinEditorResources::DefaultWidgetLayoutPath);
+
+		if (FileSystem::exists(defaultLayoutPath))
+		{
+			Path projectLayoutPath = Path::combine(path, WIDGET_LAYOUT_PATH);
+			FileSystem::copy(defaultLayoutPath, projectLayoutPath, false);
+		}
+	}
+
 	bool EditorApplication::isValidProjectPath(const Path& path)
 	{
 		if (!path.isAbsolute())

+ 1 - 1
BansheeEditor/Source/BsProjectLibrary.cpp

@@ -22,7 +22,7 @@ using namespace std::placeholders;
 namespace BansheeEngine
 {
 	const Path ProjectLibrary::RESOURCES_DIR = L"Resources\\";
-	const Path ProjectLibrary::INTERNAL_RESOURCES_DIR = L"Internal\\Resources\\";
+	const Path ProjectLibrary::INTERNAL_RESOURCES_DIR = EditorApplication::PROJECT_INTERNAL_DIR + L"Resources\\";
 	const WString ProjectLibrary::LIBRARY_ENTRIES_FILENAME = L"ProjectLibrary.asset";
 	const WString ProjectLibrary::RESOURCE_MANIFEST_FILENAME = L"ResourceManifest.asset";
 

+ 10 - 2
MBansheeEditor/EditorApplication.cs

@@ -221,7 +221,7 @@ namespace BansheeEditor
 
         public static void CreateProject(string path)
         {
-            // TODO
+            Internal_CreateProject(path);
         }
 
         [MenuItem("File/Load Project", 0)]
@@ -239,7 +239,9 @@ namespace BansheeEditor
         [MenuItem("File/Save Project", 0)]
         public static void SaveProject()
         {
-            // TODO
+            // TODO - Save dirty resources
+
+            Internal_SaveProject();
         }
 
         public static void LoadProject(string path)
@@ -486,10 +488,16 @@ namespace BansheeEditor
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern bool Internal_IsValidProject(string path);
 
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SaveProject();
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_LoadProject(string path);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_UnloadProject();
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_CreateProject(string path);
     }
 }

+ 2 - 0
SBansheeEditor/Include/BsScriptEditorApplication.h

@@ -32,7 +32,9 @@ namespace BansheeEngine
 		static MonoString* internal_GetScriptEditorAssemblyName();
 		static MonoString* internal_SaveScene(MonoString* path);
 		static bool internal_IsValidProject(MonoString* path);
+		static void internal_SaveProject();
 		static void internal_LoadProject(MonoString* path);
 		static void internal_UnloadProject();
+		static void internal_CreateProject(MonoString* path);
 	};
 }

+ 14 - 0
SBansheeEditor/Source/BsScriptEditorApplication.cpp

@@ -38,8 +38,10 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_GetScriptEditorAssemblyName", &ScriptEditorApplication::internal_GetScriptEditorAssemblyName);
 		metaData.scriptClass->addInternalCall("Internal_SaveScene", &ScriptEditorApplication::internal_SaveScene);
 		metaData.scriptClass->addInternalCall("Internal_IsValidProject", &ScriptEditorApplication::internal_IsValidProject);
+		metaData.scriptClass->addInternalCall("Internal_SaveProject", &ScriptEditorApplication::internal_SaveProject);
 		metaData.scriptClass->addInternalCall("Internal_LoadProject", &ScriptEditorApplication::internal_LoadProject);
 		metaData.scriptClass->addInternalCall("Internal_UnloadProject", &ScriptEditorApplication::internal_UnloadProject);
+		metaData.scriptClass->addInternalCall("Internal_CreateProject", &ScriptEditorApplication::internal_CreateProject);
 	}
 
 	MonoString* ScriptEditorApplication::internal_GetProjectPath()
@@ -147,6 +149,11 @@ namespace BansheeEngine
 		return gEditorApplication().isValidProjectPath(nativePath);
 	}
 
+	void ScriptEditorApplication::internal_SaveProject()
+	{
+		gEditorApplication().saveProject();
+	}
+
 	void ScriptEditorApplication::internal_LoadProject(MonoString* path)
 	{
 		Path nativePath = MonoUtil::monoToWString(path);
@@ -157,4 +164,11 @@ namespace BansheeEngine
 	{
 		gEditorApplication().unloadProject();
 	}
+
+	void ScriptEditorApplication::internal_CreateProject(MonoString* path)
+	{
+		Path nativePath = MonoUtil::monoToWString(path);
+
+		gEditorApplication().createProject(nativePath);
+	}
 }

+ 0 - 7
TODO.txt

@@ -56,13 +56,6 @@ Move data folder within current repo
  - Store default layout asset in Data/Editor folder
  - Store data generated by editor runtime at Data/Runtime
 
-EditorApplication.SaveProject not implemented
- - Separate Unload project into Save & Unload
-
-EditorApplication.CreateProject not implemented
- - Copy default layout from Data/Editor to the project folder
- - Create Resources & Internal folders
-
 TODO - Test if project loading/unloading/reloading works
 
 Ribek use: