AnimationAsset_ScriptBinding.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. ConsoleMethod(AnimationAsset, setImage, void, 3, 3, "(assetId) Sets the image asset Id.\n"
  23. "@return No return value.")
  24. {
  25. object->setImage( argv[2] );
  26. }
  27. //-----------------------------------------------------------------------------
  28. ConsoleMethod(AnimationAsset, getImage, const char*, 2, 2, "() Gets the image asset Id.\n"
  29. "@return The image asset Id.")
  30. {
  31. return object->getImage().getAssetId();
  32. }
  33. //-----------------------------------------------------------------------------
  34. ConsoleMethod(AnimationAsset, setAnimationFrames, void, 3, 3, "(animationFrames) Sets the image frames that compose the animation.\n"
  35. "@param animationFrames A set of image frames that compose the animation.\n"
  36. "@return No return value.")
  37. {
  38. object->setAnimationFrames( argv[2] );
  39. }
  40. //-----------------------------------------------------------------------------
  41. ConsoleMethod(AnimationAsset, getAnimationFrames, const char*, 2, 3, "([bool validatedFrames]) Gets the frames that compose the animation or optionally only the ones validated against the image asset.\n"
  42. "@param validatedFrames - Whether to return only the validated frames or not. Optional: Default is false.\n"
  43. "@return The image frames that compose the animation or optionally only the ones validated against the image asset.")
  44. {
  45. // Fetch a return buffer.
  46. S32 bufferSize = 4096;
  47. char* pBuffer = Con::getReturnBuffer( bufferSize );
  48. char* pReturnBuffer = pBuffer;
  49. // Fetch validated frames flag.
  50. const bool validatedFrames = argc >= 3 ? dAtob( argv[2] ) : false;
  51. // Fetch specified frames.
  52. const Vector<S32>& frames = validatedFrames ? object->getValidatedAnimationFrames() : object->getSpecifiedAnimationFrames();
  53. // Fetch frame count.
  54. const U32 frameCount = (U32)frames.size();
  55. // Format frames.
  56. for ( U32 frameIndex = 0; frameIndex < frameCount; ++frameIndex )
  57. {
  58. const S32 offset = dSprintf( pBuffer, bufferSize, "%d ", frames[frameIndex] );
  59. pBuffer += offset;
  60. bufferSize -= offset;
  61. }
  62. // Return frames.
  63. return pReturnBuffer;
  64. }
  65. //-----------------------------------------------------------------------------
  66. ConsoleMethod(AnimationAsset, getAnimationFrameCount, S32, 2, 3, "([bool validatedFrames]) Gets the count of frame that compose the animation or optionally only the ones validated against the image asset.\n"
  67. "@param validatedFrames - Whether to return only the validated frames or not. Optional: Default is false.\n"
  68. "@return The image frames that compose the animation or optionally only the ones validated against the image asset.")
  69. {
  70. // Fetch validated frames flag.
  71. const bool validatedFrames = argc >= 3 ? dAtob( argv[2] ) : false;
  72. // Fetch specified frames.
  73. const Vector<S32>& frames = validatedFrames ? object->getValidatedAnimationFrames() : object->getSpecifiedAnimationFrames();
  74. return frames.size();
  75. }
  76. //-----------------------------------------------------------------------------
  77. ConsoleMethod(AnimationAsset, setAnimationTime, void, 3, 3, "(float animationTime) Sets the total time to cycle through all animation frames.\n"
  78. "@param animationTime The total time to cycle through all animation frames.\n"
  79. "@return No return value.")
  80. {
  81. object->setAnimationTime( dAtof(argv[2] ) );
  82. }
  83. //-----------------------------------------------------------------------------
  84. ConsoleMethod(AnimationAsset, getAnimationTime, F32, 2, 2, "() Gets the total time to cycle through all animation frames.\n"
  85. "@return The total time to cycle through all animation frames.")
  86. {
  87. return object->getAnimationTime();
  88. }
  89. //-----------------------------------------------------------------------------
  90. ConsoleMethod(AnimationAsset, setAnimationCycle, void, 3, 3, "(bool animationCycle) Sets whether the animation cycles or not.\n"
  91. "@param animationCycle Whether the animation cycles or not.\n"
  92. "@return No return value.")
  93. {
  94. object->setAnimationCycle( dAtob(argv[2] ) );
  95. }
  96. //-----------------------------------------------------------------------------
  97. ConsoleMethod(AnimationAsset, getAnimationCycle, bool, 2, 2, "() Gets whether the animation cycles or not.\n"
  98. "@return Whether the animation cycles or not.")
  99. {
  100. return object->getAnimationCycle();
  101. }