AnimationAsset_ScriptBinding.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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(AnimationAsset, AssetBase)
  23. /*! Sets the image asset Id.
  24. @return No return value.
  25. */
  26. ConsoleMethodWithDocs(AnimationAsset, setImage, ConsoleVoid, 3, 3, (assetId))
  27. {
  28. object->setImage( argv[2] );
  29. }
  30. //-----------------------------------------------------------------------------
  31. /*! Gets the image asset Id.
  32. @return The image asset Id.
  33. */
  34. ConsoleMethodWithDocs(AnimationAsset, getImage, ConsoleString, 2, 2, ())
  35. {
  36. return object->getImage().getAssetId();
  37. }
  38. //-----------------------------------------------------------------------------
  39. /*! Sets the image frames that compose the animation.
  40. @param animationFrames A set of image frames that compose the animation.
  41. @return No return value.
  42. */
  43. ConsoleMethodWithDocs(AnimationAsset, setAnimationFrames, ConsoleVoid, 3, 3, (animationFrames))
  44. {
  45. // Are we in named cells mode?
  46. if ( object->getNamedCellsMode() )
  47. {
  48. // Yes, so warn.
  49. Con::warnf( "AnimationAsset::setAnimationFrames() - Method invalid, in named cells mode." );
  50. return;
  51. }
  52. object->setAnimationFrames( argv[2] );
  53. }
  54. //-----------------------------------------------------------------------------
  55. /*! Gets the frames that compose the animation or optionally only the ones validated against the image asset.
  56. @param validatedFrames - Whether to return only the validated frames or not. Optional: Default is false.
  57. @return The image frames that compose the animation or optionally only the ones validated against the image asset.
  58. */
  59. ConsoleMethodWithDocs(AnimationAsset, getAnimationFrames, ConsoleString, 2, 3, ([bool validatedFrames]))
  60. {
  61. // Are we in named cells mode?
  62. if ( object->getNamedCellsMode() )
  63. {
  64. // Yes, so warn.
  65. Con::warnf( "AnimationAsset::getAnimationFrames() - Method invalid, in named cells mode." );
  66. return StringTable->EmptyString;
  67. }
  68. // Fetch a return buffer.
  69. S32 bufferSize = 4096;
  70. char* pBuffer = Con::getReturnBuffer( bufferSize );
  71. char* pReturnBuffer = pBuffer;
  72. // Fetch validated frames flag.
  73. const bool validatedFrames = argc >= 3 ? dAtob( argv[2] ) : false;
  74. // Fetch specified frames.
  75. const Vector<S32>& frames = validatedFrames ? object->getValidatedAnimationFrames() : object->getSpecifiedAnimationFrames();
  76. // Fetch frame count.
  77. const U32 frameCount = (U32)frames.size();
  78. // Format frames.
  79. for ( U32 frameIndex = 0; frameIndex < frameCount; ++frameIndex )
  80. {
  81. const S32 offset = dSprintf( pBuffer, bufferSize, "%d ", frames[frameIndex] );
  82. pBuffer += offset;
  83. bufferSize -= offset;
  84. }
  85. // Return frames.
  86. return pReturnBuffer;
  87. }
  88. //-----------------------------------------------------------------------------
  89. /*! Gets the count of frame that compose the animation or optionally only the ones validated against the image asset.
  90. @param validatedFrames - Whether to return only the validated frames or not. Optional: Default is false.
  91. @return The image frames that compose the animation or optionally only the ones validated against the image asset.
  92. */
  93. ConsoleMethodWithDocs(AnimationAsset, getAnimationFrameCount, ConsoleInt, 2, 3, ([bool validatedFrames]))
  94. {
  95. // Are we in named cells mode?
  96. if ( object->getNamedCellsMode() )
  97. {
  98. // Yes, so warn.
  99. Con::warnf( "AnimationAsset::getAnimationFrameCount() - Method invalid, in named cells mode." );
  100. return -1;
  101. }
  102. // Fetch validated frames flag.
  103. const bool validatedFrames = argc >= 3 ? dAtob( argv[2] ) : false;
  104. // Fetch specified frames.
  105. const Vector<S32>& frames = validatedFrames ? object->getValidatedAnimationFrames() : object->getSpecifiedAnimationFrames();
  106. return frames.size();
  107. }
  108. //-----------------------------------------------------------------------------
  109. /*! Sets the named image frames that compose the animation.
  110. @param animationFrames A set of named image frames that compose the animation.
  111. @return No return value.
  112. */
  113. ConsoleMethodWithDocs(AnimationAsset, setNamedAnimationFrames, ConsoleVoid, 3, 3, (animationFrames))
  114. {
  115. // Are we in named cells mode?
  116. if ( !object->getNamedCellsMode() )
  117. {
  118. // No, so warn.
  119. Con::warnf( "AnimationAsset::setNamedAnimationFrames() - Method invalid, not in named cells mode." );
  120. return;
  121. }
  122. object->setNamedAnimationFrames( argv[2] );
  123. }
  124. //-----------------------------------------------------------------------------
  125. /*! Gets the named frames that compose the animation or optionally only the ones validated against the image asset.
  126. @param validatedFrames - Whether to return only the validated frames or not. Optional: Default is false.
  127. @return The named image frames that compose the animation or optionally only the ones validated against the image asset.
  128. */
  129. ConsoleMethodWithDocs(AnimationAsset, getNamedAnimationFrames, ConsoleString, 2, 3, ([bool validatedFrames]))
  130. {
  131. // Are we in named cells mode?
  132. if ( !object->getNamedCellsMode() )
  133. {
  134. // No, so warn.
  135. Con::warnf( "AnimationAsset::getNamedAnimationFrames() - Method invalid, not in named cells mode." );
  136. return StringTable->EmptyString;
  137. }
  138. // Fetch a return buffer.
  139. S32 bufferSize = 4096;
  140. char* pBuffer = Con::getReturnBuffer( bufferSize );
  141. char* pReturnBuffer = pBuffer;
  142. // Fetch validated frames flag.
  143. const bool validatedFrames = argc >= 3 ? dAtob( argv[2] ) : false;
  144. // Fetch specified frames.
  145. const Vector<StringTableEntry>& frames = validatedFrames ? object->getValidatedNamedAnimationFrames() : object->getSpecifiedNamedAnimationFrames();
  146. // Fetch frame count.
  147. const U32 frameCount = (U32)frames.size();
  148. // Format frames.
  149. for ( U32 frameIndex = 0; frameIndex < frameCount; ++frameIndex )
  150. {
  151. const S32 offset = dSprintf( pBuffer, bufferSize, "%d ", frames[frameIndex] );
  152. pBuffer += offset;
  153. bufferSize -= offset;
  154. }
  155. // Return frames.
  156. return pReturnBuffer;
  157. }
  158. //-----------------------------------------------------------------------------
  159. /*! Gets the count of named frames that compose the animation or optionally only the ones validated against the image asset.
  160. @param validatedFrames - Whether to return only the validated frames or not. Optional: Default is false.
  161. @return The named image frames that compose the animation or optionally only the ones validated against the image asset.
  162. */
  163. ConsoleMethodWithDocs(AnimationAsset, getNamedAnimationFrameCount, ConsoleInt, 2, 3, ([bool validatedFrames]))
  164. {
  165. // Are we in named cells mode?
  166. if ( !object->getNamedCellsMode() )
  167. {
  168. // No, so warn.
  169. Con::warnf( "AnimationAsset::getNamedAnimationFrameCount() - Method invalid, not in named cells mode." );
  170. return -1;
  171. }
  172. // Fetch validated frames flag.
  173. const bool validatedFrames = argc >= 3 ? dAtob( argv[2] ) : false;
  174. // Fetch specified frames.
  175. const Vector<StringTableEntry>& frames = validatedFrames ? object->getValidatedNamedAnimationFrames() : object->getSpecifiedNamedAnimationFrames();
  176. return frames.size();
  177. }
  178. //-----------------------------------------------------------------------------
  179. /*! Sets the total time to cycle through all animation frames.
  180. @param animationTime The total time to cycle through all animation frames.
  181. @return No return value.
  182. */
  183. ConsoleMethodWithDocs(AnimationAsset, setAnimationTime, ConsoleVoid, 3, 3, (float animationTime))
  184. {
  185. object->setAnimationTime( dAtof(argv[2] ) );
  186. }
  187. //-----------------------------------------------------------------------------
  188. /*! Gets the total time to cycle through all animation frames.
  189. @return The total time to cycle through all animation frames.
  190. */
  191. ConsoleMethodWithDocs(AnimationAsset, getAnimationTime, ConsoleFloat, 2, 2, ())
  192. {
  193. return object->getAnimationTime();
  194. }
  195. //-----------------------------------------------------------------------------
  196. /*! Sets whether the animation cycles or not.
  197. @param animationCycle Whether the animation cycles or not.
  198. @return No return value.
  199. */
  200. ConsoleMethodWithDocs(AnimationAsset, setAnimationCycle, ConsoleVoid, 3, 3, (bool animationCycle))
  201. {
  202. object->setAnimationCycle( dAtob(argv[2] ) );
  203. }
  204. //-----------------------------------------------------------------------------
  205. /*! Gets whether the animation cycles or not.
  206. @return Whether the animation cycles or not.
  207. */
  208. ConsoleMethodWithDocs(AnimationAsset, getAnimationCycle, ConsoleBool, 2, 2, ())
  209. {
  210. return object->getAnimationCycle();
  211. }
  212. //-----------------------------------------------------------------------------
  213. /*! Sets whether the animation uses names for cells, instead of numerical index.
  214. @param namedCellsMode True if it should be using named cells.
  215. @return No return value.
  216. */
  217. ConsoleMethodWithDocs(AnimationAsset, setNamedCellsMode, ConsoleVoid, 3, 3, ())
  218. {
  219. object->setNamedCellsMode( dAtob(argv[2] ) );
  220. }
  221. //-----------------------------------------------------------------------------
  222. /*! Gets whether the animation is using names for its cells.
  223. @return True if the animation is using named cells.
  224. */
  225. ConsoleMethodWithDocs(AnimationAsset, getNamedCellsMode, ConsoleBool, 2, 2, ())
  226. {
  227. return object->getNamedCellsMode();
  228. }
  229. ConsoleMethodGroupEndWithDocs(AnimationAsset)