moduleDefinition_ScriptBinding.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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. ConsoleMethodGroupBeginWithDocs(ModuleDefinition, SimSet)
  23. /*! Saves the module definition to the file it was loaded from (if any).
  24. @return (bool success) Whether the module definition was saved or not.
  25. */
  26. ConsoleMethodWithDocs(ModuleDefinition, save, ConsoleBool, 2, 2, ())
  27. {
  28. // Save.
  29. return object->save();
  30. }
  31. //-----------------------------------------------------------------------------
  32. /*! Gets the module manager which this module definition is registered with (if any).
  33. @return (moduleManager) The module manager which this module definition is registered with (zero if not registered).
  34. */
  35. ConsoleMethodWithDocs(ModuleDefinition, getModuleManager, ConsoleInt, 2, 2, ())
  36. {
  37. // Fetch module manager.
  38. ModuleManager* pModuleManager = object->getModuleManager();
  39. return pModuleManager != NULL ? pModuleManager->getId() : 0;
  40. }
  41. //-----------------------------------------------------------------------------
  42. /*! Gets the number of module dependencies this module definition has.
  43. @return (int count) The number of module dependencies this module definition has.
  44. */
  45. ConsoleMethodWithDocs(ModuleDefinition, getDependencyCount, ConsoleInt, 2, 2, ())
  46. {
  47. // Get module dependency count.
  48. return object->getDependencyCount();
  49. }
  50. //-----------------------------------------------------------------------------
  51. /*! Gets the module dependency at the specified index.
  52. @param dependencyIndex The module dependency index.
  53. @return (module-dependency) The module dependency at the specified index.
  54. */
  55. ConsoleMethodWithDocs(ModuleDefinition, getDependency, ConsoleString, 3, 3, (int dependencyIndex))
  56. {
  57. // Fetch dependency index.
  58. const U32 dependencyIndex = (U32)dAtoi(argv[2]);
  59. // Get module dependency.
  60. ModuleDefinition::ModuleDependency dependency;
  61. if ( object->getDependency( dependencyIndex, dependency ) == false )
  62. return StringTable->EmptyString;
  63. // Format module dependency.
  64. char* pReturnBuffer = Con::getReturnBuffer( 256 );
  65. dSprintf( pReturnBuffer, 256, "%s %d", dependency.mModuleId, dependency.mVersionId );
  66. return pReturnBuffer;
  67. }
  68. //-----------------------------------------------------------------------------
  69. /*! Adds the specified moduleId and vesionId as a dependency.
  70. @param moduleId The module Id to add as a dependency.
  71. @param versionId The version Id to add as a dependency. Using zero indicates any version.
  72. @return (bool success) Whether the module dependency was added or not.
  73. */
  74. ConsoleMethodWithDocs(ModuleDefinition, addDependency, ConsoleBool, 4, 4, (moduleId, versionId))
  75. {
  76. // Fetch module Id.
  77. const char* pModuleId = argv[2];
  78. // Fetch version Id.
  79. const U32 versionId = (U32)dAtoi(argv[3]);
  80. // Add dependency.
  81. return object->addDependency( pModuleId, versionId );
  82. }
  83. //-----------------------------------------------------------------------------
  84. /*! Removes the specified moduleId as a dependency.
  85. @param moduleId The module Id to remove as a dependency.
  86. @return (bool success) Whether the module dependency was removed or not.
  87. */
  88. ConsoleMethodWithDocs(ModuleDefinition, removeDependency, ConsoleBool, 3, 3, (moduleId))
  89. {
  90. // Fetch module Id.
  91. const char* pModuleId = argv[2];
  92. // Remove dependency.
  93. return object->removeDependency( pModuleId );
  94. }
  95. ConsoleMethodGroupEndWithDocs(ModuleDefinition)