ProjectLibraryPanel.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. function ProjectLibraryPanel::onAdd(%this)
  2. {
  3. %this.init("Library");
  4. }
  5. function ProjectLibraryPanel::load(%this)
  6. {
  7. %this.manager = new ModuleManager();
  8. %this.manager.addListener(AssetDatabase);
  9. %this.manager.EchoInfo = false;
  10. %this.manager.ScanModules(pathConcat(getMainDotCsDir(), "library"));
  11. %allModules = %this.manager.findModules(false);
  12. for(%i = 0; %i < getWordCount(%allModules); %i++)
  13. {
  14. %mod = getWord(%allModules, %i);
  15. %this.addModule(%mod);
  16. }
  17. %this.list.sortByText();
  18. }
  19. function ProjectLibraryPanel::addModule(%this, %module)
  20. {
  21. %this.list.addItemWithID(%this.getModuleName(%module), %module);
  22. }
  23. function ProjectLibraryPanel::onOpen(%this, %allModules)
  24. {
  25. %count = %this.list.getItemCount();
  26. for(%i = 0; %i < %count; %i++)
  27. {
  28. %module = %this.list.getItemID(%i);
  29. %this.refreshColor(%module, %i, %allModules);
  30. }
  31. }
  32. function ProjectLibraryPanel::refreshColor(%this, %module, %index, %projectModules)
  33. {
  34. %color = %this.gray;
  35. if(%module.Deprecated)
  36. {
  37. %color = %this.darkRed;
  38. }
  39. for(%i = 0; %i < getWordCount(%projectModules); %i++)
  40. {
  41. %projectModule = getWord(%projectModules, %i);
  42. if(%projectModule.ModuleId $= %module.ModuleId && %projectModule.VersionId $= %module.VersionId)
  43. {
  44. %color = %this.yellow;
  45. if(%module.Deprecated)
  46. {
  47. %color = %this.darkRed;
  48. }
  49. else if(%module.BuildID > %projectModule.BuildID)
  50. {
  51. %color = %this.purple;
  52. }
  53. }
  54. }
  55. %this.list.setItemColor(%index, %color);
  56. }
  57. function ProjectLibraryPanel::onInstallClick(%this)
  58. {
  59. %index = %this.list.getSelectedItem();
  60. %module = %this.list.getItemID(%index);
  61. if(isObject(%module))
  62. {
  63. %newModulePath = pathConcat(ProjectManager.getProjectFolder(), %module.moduleID);
  64. %this.manager.CopyModule(%module.moduleID, %module.versionID, %module.moduleID, %newModulePath, false);
  65. //%this.manager.synchronizeDependencies(%module, pathConcat(ProjectManager.getProjectFolder()));
  66. %file = TamlRead(pathConcat(%newModulePath, "module.taml"));
  67. %file.Group = "";
  68. TamlWrite(%file, pathConcat(%newModulePath, "module.taml"));
  69. ModuleDatabase.ScanModules(%newModulePath);
  70. ModuleDatabase.LoadExplicit(%module.moduleID, %module.versionID);
  71. %installedModule = ModuleDatabase.findModule(%module.moduleID, %module.versionID);
  72. %this.list.setItemColor(%index, "255 255 100 255");
  73. %file = TamlRead(pathConcat(%newModulePath, "module.taml"));
  74. %file.Group = "gameBase";
  75. TamlWrite(%file, pathConcat(%newModulePath, "module.taml"));
  76. %this.postEvent("ModuleInstalled", %installedModule);
  77. }
  78. }
  79. function ProjectLibraryPanel::onUpdateClick(%this)
  80. {
  81. }