//----------------------------------------------------------------------------- // Copyright (c) 2013 GarageGames, LLC // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. //----------------------------------------------------------------------------- #ifndef _ANIMATION_ASSET_H_ #define _ANIMATION_ASSET_H_ #ifndef _ASSET_PTR_H_ #include "assets/assetPtr.h" #endif //----------------------------------------------------------------------------- DefineConsoleType( TypeAnimationAssetPtr ) //----------------------------------------------------------------------------- class ImageAsset; //----------------------------------------------------------------------------- class AnimationAsset : public AssetBase { private: typedef AssetBase Parent; AssetPtr mImageAsset; Vector mAnimationFrames; Vector mNamedAnimationFrames; Vector mValidatedFrames; Vector mValidatedNameFrames; F32 mAnimationTime; bool mAnimationCycle; bool mRandomStart; F32 mAnimationIntegration; bool mNamedCellsMode; public: AnimationAsset(); virtual ~AnimationAsset(); static void initPersistFields(); virtual bool onAdd(); virtual void onRemove(); virtual void copyTo(SimObject* object); void setImage( const char* pAssetId ); inline const AssetPtr& getImage( void ) const { return mImageAsset; } void setAnimationFrames( const char* pAnimationFrames ); inline const Vector& getSpecifiedAnimationFrames( void ) const { return mAnimationFrames; } inline const Vector& getValidatedAnimationFrames( void ) const { return mValidatedFrames; } void setNamedAnimationFrames( const char* pAnimationFrames ); inline const Vector& getSpecifiedNamedAnimationFrames( void ) const { return mNamedAnimationFrames; } inline const Vector& getValidatedNamedAnimationFrames( void ) const { return mValidatedNameFrames; } void setAnimationTime( const F32 animationTime ); inline F32 getAnimationTime( void ) const { return mAnimationTime; } void setAnimationCycle( const bool animationCycle ); inline bool getAnimationCycle( void ) const { return mAnimationCycle; } void setRandomStart( const bool randomStart ); inline bool getRandomStart( void ) const { return mRandomStart; } void setNamedCellsMode( const bool namedCellsMode ); inline bool getNamedCellsMode( void ) const { return mNamedCellsMode; } // Frame validation. void validateFrames( void ); void validateNumericalFrames( void ); void validateNamedFrames( void ); // Asset validation. virtual bool isAssetValid( void ) const; /// Declare Console Object. DECLARE_CONOBJECT(AnimationAsset); protected: virtual void initializeAsset( void ); virtual void onAssetRefresh( void ); protected: static bool setImage( void* obj, const char* data ) { static_cast(obj)->setImage( data ); return false; } static bool writeImage( void* obj, StringTableEntry pFieldName ) { return static_cast(obj)->mImageAsset.notNull(); } static bool setAnimationFrames( void* obj, const char* data ) { static_cast(obj)->setAnimationFrames( data ); return false; } static bool writeAnimationFrames( void* obj, StringTableEntry pFieldName ) { return static_cast(obj)->mAnimationFrames.size() > 0; } static bool setNamedAnimationFrames( void* obj, const char* data ) { static_cast(obj)->setNamedAnimationFrames( data ); return false; } static bool writeNamedAnimationFrames( void* obj, StringTableEntry pFieldName ) { return static_cast(obj)->mNamedAnimationFrames.size() > 0; } static bool setAnimationTime( void* obj, const char* data ) { static_cast(obj)->setAnimationTime( dAtof(data) ); return false; } static bool setAnimationCycle( void* obj, const char* data ) { static_cast(obj)->setAnimationCycle( dAtob(data) ); return false; } static bool writeAnimationCycle( void* obj, StringTableEntry pFieldName ) { return static_cast(obj)->getAnimationCycle() == false; } static bool setRandomStart( void* obj, const char* data ) { static_cast(obj)->setRandomStart( dAtob(data) ); return false; } static bool writeRandomStart( void* obj, StringTableEntry pFieldName ) { return static_cast(obj)->getRandomStart() == true; } static bool setNamedCellsMode( void* obj, const char* data ) { static_cast(obj)->setNamedCellsMode( dAtob(data) ); return false; } static bool writeNamedCellsMode( void* obj, StringTableEntry pFieldName ) { return static_cast(obj)->getNamedCellsMode() == true; } }; #endif // _ANIMATION_ASSET_H_