Skeleton_ScriptBinding.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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(Skeleton, SceneObject)
  23. /*! Sets the skeleton asset Id to use.
  24. @param skeletonAssetId The skeleton asset Id to use.
  25. @return No return value.
  26. */
  27. ConsoleMethodWithDocs(Skeleton, setSkeletonAsset, ConsoleVoid, 3, 3, (skeletonAssetId?))
  28. {
  29. object->setSkeletonAsset( argv[2] );
  30. }
  31. //-----------------------------------------------------------------------------
  32. /*! Gets the skeleton asset Id.
  33. @return The skeleton asset Id.
  34. */
  35. ConsoleMethodWithDocs(Skeleton, getSkeletonAsset, ConsoleString, 2, 2, ())
  36. {
  37. return object->getSkeletonAsset();
  38. }
  39. //-----------------------------------------------------------------------------
  40. /*! Sets the animation for the object.
  41. @param animationName String containing animation name.
  42. @param cycle Optional bool to determine whether the animation should loop.
  43. @return Returns true on success."
  44. */
  45. ConsoleMethodWithDocs(Skeleton, setAnimation, ConsoleBool, 3, 4, (animationName, [cycle]))
  46. {
  47. // Determine looping
  48. bool shouldLoop = argc >= 4 ? dAtob(argv[3]) : false;
  49. return object->setCurrentAnimation(argv[2], shouldLoop);
  50. }
  51. //-----------------------------------------------------------------------------
  52. /*! Gets the name of the current animation.
  53. @return String containing the animation name.
  54. */
  55. ConsoleMethodWithDocs(Skeleton, getAnimation, ConsoleString, 2, 2, ())
  56. {
  57. return object->getCurrentAnimation();
  58. }
  59. //-----------------------------------------------------------------------------
  60. /*! Sets the skin for the skeleton.
  61. @return No return value.
  62. */
  63. ConsoleMethodWithDocs(Skeleton, setSkin, ConsoleVoid, 3, 3, (skinName))
  64. {
  65. object->setCurrentSkin(argv[2]);
  66. }
  67. //-----------------------------------------------------------------------------
  68. /*! Gets the name of the current skin.
  69. @return String containing the skin name.
  70. */
  71. ConsoleMethodWithDocs(Skeleton, getSkin, ConsoleString, 2, 2, ())
  72. {
  73. return object->getCurrentSkin();
  74. }
  75. //-----------------------------------------------------------------------------
  76. /*! Sets scaling of the skeleton's root bone.
  77. @param scaleX Base x coordinate scale.
  78. @param scaleY Base y coordinate scale.
  79. @return No return value.
  80. */
  81. ConsoleMethodWithDocs(Skeleton, setRootBoneScale, ConsoleVoid, 3, 4, (float scaleX, float scaleY))
  82. {
  83. F32 scaleX, scaleY;
  84. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  85. // ("width height")
  86. if ((elementCount == 2) && (argc == 3))
  87. {
  88. scaleX = dAtof(Utility::mGetStringElement(argv[2], 0));
  89. scaleY = dAtof(Utility::mGetStringElement(argv[2], 1));
  90. }
  91. // (width, [height])
  92. else if (elementCount == 1)
  93. {
  94. scaleX = dAtof(argv[2]);
  95. if (argc > 3)
  96. scaleY = dAtof(argv[3]);
  97. else
  98. scaleY = scaleX;
  99. }
  100. // Invalid
  101. else
  102. {
  103. Con::warnf("Skeleton::setRootBoneScale() - Invalid number of parameters!");
  104. return;
  105. }
  106. // Set Size.
  107. object->setSkeletonScale(Vector2(scaleX, scaleY));
  108. }
  109. //-----------------------------------------------------------------------------
  110. /*! Gets the skeleton's root bone scale.
  111. @return (float x/y height) The x and y scale of the object's root bone.
  112. */
  113. ConsoleMethodWithDocs(Skeleton, getRootBoneScale, ConsoleString, 2, 2, ())
  114. {
  115. return object->getSkeletonScale().scriptThis();
  116. }
  117. //-----------------------------------------------------------------------------
  118. /*! Sets local offset of the skeleton's root bone.
  119. @param x Base x coordinate.
  120. @param y Base y coordinate.
  121. @return No return value.
  122. */
  123. ConsoleMethodWithDocs(Skeleton, setRootBoneOffset, ConsoleVoid, 3, 4, (float x, float y))
  124. {
  125. F32 x, y;
  126. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  127. // ("x y")
  128. if ((elementCount == 2) && (argc == 3))
  129. {
  130. x = dAtof(Utility::mGetStringElement(argv[2], 0));
  131. y = dAtof(Utility::mGetStringElement(argv[2], 1));
  132. }
  133. // (x, [y])
  134. else if (elementCount == 1)
  135. {
  136. x = dAtof(argv[2]);
  137. if (argc > 3)
  138. y = dAtof(argv[3]);
  139. else
  140. y = x;
  141. }
  142. // Invalid
  143. else
  144. {
  145. Con::warnf("Skeleton::setRootBoneOffset() - Invalid number of parameters!");
  146. return;
  147. }
  148. // Set Size.
  149. object->setSkeletonOffset(Vector2(x, y));
  150. }
  151. //-----------------------------------------------------------------------------
  152. /*! Gets the skeleton's root bone offset.
  153. @return (float x/y) The x and y offset of the object's root bone.
  154. */
  155. ConsoleMethodWithDocs(Skeleton, getRootBoneOffset, ConsoleString, 2, 2, ())
  156. {
  157. return object->getSkeletonOffset().scriptThis();
  158. }
  159. //-----------------------------------------------------------------------------
  160. /*! Gets the duration of the current animation.
  161. @return Duration of the animation in seconds.
  162. */
  163. ConsoleMethodWithDocs(Skeleton, getAnimationDuration, ConsoleFloat, 2, 2, ())
  164. {
  165. return object->getAnimationDuration();
  166. }
  167. //-----------------------------------------------------------------------------
  168. /*! Mixes the current animation with another.
  169. @param animation The name of the animation to mix.
  170. @param time The time to start mixing.
  171. */
  172. ConsoleMethodWithDocs(Skeleton, setMix, ConsoleBool, 5, 5, (fromAnimation, toAnimation, time))
  173. {
  174. Con::printf("Mixing %s with %s at %f", argv[2], argv[3], dAtof(argv[4]));
  175. return object->setMix(argv[2], argv[3], dAtof(argv[4]));
  176. }
  177. ConsoleMethodGroupEndWithDocs(Skeleton)