SkeletonAsset.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 _SKELETON_ASSET_H_
  23. #define _SKELETON_ASSET_H_
  24. #ifndef _ASSET_PTR_H_
  25. #include "assets/assetPtr.h"
  26. #endif
  27. #ifndef _IMAGE_ASSET_H_
  28. #include "2d/assets/ImageAsset.h"
  29. #endif
  30. #ifndef SPINE_SPINE_H_
  31. #include "spine/spine.h"
  32. #endif
  33. //-----------------------------------------------------------------------------
  34. DefineConsoleType( TypeSkeletonAssetPtr )
  35. //-----------------------------------------------------------------------------
  36. class SkeletonAsset : public AssetBase
  37. {
  38. private:
  39. typedef AssetBase Parent;
  40. bool mAtlasDirty;
  41. public:
  42. StringTableEntry mSkeletonFile;
  43. StringTableEntry mAtlasFile;
  44. AssetPtr<ImageAsset> mImageAsset;
  45. spAtlas* mAtlas;
  46. spSkeletonData* mSkeletonData;
  47. spAnimationStateData* mStateData;
  48. public:
  49. SkeletonAsset();
  50. virtual ~SkeletonAsset();
  51. /// Core.
  52. static void initPersistFields();
  53. virtual bool onAdd();
  54. virtual void onRemove();
  55. virtual void copyTo(SimObject* object);
  56. void setSkeletonFile( const char* pSkeletonFile );
  57. inline StringTableEntry getSkeletonFile( void ) const { return mSkeletonFile; }
  58. void setAtlasFile( const char* pAtlasFile );
  59. inline StringTableEntry getAtlasFile( void ) const { return mAtlasFile; }
  60. virtual bool isAssetValid( void ) const;
  61. /// Declare Console Object.
  62. DECLARE_CONOBJECT(SkeletonAsset);
  63. private:
  64. void buildAtlasData( void );
  65. void buildSkeletonData( void );
  66. protected:
  67. virtual void initializeAsset( void );
  68. virtual void onAssetRefresh( void );
  69. /// Taml callbacks.
  70. virtual void onTamlPreWrite( void );
  71. virtual void onTamlPostWrite( void );
  72. virtual void onTamlCustomWrite( TamlCustomNodes& customNodes );
  73. virtual void onTamlCustomRead( const TamlCustomNodes& customNodes );
  74. protected:
  75. static bool setSkeletonFile( void* obj, const char* data ) { static_cast<SkeletonAsset*>(obj)->setSkeletonFile(data); return false; }
  76. static bool writeSkeletonFile( void* obj, StringTableEntry pFieldName ) { return static_cast<SkeletonAsset*>(obj)->getSkeletonFile() != StringTable->EmptyString; }
  77. static bool setAtlasFile( void* obj, const char* data ) { static_cast<SkeletonAsset*>(obj)->setAtlasFile(data); return false; }
  78. static bool writeAtlasFile( void* obj, StringTableEntry pFieldName ) { return static_cast<SkeletonAsset*>(obj)->getAtlasFile() != StringTable->EmptyString; }
  79. };
  80. #endif // _SKELETON_ASSET_H_