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

Project Manager Update Module

This allows a module with a higher build number in the library to replace a matching module in the project. This is not done automatically, since the process involves deleting the old module.
Peter Robinson пре 3 година
родитељ
комит
7eeb4c6ed6

+ 17 - 0
editor/ProjectManager/scripts/ProjectGamePanel.cs

@@ -21,6 +21,11 @@ function ProjectGamePanel::onOpen(%this, %allModules)
 		%this.addModule(%mod, %loadedModules);
 	}
 	%this.list.sortByText();
+
+	if(%this.card.visible)
+	{
+		%this.refreshCard();
+	}
 }
 
 function ProjectGamePanel::addModule(%this, %module, %loadedModules)
@@ -47,3 +52,15 @@ function ProjectGamePanel::addModule(%this, %module, %loadedModules)
 	%index = %this.list.findItemID(%module);
 	%this.list.setItemColor(%index, %color);
 }
+
+function ProjectGamePanel::refreshCard(%this)
+{
+	%module = ModuleDatabase.findModule(%this.card.moduleID, %this.card.versionID);
+	%indexList = %this.list.findItemText(%this.getModuleName(%module));
+	%index = getWord(%indexList, 0);
+	if(%index != -1)
+	{
+		%this.list.setCurSel(%index);
+	}
+	%this.card.show(%module);
+}

+ 47 - 0
editor/ProjectManager/scripts/ProjectLibraryPanel.cs

@@ -38,6 +38,11 @@ function ProjectLibraryPanel::onOpen(%this, %allModules)
 		%module = %this.list.getItemID(%i);
 		%this.refreshColor(%module, %i, %allModules);
 	}
+
+	if(%this.card.visible)
+	{
+		%this.refreshCard();
+	}
 }
 
 function ProjectLibraryPanel::refreshColor(%this, %module, %index, %projectModules)
@@ -81,9 +86,51 @@ function ProjectLibraryPanel::onInstallClick(%this)
 		%installedModule = ModuleDatabase.findModule(%module.moduleID, %module.versionID);
 		%this.postEvent("ModuleInstalled", %installedModule);
 	}
+	else
+	{
+		warn("Project Manager - Could not install module.");
+	}
 }
 
 function ProjectLibraryPanel::onUpdateClick(%this)
 {
+	%index = %this.list.getSelectedItem();
+	%module = %this.list.getItemID(%index);
+	%installedModule = ModuleDatabase.findModule(%module.moduleID, %module.versionID);
+
+	if(isObject(%module) && isObject(%installedModule))
+	{
+		%path = %installedModule.getModulePath();
+		%wasLoaded = false;
+		if(ModuleDatabase.isModuleLoaded(%installedModule.moduleID))
+		{
+			%wasLoaded = true;
+			ModuleDatabase.UnloadExplicit(%installedModule.moduleID);
+		}
+		ModuleDatabase.unregisterModule(%installedModule.moduleID, %installedModule.versionID);
+
+		directoryDelete(%path);
+		%this.manager.CopyModule(%module.moduleID, %module.versionID, %module.moduleID, ProjectManager.getProjectFolder(), true);
+		%this.manager.synchronizeDependencies(%module, ProjectManager.getProjectFolder());
 
+		ModuleDatabase.ScanModules(ProjectManager.getProjectFolder());
+		%installedModule = ModuleDatabase.findModule(%module.moduleID, %module.versionID);
+
+		if(%wasLoaded)
+		{
+			ModuleDatabase.LoadExplicit(%installedModule.moduleID, %installedModule.versionID);
+		}
+
+		%this.postEvent("ModuleInstalled", %installedModule);
+	}
+	else
+	{
+		warn("Project Manager - Could not update module.");
+	}
+}
+
+function ProjectLibraryPanel::refreshCard(%this)
+{
+	%module = %this.manager.findModule(%this.card.moduleID, %this.card.versionID);
+	%this.card.show(%module);
 }

+ 27 - 19
editor/ProjectManager/scripts/ProjectModuleCard.cs

@@ -99,36 +99,44 @@ function ProjectModuleCard::onThemeChange(%this, %theme)
 
 function ProjectModuleCard::show(%this, %module)
 {
-	%this.titleText.setText(%module.moduleID);
-	%this.setAuthor(%module);
-	%this.setVersion(%module);
-	%this.descriptionText.setText(%module.description);
-
-	%this.button.visible = false;
-	%projectModule = %this.getInstalledModule(%module.moduleID, %module.versionID);
-	if(%projectModule != %module)
+	if(isObject(%module))
 	{
-		if(!isObject(%projectModule))
+		%this.moduleID = %module.moduleID;
+		%this.versionID = %module.versionID;
+
+		%this.titleText.setText(%module.moduleID);
+		%this.setAuthor(%module);
+		%this.setVersion(%module);
+		%this.descriptionText.setText(%module.description);
+
+		%this.button.visible = false;
+		%projectModule = %this.getInstalledModule(%module.moduleID, %module.versionID);
+		if(%projectModule != %module)
 		{
-			%this.button.setText("Install");
-			%this.button.visible = true;
+			if(!isObject(%projectModule))
+			{
+				%this.button.setText("Install");
+				%this.button.visible = true;
+			}
+			else if(%projectmodule.buildID < %module.buildID)
+			{
+				%this.button.setText("Update");
+				%this.button.visible = true;
+			}
 		}
-		else if(%projectmodule.buildID < %module.buildID)
+		else
 		{
-			%this.button.setText("Update");
-			%this.button.visible = true;
+
 		}
-	}
-	else
-	{
 
+		%this.visible = true;
 	}
-
-	%this.visible = true;
 }
 
 function ProjectModuleCard::hide(%this)
 {
+	%this.moduleID = "";
+	%this.versionID = 0;
 	%this.visible = false;
 }
 

+ 13 - 0
engine/source/module/moduleManager_ScriptBinding.h

@@ -138,6 +138,19 @@ ConsoleMethodWithDocs(ModuleManager, unloadExplicit, ConsoleBool, 3, 3, (moduleI
 
 //-----------------------------------------------------------------------------
 
+/*! Checks to see if a module is loaded or not.
+    @param moduleId The module Id to check.
+    @return True if the module is loaded. False otherwise.
+*/
+ConsoleMethodWithDocs(ModuleManager, isModuleLoaded, ConsoleBool, 3, 3, (moduleId))
+{
+    ModuleDefinition* pLoadedModule = object->findLoadedModule(argv[2]);
+
+    return pLoadedModule != NULL;
+}
+
+//-----------------------------------------------------------------------------
+
 /*! Find the specific module Id optionally at the specified version Id.
     @param moduleId The module Id to find.
     @param versionId The version Id to find.