assetQuery_ScriptBinding.h 3.4 KB

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