AnimationAsset.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #ifndef _ANIMATION_ASSET_H_
  23. #define _ANIMATION_ASSET_H_
  24. #ifndef _ASSET_PTR_H_
  25. #include "assets/assetPtr.h"
  26. #endif
  27. //-----------------------------------------------------------------------------
  28. DefineConsoleType( TypeAnimationAssetPtr )
  29. //-----------------------------------------------------------------------------
  30. class ImageAsset;
  31. //-----------------------------------------------------------------------------
  32. class AnimationAsset : public AssetBase
  33. {
  34. private:
  35. typedef AssetBase Parent;
  36. AssetPtr<ImageAsset> mImageAsset;
  37. Vector<S32> mAnimationFrames;
  38. Vector<StringTableEntry> mNamedAnimationFrames;
  39. Vector<S32> mValidatedFrames;
  40. Vector<StringTableEntry> mValidatedNameFrames;
  41. F32 mAnimationTime;
  42. bool mAnimationCycle;
  43. bool mRandomStart;
  44. F32 mAnimationIntegration;
  45. bool mNamedCellsMode;
  46. public:
  47. AnimationAsset();
  48. virtual ~AnimationAsset();
  49. static void initPersistFields();
  50. virtual bool onAdd();
  51. virtual void onRemove();
  52. virtual void copyTo(SimObject* object);
  53. void setImage( const char* pAssetId );
  54. inline const AssetPtr<ImageAsset>& getImage( void ) const { return mImageAsset; }
  55. void setAnimationFrames( const char* pAnimationFrames );
  56. inline const Vector<S32>& getSpecifiedAnimationFrames( void ) const { return mAnimationFrames; }
  57. inline const Vector<S32>& getValidatedAnimationFrames( void ) const { return mValidatedFrames; }
  58. void setNamedAnimationFrames( const char* pAnimationFrames );
  59. inline const Vector<StringTableEntry>& getSpecifiedNamedAnimationFrames( void ) const { return mNamedAnimationFrames; }
  60. inline const Vector<StringTableEntry>& getValidatedNamedAnimationFrames( void ) const { return mValidatedNameFrames; }
  61. void setAnimationTime( const F32 animationTime );
  62. inline F32 getAnimationTime( void ) const { return mAnimationTime; }
  63. void setAnimationCycle( const bool animationCycle );
  64. inline bool getAnimationCycle( void ) const { return mAnimationCycle; }
  65. void setRandomStart( const bool randomStart );
  66. inline bool getRandomStart( void ) const { return mRandomStart; }
  67. void setNamedCellsMode( const bool namedCellsMode );
  68. inline bool getNamedCellsMode( void ) const { return mNamedCellsMode; }
  69. // Frame validation.
  70. void validateFrames( void );
  71. void validateNumericalFrames( void );
  72. void validateNamedFrames( void );
  73. // Asset validation.
  74. virtual bool isAssetValid( void ) const;
  75. /// Declare Console Object.
  76. DECLARE_CONOBJECT(AnimationAsset);
  77. protected:
  78. virtual void initializeAsset( void );
  79. virtual void onAssetRefresh( void );
  80. protected:
  81. static bool setImage( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setImage( data ); return false; }
  82. static bool writeImage( void* obj, StringTableEntry pFieldName ) { return static_cast<AnimationAsset*>(obj)->mImageAsset.notNull(); }
  83. static bool setAnimationFrames( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setAnimationFrames( data ); return false; }
  84. static bool writeAnimationFrames( void* obj, StringTableEntry pFieldName ) { return static_cast<AnimationAsset*>(obj)->mAnimationFrames.size() > 0; }
  85. static bool setNamedAnimationFrames( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setNamedAnimationFrames( data ); return false; }
  86. static bool writeNamedAnimationFrames( void* obj, StringTableEntry pFieldName ) { return static_cast<AnimationAsset*>(obj)->mNamedAnimationFrames.size() > 0; }
  87. static bool setAnimationTime( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setAnimationTime( dAtof(data) ); return false; }
  88. static bool setAnimationCycle( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setAnimationCycle( dAtob(data) ); return false; }
  89. static bool writeAnimationCycle( void* obj, StringTableEntry pFieldName ) { return static_cast<AnimationAsset*>(obj)->getAnimationCycle() == false; }
  90. static bool setRandomStart( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setRandomStart( dAtob(data) ); return false; }
  91. static bool writeRandomStart( void* obj, StringTableEntry pFieldName ) { return static_cast<AnimationAsset*>(obj)->getRandomStart() == true; }
  92. static bool setNamedCellsMode( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setNamedCellsMode( dAtob(data) ); return false; }
  93. static bool writeNamedCellsMode( void* obj, StringTableEntry pFieldName ) { return static_cast<AnimationAsset*>(obj)->getNamedCellsMode() == true; }
  94. };
  95. #endif // _ANIMATION_ASSET_H_