123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- //-----------------------------------------------------------------------------
- // 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.
- //-----------------------------------------------------------------------------
- ConsoleMethodGroupBeginWithDocs(AnimationAsset, AssetBase)
- /*! Sets the image asset Id.
- @return No return value.
- */
- ConsoleMethodWithDocs(AnimationAsset, setImage, ConsoleVoid, 3, 3, (assetId))
- {
- object->setImage( argv[2] );
- }
- //-----------------------------------------------------------------------------
- /*! Gets the image asset Id.
- @return The image asset Id.
- */
- ConsoleMethodWithDocs(AnimationAsset, getImage, ConsoleString, 2, 2, ())
- {
- return object->getImage().getAssetId();
- }
- //-----------------------------------------------------------------------------
- /*! Sets the image frames that compose the animation.
- @param animationFrames A set of image frames that compose the animation.
- @return No return value.
- */
- ConsoleMethodWithDocs(AnimationAsset, setAnimationFrames, ConsoleVoid, 3, 3, (animationFrames))
- {
- // Are we in named cells mode?
- if ( object->getNamedCellsMode() )
- {
- // Yes, so warn.
- Con::warnf( "AnimationAsset::setAnimationFrames() - Method invalid, in named cells mode." );
- return;
- }
- object->setAnimationFrames( argv[2] );
- }
- //-----------------------------------------------------------------------------
- /*! Gets the frames that compose the animation or optionally only the ones validated against the image asset.
- @param validatedFrames - Whether to return only the validated frames or not. Optional: Default is false.
- @return The image frames that compose the animation or optionally only the ones validated against the image asset.
- */
- ConsoleMethodWithDocs(AnimationAsset, getAnimationFrames, ConsoleString, 2, 3, ([bool validatedFrames]))
- {
- // Are we in named cells mode?
- if ( object->getNamedCellsMode() )
- {
- // Yes, so warn.
- Con::warnf( "AnimationAsset::getAnimationFrames() - Method invalid, in named cells mode." );
- return StringTable->EmptyString;
- }
- // Fetch a return buffer.
- S32 bufferSize = 4096;
- char* pBuffer = Con::getReturnBuffer( bufferSize );
- char* pReturnBuffer = pBuffer;
- // Fetch validated frames flag.
- const bool validatedFrames = argc >= 3 ? dAtob( argv[2] ) : false;
- // Fetch specified frames.
- const Vector<S32>& frames = validatedFrames ? object->getValidatedAnimationFrames() : object->getSpecifiedAnimationFrames();
- // Fetch frame count.
- const U32 frameCount = (U32)frames.size();
- // Format frames.
- for ( U32 frameIndex = 0; frameIndex < frameCount; ++frameIndex )
- {
- const S32 offset = dSprintf( pBuffer, bufferSize, "%d ", frames[frameIndex] );
- pBuffer += offset;
- bufferSize -= offset;
- }
- // Return frames.
- return pReturnBuffer;
- }
- //-----------------------------------------------------------------------------
- /*! Gets the count of frame that compose the animation or optionally only the ones validated against the image asset.
- @param validatedFrames - Whether to return only the validated frames or not. Optional: Default is false.
- @return The image frames that compose the animation or optionally only the ones validated against the image asset.
- */
- ConsoleMethodWithDocs(AnimationAsset, getAnimationFrameCount, ConsoleInt, 2, 3, ([bool validatedFrames]))
- {
- // Are we in named cells mode?
- if ( object->getNamedCellsMode() )
- {
- // Yes, so warn.
- Con::warnf( "AnimationAsset::getAnimationFrameCount() - Method invalid, in named cells mode." );
- return -1;
- }
- // Fetch validated frames flag.
- const bool validatedFrames = argc >= 3 ? dAtob( argv[2] ) : false;
- // Fetch specified frames.
- const Vector<S32>& frames = validatedFrames ? object->getValidatedAnimationFrames() : object->getSpecifiedAnimationFrames();
- return frames.size();
- }
- //-----------------------------------------------------------------------------
- /*! Sets the named image frames that compose the animation.
- @param animationFrames A set of named image frames that compose the animation.
- @return No return value.
- */
- ConsoleMethodWithDocs(AnimationAsset, setNamedAnimationFrames, ConsoleVoid, 3, 3, (animationFrames))
- {
- // Are we in named cells mode?
- if ( !object->getNamedCellsMode() )
- {
- // No, so warn.
- Con::warnf( "AnimationAsset::setNamedAnimationFrames() - Method invalid, not in named cells mode." );
- return;
- }
- object->setNamedAnimationFrames( argv[2] );
- }
- //-----------------------------------------------------------------------------
- /*! Gets the named frames that compose the animation or optionally only the ones validated against the image asset.
- @param validatedFrames - Whether to return only the validated frames or not. Optional: Default is false.
- @return The named image frames that compose the animation or optionally only the ones validated against the image asset.
- */
- ConsoleMethodWithDocs(AnimationAsset, getNamedAnimationFrames, ConsoleString, 2, 3, ([bool validatedFrames]))
- {
- // Are we in named cells mode?
- if ( !object->getNamedCellsMode() )
- {
- // No, so warn.
- Con::warnf( "AnimationAsset::getNamedAnimationFrames() - Method invalid, not in named cells mode." );
- return StringTable->EmptyString;
- }
- // Fetch a return buffer.
- S32 bufferSize = 4096;
- char* pBuffer = Con::getReturnBuffer( bufferSize );
- char* pReturnBuffer = pBuffer;
- // Fetch validated frames flag.
- const bool validatedFrames = argc >= 3 ? dAtob( argv[2] ) : false;
- // Fetch specified frames.
- const Vector<StringTableEntry>& frames = validatedFrames ? object->getValidatedNamedAnimationFrames() : object->getSpecifiedNamedAnimationFrames();
- // Fetch frame count.
- const U32 frameCount = (U32)frames.size();
- // Format frames.
- for ( U32 frameIndex = 0; frameIndex < frameCount; ++frameIndex )
- {
- const S32 offset = dSprintf( pBuffer, bufferSize, "%d ", frames[frameIndex] );
- pBuffer += offset;
- bufferSize -= offset;
- }
- // Return frames.
- return pReturnBuffer;
- }
- //-----------------------------------------------------------------------------
- /*! Gets the count of named frames that compose the animation or optionally only the ones validated against the image asset.
- @param validatedFrames - Whether to return only the validated frames or not. Optional: Default is false.
- @return The named image frames that compose the animation or optionally only the ones validated against the image asset.
- */
- ConsoleMethodWithDocs(AnimationAsset, getNamedAnimationFrameCount, ConsoleInt, 2, 3, ([bool validatedFrames]))
- {
- // Are we in named cells mode?
- if ( !object->getNamedCellsMode() )
- {
- // No, so warn.
- Con::warnf( "AnimationAsset::getNamedAnimationFrameCount() - Method invalid, not in named cells mode." );
- return -1;
- }
- // Fetch validated frames flag.
- const bool validatedFrames = argc >= 3 ? dAtob( argv[2] ) : false;
- // Fetch specified frames.
- const Vector<StringTableEntry>& frames = validatedFrames ? object->getValidatedNamedAnimationFrames() : object->getSpecifiedNamedAnimationFrames();
- return frames.size();
- }
- //-----------------------------------------------------------------------------
- /*! Sets the total time to cycle through all animation frames.
- @param animationTime The total time to cycle through all animation frames.
- @return No return value.
- */
- ConsoleMethodWithDocs(AnimationAsset, setAnimationTime, ConsoleVoid, 3, 3, (float animationTime))
- {
- object->setAnimationTime( dAtof(argv[2] ) );
- }
- //-----------------------------------------------------------------------------
- /*! Gets the total time to cycle through all animation frames.
- @return The total time to cycle through all animation frames.
- */
- ConsoleMethodWithDocs(AnimationAsset, getAnimationTime, ConsoleFloat, 2, 2, ())
- {
- return object->getAnimationTime();
- }
- //-----------------------------------------------------------------------------
- /*! Sets whether the animation cycles or not.
- @param animationCycle Whether the animation cycles or not.
- @return No return value.
- */
- ConsoleMethodWithDocs(AnimationAsset, setAnimationCycle, ConsoleVoid, 3, 3, (bool animationCycle))
- {
- object->setAnimationCycle( dAtob(argv[2] ) );
- }
- //-----------------------------------------------------------------------------
- /*! Gets whether the animation cycles or not.
- @return Whether the animation cycles or not.
- */
- ConsoleMethodWithDocs(AnimationAsset, getAnimationCycle, ConsoleBool, 2, 2, ())
- {
- return object->getAnimationCycle();
- }
- //-----------------------------------------------------------------------------
- /*! Sets whether the animation uses names for cells, instead of numerical index.
- @param namedCellsMode True if it should be using named cells.
- @return No return value.
- */
- ConsoleMethodWithDocs(AnimationAsset, setNamedCellsMode, ConsoleVoid, 3, 3, ())
- {
- object->setNamedCellsMode( dAtob(argv[2] ) );
- }
- //-----------------------------------------------------------------------------
- /*! Gets whether the animation is using names for its cells.
- @return True if the animation is using named cells.
- */
- ConsoleMethodWithDocs(AnimationAsset, getNamedCellsMode, ConsoleBool, 2, 2, ())
- {
- return object->getNamedCellsMode();
- }
- ConsoleMethodGroupEndWithDocs(AnimationAsset)
|