Manual_Resource.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Precompiled.h"
  23. #include "../AngelScript/APITemplates.h"
  24. #include "../AngelScript/Manual_Resource.h"
  25. #include "../Resource/ResourceCache.h"
  26. #include "../Resource/Localization.h"
  27. namespace Urho3D
  28. {
  29. // This function is called before ASRegisterGenerated()
  30. void ASRegisterManualFirst_Resource(asIScriptEngine* engine)
  31. {
  32. }
  33. // ========================================================================================
  34. // template<class T> T * Object::GetSubsystem() const | File: ../Core/Object.h
  35. static ResourceCache* GetResourceCache()
  36. {
  37. return GetScriptContext()->GetSubsystem<ResourceCache>();
  38. }
  39. // template<class T> T * Object::GetSubsystem() const | File: ../Core/Object.h
  40. static Localization* GetLocalization()
  41. {
  42. return GetScriptContext()->GetSubsystem<Localization>();
  43. }
  44. // This function is called after ASRegisterGenerated()
  45. void ASRegisterManualLast_Resource(asIScriptEngine* engine)
  46. {
  47. // template<class T> T * Object::GetSubsystem() const | File: ../Core/Object.h
  48. engine->RegisterGlobalFunction("Localization@+ get_localization()", asFUNCTION(GetLocalization), asCALL_CDECL);
  49. // template<class T> T * Object::GetSubsystem() const | File: ../Core/Object.h
  50. engine->RegisterGlobalFunction("ResourceCache@+ get_resourceCache()", asFUNCTION(GetResourceCache), asCALL_CDECL);
  51. // template<class T> T * Object::GetSubsystem() const | File: ../Core/Object.h
  52. engine->RegisterGlobalFunction("ResourceCache@+ get_cache()", asFUNCTION(GetResourceCache), asCALL_CDECL);
  53. }
  54. // ========================================================================================
  55. // bool Resource::Load(Deserializer &source) | File: ../Resource/Resource.h
  56. bool ResourceLoad(File* file, Resource* ptr)
  57. {
  58. return file && ptr->Load(*file);
  59. }
  60. // bool Resource::Load(Deserializer &source) | File: ../Resource/Resource.h
  61. bool ResourceLoadVectorBuffer(VectorBuffer& buffer, Resource* ptr)
  62. {
  63. return ptr->Load(buffer);
  64. }
  65. // virtual bool Resource::Save(Serializer &dest) const | File: ../Resource/Resource.h
  66. bool ResourceSave(File* file, Resource* ptr)
  67. {
  68. return file && ptr->Save(*file);
  69. }
  70. // virtual bool Resource::Save(Serializer &dest) const | File: ../Resource/Resource.h
  71. bool ResourceSaveVectorBuffer(VectorBuffer& buffer, Resource* ptr)
  72. {
  73. return ptr->Save(buffer);
  74. }
  75. // ========================================================================================
  76. // bool XPathQuery::SetQuery(const String &queryString, const String &variableString=String::EMPTY, bool bind=true) | File: ../Resource/XMLElement.h
  77. bool XPathQuery_SetQuery(const String& queryString, XPathQuery* ptr)
  78. {
  79. return ptr->SetQuery(queryString);
  80. }
  81. // ========================================================================================
  82. // XMLElement XMLFile::GetRoot(const String &name=String::EMPTY) | File: ../Resource/XMLFile.h
  83. XMLElement XMLFileGetRootDefault(XMLFile* ptr)
  84. {
  85. return ptr->GetRoot();
  86. }
  87. // ========================================================================================
  88. void ArrayToVariantVector(CScriptArray* arr, VariantVector& dest);
  89. // XMLElement XMLElement::SelectSingle(const String &query, pugi::xpath_variable_set *variables=nullptr) const | File: ../Resource/XMLElement.h
  90. XMLElement XMLElement_SelectSingle(const String& query, XMLElement* ptr)
  91. {
  92. return ptr->SelectSingle(query);
  93. }
  94. // XPathResultSet XMLElement::Select(const String &query, pugi::xpath_variable_set *variables=nullptr) const | File: ../Resource/XMLElement.h
  95. XPathResultSet XMLElement_Select(const String& query, XMLElement* ptr)
  96. {
  97. return ptr->Select(query);
  98. }
  99. // bool XMLElement::SetVariantVector(const VariantVector &value) | File: ../Resource/XMLElement.h
  100. bool XMLElementSetVariantVector(CScriptArray* value, XMLElement* ptr)
  101. {
  102. VariantVector src;
  103. ArrayToVariantVector(value, src);
  104. return ptr->SetVariantVector(src);
  105. }
  106. // VariantVector XMLElement::GetVariantVector() const | File: ../Resource/XMLElement.h
  107. CScriptArray* XMLElementGetVariantVector(XMLElement* ptr)
  108. {
  109. return VectorToArray<Variant>(ptr->GetVariantVector(), "Array<Variant>");
  110. }
  111. // ========================================================================================
  112. // void ResourceCache::GetResources(PODVector< Resource * > &result, StringHash type) const | File: ../Resource/ResourceCache.h
  113. CScriptArray* ResourceCacheGetResources(StringHash type, ResourceCache* ptr)
  114. {
  115. PODVector<Resource*> resources;
  116. ptr->GetResources(resources, type);
  117. return VectorToHandleArray(resources, "Array<Resource@>");
  118. }
  119. // ========================================================================================
  120. CScriptArray* JSONValueGetKeys(const JSONValue& jsonValue)
  121. {
  122. Vector<String> keys;
  123. if (jsonValue.IsObject())
  124. {
  125. for (ConstJSONObjectIterator i = jsonValue.Begin(); i != jsonValue.End(); ++i)
  126. keys.Push(i->first_);
  127. }
  128. return VectorToArray<String>(keys, "Array<String>");
  129. }
  130. CScriptArray* JSONValueGetValues(const JSONValue& jsonValue)
  131. {
  132. if (jsonValue.IsArray())
  133. return VectorToArray<JSONValue>(jsonValue.GetArray(), "Array<JSONValue>");
  134. else
  135. {
  136. Vector<JSONValue> values;
  137. if (jsonValue.IsObject())
  138. {
  139. for (ConstJSONObjectIterator i = jsonValue.Begin(); i != jsonValue.End(); ++i)
  140. values.Push(i->second_);
  141. }
  142. return VectorToArray<JSONValue>(values, "Array<JSONValue>");
  143. }
  144. }
  145. }