addModuleWindow.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function AssetBrowser_addModuleWindow::onGainFirstResponder(%this)
  23. {
  24. %this-->moduleName.setFirstResponder();
  25. }
  26. function AssetBrowser_addModuleWindow::close()
  27. {
  28. Canvas.popDialog(AssetBrowser_addModule);
  29. eval(AssetBrowser_addModuleWindow.callbackFunction);
  30. }
  31. function AssetBrowser_addModuleWindow::CreateNewModule(%this)
  32. {
  33. %newModuleName = %this-->moduleName.getText();
  34. if(%newModuleName $= "")
  35. return;
  36. echo("Creating a new Module named: " @ %newModuleName);
  37. %moduleFilePath = "data/" @ %newModuleName;
  38. %moduleDefinitionFilePath = %moduleFilePath @ "/" @ %newModuleName @ ".module";
  39. %moduleScriptFilePath = %moduleFilePath @ "/" @ %newModuleName @ ".cs";
  40. %newModule = new ModuleDefinition()
  41. {
  42. ModuleId = %newModuleName;
  43. versionId = 1;
  44. ScriptFile = %newModuleName @ ".cs";
  45. CreateFunction="onCreate";
  46. DestroyFunction="onDestroy";
  47. Group = "Game";
  48. new DeclaredAssets()
  49. {
  50. Extension = "asset.taml";
  51. Recurse = true;
  52. };
  53. };
  54. TAMLWrite(%newModule, %moduleDefinitionFilePath);
  55. //Now generate the script file for it
  56. %file = new FileObject();
  57. if(%file.openForWrite(%moduleScriptFilePath))
  58. {
  59. %file.writeline("function " @ %newModuleName @ "::onCreate(%this)\n{\n\n}\n");
  60. %file.writeline("function " @ %newModuleName @ "::onDestroy(%this)\n{\n\n}\n");
  61. //todo, pre-write any event functions of interest
  62. %file.close();
  63. }
  64. //force a refresh of our modules list
  65. ModuleDatabase.ignoreLoadedGroups(true);
  66. ModuleDatabase.scanModules();
  67. %success = ModuleDatabase.loadExplicit(%newModuleName, 1);
  68. ModuleDatabase.ignoreLoadedGroups(false);
  69. //force a reload of the Module lists
  70. NewAssetModuleList.refresh();
  71. GameObjectModuleList.refresh();
  72. ImportAssetModuleList.refresh();
  73. AssetBrowser.newModuleId = %newModuleName;
  74. Canvas.popDialog(AssetBrowser_addModule);
  75. eval(AssetBrowser_addModuleWindow.callbackFunction);
  76. }
  77. function AssetBrowserModuleList::onWake(%this)
  78. {
  79. %this.refresh();
  80. }
  81. function AssetBrowserModuleList::refresh(%this)
  82. {
  83. %this.clear();
  84. //First, get our list of modules
  85. %moduleList = ModuleDatabase.findModules();
  86. %count = getWordCount(%moduleList);
  87. for(%i=0; %i < %count; %i++)
  88. {
  89. %moduleName = getWord(%moduleList, %i);
  90. %this.add(%moduleName.ModuleId, %i);
  91. }
  92. }