simComponent_ScriptBinding.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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(SimComponent, SimObject)
  23. /*! Adds additional components to current list.
  24. @param Up to 62 component names
  25. @return Returns true on success, false otherwise.
  26. */
  27. ConsoleMethodWithDocs( SimComponent, addComponents, ConsoleBool, 3, 64, ( compObjName, compObjName2, ... ))
  28. {
  29. for(S32 i = 2; i < argc; i++)
  30. {
  31. SimComponent *obj = dynamic_cast<SimComponent*> (Sim::findObject(argv[i]) );
  32. if(obj)
  33. object->addComponent(obj);
  34. else
  35. Con::printf("SimComponent::addComponents - Invalid Component Object \"%s\"", argv[i]);
  36. }
  37. return true;
  38. }
  39. /*! Removes components by name from current list.
  40. @param objNamex Up to 62 component names
  41. @return Returns true on success, false otherwise.
  42. */
  43. ConsoleMethodWithDocs( SimComponent, removeComponents, ConsoleBool, 3, 64, ( compObjName, compObjName2, ... ))
  44. {
  45. for(S32 i = 2; i < argc; i++)
  46. {
  47. SimComponent *obj = dynamic_cast<SimComponent*> (Sim::findObject(argv[i]) );
  48. if(obj)
  49. object->removeComponent(obj);
  50. else
  51. Con::printf("SimComponent::removeComponents - Invalid Component Object \"%s\"", argv[i]);
  52. }
  53. return true;
  54. }
  55. /*! Get the current component count
  56. @return The number of components in the list as an integer
  57. */
  58. ConsoleMethodWithDocs( SimComponent, getComponentCount, ConsoleInt, 2, 2, ())
  59. {
  60. return object->getComponentCount();
  61. }
  62. /*! Get the component corresponding to the given index.
  63. @param idx An integer index value corresponding to the desired component.
  64. @return The id of the component at the given index as an integer
  65. */
  66. ConsoleMethodWithDocs( SimComponent, getComponent, ConsoleInt, 3, 3, (idx))
  67. {
  68. S32 idx = dAtoi(argv[2]);
  69. if(idx < 0 || idx >= (S32)object->getComponentCount())
  70. {
  71. Con::errorf("SimComponent::getComponent - Invalid index %d", idx);
  72. return 0;
  73. }
  74. SimComponent *c = object->getComponent(idx);
  75. return c ? c->getId() : 0;
  76. }
  77. /*! Sets or unsets the enabled flag
  78. @param enabled Boolean value
  79. @return No return value
  80. */
  81. ConsoleMethodWithDocs(SimComponent, setEnabled, ConsoleVoid, 3, 3, (enabled))
  82. {
  83. object->setEnabled(dAtob(argv[2]));
  84. }
  85. /*! Check whether SimComponent is currently enabled
  86. @return true if enabled and false if not
  87. */
  88. ConsoleMethodWithDocs(SimComponent, isEnabled, ConsoleBool, 2, 2, ())
  89. {
  90. return object->isEnabled();
  91. }
  92. ConsoleMethodGroupEndWithDocs(SimComponent)