assetQuery.cpp
Engine/source/assets/assetQuery.cpp
Public Functions
Detailed Description
Public Functions
IMPLEMENT_CONOBJECT(AssetQuery )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2013 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _ASSET_QUERY_H_ 25#include "assetQuery.h" 26#endif 27 28#ifndef _CONSOLETYPES_H_ 29#include "console/consoleTypes.h" 30#endif 31 32#ifndef _TAML_CUSTOM_H_ 33#include "persistence/taml/tamlCustom.h" 34#endif 35 36// Script bindings. 37#include "assetQuery_ScriptBinding.h" 38 39//----------------------------------------------------------------------------- 40 41IMPLEMENT_CONOBJECT( AssetQuery ); 42 43//----------------------------------------------------------------------------- 44 45void AssetQuery::initPersistFields() 46{ 47 // Call parent. 48 Parent::initPersistFields(); 49 50 addProtectedField("Count", TypeS32, 0, &defaultProtectedSetFn, &getCount, &writeCount, "Gets the number of results in the asset query."); 51} 52 53//----------------------------------------------------------------------------- 54 55void AssetQuery::onTamlCustomWrite( TamlCustomNodes& customNodes ) 56{ 57 // Call parent. 58 Parent::onTamlCustomWrite( customNodes ); 59 60 // Add node. 61 TamlCustomNode* pCustomNode = customNodes.addNode( ASSETQUERY_RESULTS_NODE_NAME ); 62 63 // Finish if no assets. 64 if (mAssetList.size() == 0) 65 return; 66 67 // Iterate asset. 68 for (Vector<StringTableEntry>::iterator assetItr = mAssetList.begin(); assetItr != mAssetList.end(); ++assetItr) 69 { 70 // Add asset node. 71 TamlCustomNode* pAssetNode = pCustomNode->addNode( ASSETQUERY_ASSETNODE_NAME ); 72 73 // Add field. 74 pAssetNode->addField( ASSETQUERY_ASSETID_FIELD_NAME, *assetItr ); 75 } 76} 77 78//----------------------------------------------------------------------------- 79 80void AssetQuery::onTamlCustomRead( const TamlCustomNodes& customNodes ) 81{ 82 // Call parent. 83 Parent::onTamlCustomRead( customNodes ); 84 85 // Find custom node name. 86 const TamlCustomNode* pResultsNode = customNodes.findNode( ASSETQUERY_RESULTS_NODE_NAME ); 87 88 // Finish if we don't have a results name. 89 if ( pResultsNode == NULL ) 90 return; 91 92 // Fetch node name. 93 StringTableEntry assetNodeName = StringTable->insert( ASSETQUERY_ASSETNODE_NAME ); 94 95 // Fetch children asset nodes. 96 const TamlCustomNodeVector& assetNodes = pResultsNode->getChildren(); 97 98 // Iterate asset nodes. 99 for( TamlCustomNodeVector::const_iterator assetNodeItr = assetNodes.begin(); assetNodeItr != assetNodes.end(); ++assetNodeItr ) 100 { 101 // Fetch asset node. 102 const TamlCustomNode* pAssetNode = *assetNodeItr; 103 104 // Skip if an unknown node name. 105 if ( pAssetNode->getNodeName() != assetNodeName ) 106 continue; 107 108 // Fetch field. 109 const TamlCustomField* pField = pAssetNode->findField( ASSETQUERY_ASSETID_FIELD_NAME ); 110 111 // Do we find the field? 112 if ( pField == NULL ) 113 { 114 // No, so warn. 115 Con::warnf( "AssetQuery::onTamlCustomRead() - Could not find '%s' field.", ASSETQUERY_ASSETID_FIELD_NAME ); 116 continue; 117 } 118 119 // Store asset. 120 mAssetList.push_back(pField->getFieldValue()); 121 } 122} 123