AnimationAsset.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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<S32> mValidatedFrames;
  39. F32 mAnimationTime;
  40. bool mAnimationCycle;
  41. bool mRandomStart;
  42. F32 mAnimationIntegration;
  43. public:
  44. AnimationAsset();
  45. virtual ~AnimationAsset();
  46. static void initPersistFields();
  47. virtual bool onAdd();
  48. virtual void onRemove();
  49. virtual void copyTo(SimObject* object);
  50. void setImage( const char* pAssetId );
  51. inline const AssetPtr<ImageAsset>& getImage( void ) const { return mImageAsset; }
  52. void setAnimationFrames( const char* pAnimationFrames );
  53. inline const Vector<S32>& getSpecifiedAnimationFrames( void ) const { return mAnimationFrames; }
  54. inline const Vector<S32>& getValidatedAnimationFrames( void ) const { return mValidatedFrames; }
  55. void setAnimationTime( const F32 animationTime );
  56. inline F32 getAnimationTime( void ) const { return mAnimationTime; }
  57. void setAnimationCycle( const bool animationCycle );
  58. inline bool getAnimationCycle( void ) const { return mAnimationCycle; }
  59. void setRandomStart( const bool randomStart );
  60. inline bool getRandomStart( void ) const { return mRandomStart; }
  61. // Frame validation.
  62. void validateFrames( void );
  63. // Asset validation.
  64. virtual bool isAssetValid( void ) const;
  65. /// Declare Console Object.
  66. DECLARE_CONOBJECT(AnimationAsset);
  67. protected:
  68. virtual void initializeAsset( void );
  69. virtual void onAssetRefresh( void );
  70. protected:
  71. static bool setImage( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setImage( data ); return false; }
  72. static bool writeImage( void* obj, StringTableEntry pFieldName ) { return static_cast<AnimationAsset*>(obj)->mImageAsset.notNull(); }
  73. static bool setAnimationFrames( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setAnimationFrames( data ); return false; }
  74. static bool writeAnimationFrames( void* obj, StringTableEntry pFieldName ) { return static_cast<AnimationAsset*>(obj)->mAnimationFrames.size() > 0; }
  75. static bool setAnimationTime( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setAnimationTime( dAtof(data) ); return false; }
  76. static bool setAnimationCycle( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setAnimationCycle( dAtob(data) ); return false; }
  77. static bool writeAnimationCycle( void* obj, StringTableEntry pFieldName ) { return static_cast<AnimationAsset*>(obj)->getAnimationCycle() == false; }
  78. static bool setRandomStart( void* obj, const char* data ) { static_cast<AnimationAsset*>(obj)->setRandomStart( dAtob(data) ); return false; }
  79. static bool writeRandomStart( void* obj, StringTableEntry pFieldName ) { return static_cast<AnimationAsset*>(obj)->getRandomStart() == true; }
  80. };
  81. #endif // _ANIMATION_ASSET_H_