assetQuery_ScriptBinding.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. ConsoleMethodGroupBeginWithDocs(AssetQuery, SimObject)
  23. /*! Clears all asset Id results.
  24. @return () No return value.
  25. */
  26. ConsoleMethodWithDocs(AssetQuery, clear, ConsoleVoid, 2, 2, ())
  27. {
  28. object->clear();
  29. }
  30. //-----------------------------------------------------------------------------
  31. /*! Sets the asset query to a copy of the specified asset query.
  32. @param assetQuery The asset query to copy.
  33. @return Whether the operation succeeded or not.
  34. */
  35. ConsoleMethodWithDocs(AssetQuery, set, ConsoleBool, 3, 3, (assetQuery))
  36. {
  37. // Find asset query.
  38. AssetQuery* pAssetQuery = Sim::findObject<AssetQuery>( argv[2] );
  39. // Did we find the asset query?
  40. if ( pAssetQuery == NULL )
  41. {
  42. // No, so warn.
  43. Con::warnf( "AssetQuery::set() - Could not find asset query '%s'.", argv[2] );
  44. return false;
  45. }
  46. // Set asset query.
  47. object->set( *pAssetQuery );
  48. return true;
  49. }
  50. //-----------------------------------------------------------------------------
  51. /*! Gets the count of asset Id results.
  52. @return (int) The count of asset Id results.
  53. */
  54. ConsoleMethodWithDocs(AssetQuery, getCount, ConsoleInt, 2, 2, ())
  55. {
  56. return object->size();
  57. }
  58. //-----------------------------------------------------------------------------
  59. /*! Gets the asset Id at the specified query result index.
  60. @param resultIndex The query result index to use.
  61. @return (assetId) The asset Id at the specified index or NULL if not valid.
  62. */
  63. ConsoleMethodWithDocs(AssetQuery, getAsset, ConsoleString, 3, 3, (int resultIndex))
  64. {
  65. // Fetch result index.
  66. const S32 resultIndex = dAtoi(argv[2]);
  67. // Is index within bounds?
  68. if ( resultIndex >= object->size() )
  69. {
  70. // No, so warn.
  71. Con::warnf( "AssetQuery::getAsset() - Result index '%s' is out of bounds.", argv[2] );
  72. return StringTable->EmptyString;
  73. }
  74. return object->at(resultIndex);
  75. }
  76. ConsoleMethodGroupEndWithDocs(AssetQuery)