SkeletonObject_ScriptBinding.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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(SkeletonObject, 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(SkeletonObject, 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(SkeletonObject, 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(SkeletonObject, setAnimationName, ConsoleBool, 3, 4, (animationName, [cycle]))
  46. {
  47. // Determine looping
  48. bool shouldLoop = argc >= 4 ? dAtob(argv[3]) : false;
  49. return object->setAnimationName(argv[2], shouldLoop);
  50. }
  51. //-----------------------------------------------------------------------------
  52. /*! Gets the name of the current animation.
  53. @return String containing the animation name.
  54. */
  55. ConsoleMethodWithDocs(SkeletonObject, getAnimationName, ConsoleString, 2, 2, ())
  56. {
  57. return object->getAnimationName();
  58. }
  59. //-----------------------------------------------------------------------------
  60. /*! Sets the skin for the skeleton.
  61. @return No return value.
  62. */
  63. ConsoleMethodWithDocs(SkeletonObject, 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(SkeletonObject, 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(SkeletonObject, 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("SkeletonObject::setRootBoneScale() - Invalid number of parameters!");
  104. return;
  105. }
  106. // Set Scale.
  107. object->setRootBoneScale(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(SkeletonObject, getRootBoneScale, ConsoleString, 2, 2, ())
  114. {
  115. return object->getRootBoneScale().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(SkeletonObject, 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("SkeletonObject::setRootBoneOffset() - Invalid number of parameters!");
  146. return;
  147. }
  148. // Set Size.
  149. object->setRootBoneOffset(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(SkeletonObject, getRootBoneOffset, ConsoleString, 2, 2, ())
  156. {
  157. return object->getRootBoneOffset().scriptThis();
  158. }
  159. //-----------------------------------------------------------------------------
  160. /*! Sets whether the animation cycles or not.
  161. @param cycle Bool to determine whether the animation should loop.
  162. @return No return value.
  163. */
  164. ConsoleMethodWithDocs(SkeletonObject, setAnimationCycle, ConsoleVoid, 3, 3, (bool cycle))
  165. {
  166. object->setAnimationCycle( dAtob(argv[2] ) );
  167. }
  168. //-----------------------------------------------------------------------------
  169. /*! Gets whether the animation cycles or not.
  170. @return Whether the animation cycles or not.
  171. */
  172. ConsoleMethodWithDocs(SkeletonObject, getAnimationCycle, ConsoleBool, 2, 2, ())
  173. {
  174. return object->getAnimationCycle();
  175. }
  176. //-----------------------------------------------------------------------------
  177. /*! Sets the sprite texture flipping for each axis.
  178. @param flipX Whether or not to flip the texture along the x (horizontal) axis.
  179. @param flipY Whether or not to flip the texture along the y (vertical) axis.
  180. @return No return value.
  181. */
  182. ConsoleMethodWithDocs(SkeletonObject, setFlip, ConsoleVoid, 4, 4, (bool flipX, bool flipY))
  183. {
  184. // Set Flip.
  185. object->setFlip( dAtob(argv[2]), dAtob(argv[3]) );
  186. }
  187. //-----------------------------------------------------------------------------
  188. /*! Gets the flip for each axis.
  189. @return (bool flipX/bool flipY) Whether or not the texture is flipped along the x and y axis.
  190. */
  191. ConsoleMethodWithDocs(SkeletonObject, getFlip, ConsoleString, 2, 2, ())
  192. {
  193. // Create Returnable Buffer.
  194. char* pBuffer = Con::getReturnBuffer(32);
  195. // Format Buffer.
  196. dSprintf(pBuffer, 32, "%d %d", object->getFlipX(), object->getFlipY());
  197. // Return Buffer.
  198. return pBuffer;
  199. }
  200. //-----------------------------------------------------------------------------
  201. /*! Sets whether or not the texture is flipped horizontally.
  202. @param flipX Whether or not to flip the texture along the x (horizontal) axis.
  203. @return No return value.
  204. */
  205. ConsoleMethodWithDocs(SkeletonObject, setFlipX, ConsoleVoid, 3, 3, (bool flipX))
  206. {
  207. // Set Flip.
  208. object->setFlipX( dAtob(argv[2]) );
  209. }
  210. //-----------------------------------------------------------------------------
  211. /*! Sets whether or not the texture is flipped vertically.
  212. @param flipY Whether or not to flip the texture along the y (vertical) axis.
  213. @return No return value.
  214. */
  215. ConsoleMethodWithDocs(SkeletonObject, setFlipY, ConsoleVoid, 3, 3, (bool flipY))
  216. {
  217. // Set Flip.
  218. object->setFlipY( dAtob(argv[2]) );
  219. }
  220. //-----------------------------------------------------------------------------
  221. /*! Gets whether or not the texture is flipped horizontally.
  222. @return (bool flipX) Whether or not the texture is flipped along the x axis.
  223. */
  224. ConsoleMethodWithDocs(SkeletonObject, getFlipX, ConsoleBool, 2, 2, ())
  225. {
  226. return object->getFlipX();
  227. }
  228. //-----------------------------------------------------------------------------
  229. /*! Gets whether or not the texture is flipped vertically.
  230. @return (bool flipY) Whether or not the texture is flipped along the y axis.
  231. */
  232. ConsoleMethodWithDocs(SkeletonObject, getFlipY, ConsoleBool, 2, 2, ())
  233. {
  234. return object->getFlipY();
  235. }
  236. //-----------------------------------------------------------------------------
  237. /*! Gets the duration of the current animation.
  238. @return Duration of the animation in seconds.
  239. */
  240. ConsoleMethodWithDocs(SkeletonObject, getAnimationDuration, ConsoleFloat, 2, 2, ())
  241. {
  242. return object->getAnimationDuration();
  243. }
  244. //-----------------------------------------------------------------------------
  245. /*! Mixes the current animation with another.
  246. @param animation The name of the animation to mix.
  247. @param time The time to start mixing.
  248. */
  249. ConsoleMethodWithDocs(SkeletonObject, setMix, ConsoleBool, 5, 5, (fromAnimation, toAnimation, time))
  250. {
  251. Con::printf("Mixing %s with %s at %f", argv[2], argv[3], dAtof(argv[4]));
  252. return object->setMix(argv[2], argv[3], dAtof(argv[4]));
  253. }
  254. ConsoleMethodGroupEndWithDocs(SkeletonObject)