| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- //
- // Copyright (c) 2008-2020 the Urho3D project.
- //
- // 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.
- //
- #include "../Precompiled.h"
- #include "../AngelScript/APITemplates.h"
- #include "../AngelScript/Manual_Resource.h"
- #include "../Resource/ResourceCache.h"
- #include "../Resource/Localization.h"
- namespace Urho3D
- {
- // This function is called before ASRegisterGenerated()
- void ASRegisterManualFirst_Resource(asIScriptEngine* engine)
- {
- }
- // ========================================================================================
- // template<class T> T * Object::GetSubsystem() const | File: ../Core/Object.h
- static ResourceCache* GetResourceCache()
- {
- return GetScriptContext()->GetSubsystem<ResourceCache>();
- }
- // template<class T> T * Object::GetSubsystem() const | File: ../Core/Object.h
- static Localization* GetLocalization()
- {
- return GetScriptContext()->GetSubsystem<Localization>();
- }
- // This function is called after ASRegisterGenerated()
- void ASRegisterManualLast_Resource(asIScriptEngine* engine)
- {
- // template<class T> T * Object::GetSubsystem() const | File: ../Core/Object.h
- engine->RegisterGlobalFunction("Localization@+ get_localization()", asFUNCTION(GetLocalization), asCALL_CDECL);
- // template<class T> T * Object::GetSubsystem() const | File: ../Core/Object.h
- engine->RegisterGlobalFunction("ResourceCache@+ get_resourceCache()", asFUNCTION(GetResourceCache), asCALL_CDECL);
- // template<class T> T * Object::GetSubsystem() const | File: ../Core/Object.h
- engine->RegisterGlobalFunction("ResourceCache@+ get_cache()", asFUNCTION(GetResourceCache), asCALL_CDECL);
- }
- // ========================================================================================
- // bool Resource::Load(Deserializer &source) | File: ../Resource/Resource.h
- bool ResourceLoad(File* file, Resource* ptr)
- {
- return file && ptr->Load(*file);
- }
- // bool Resource::Load(Deserializer &source) | File: ../Resource/Resource.h
- bool ResourceLoadVectorBuffer(VectorBuffer& buffer, Resource* ptr)
- {
- return ptr->Load(buffer);
- }
- // virtual bool Resource::Save(Serializer &dest) const | File: ../Resource/Resource.h
- bool ResourceSave(File* file, Resource* ptr)
- {
- return file && ptr->Save(*file);
- }
- // virtual bool Resource::Save(Serializer &dest) const | File: ../Resource/Resource.h
- bool ResourceSaveVectorBuffer(VectorBuffer& buffer, Resource* ptr)
- {
- return ptr->Save(buffer);
- }
- // ========================================================================================
- // XMLElement XMLFile::GetRoot(const String &name=String::EMPTY) | File: ../Resource/XMLFile.h
- XMLElement XMLFileGetRootDefault(XMLFile* ptr)
- {
- return ptr->GetRoot();
- }
- // ========================================================================================
- void ArrayToVariantVector(CScriptArray* arr, VariantVector& dest);
- // bool XMLElement::SetVariantVector(const VariantVector &value) | File: ../Resource/XMLElement.h
- bool XMLElementSetVariantVector(CScriptArray* value, XMLElement* ptr)
- {
- VariantVector src;
- ArrayToVariantVector(value, src);
- return ptr->SetVariantVector(src);
- }
- // VariantVector XMLElement::GetVariantVector() const | File: ../Resource/XMLElement.h
- CScriptArray* XMLElementGetVariantVector(XMLElement* ptr)
- {
- return VectorToArray<Variant>(ptr->GetVariantVector(), "Array<Variant>");
- }
- // ========================================================================================
- // void ResourceCache::GetResources(PODVector< Resource * > &result, StringHash type) const | File: ../Resource/ResourceCache.h
- CScriptArray* ResourceCacheGetResources(StringHash type, ResourceCache* ptr)
- {
- PODVector<Resource*> resources;
- ptr->GetResources(resources, type);
- return VectorToHandleArray(resources, "Array<Resource@>");
- }
- // ========================================================================================
- // void JSONValue::SetVariant(const Variant &variant, Context *context=nullptr) | File: ../Resource/JSONValue.h
- void JSONValueSetVariant(const Variant& variant, JSONValue& jsonValue)
- {
- jsonValue.SetVariant(variant, GetScriptContext());
- }
- // void JSONValue::SetVariantMap(const VariantMap &variantMap, Context *context=nullptr) | File: ../Resource/JSONValue.h
- void JSONValueSetVariantMap(const VariantMap& variantMap, JSONValue& jsonValue)
- {
- jsonValue.SetVariantMap(variantMap, GetScriptContext());
- }
- CScriptArray* JSONValueGetKeys(const JSONValue& jsonValue)
- {
- Vector<String> keys;
- if (jsonValue.IsObject())
- {
- for (ConstJSONObjectIterator i = jsonValue.Begin(); i != jsonValue.End(); ++i)
- keys.Push(i->first_);
- }
- return VectorToArray<String>(keys, "Array<String>");
- }
- CScriptArray* JSONValueGetValues(const JSONValue& jsonValue)
- {
- if (jsonValue.IsArray())
- return VectorToArray<JSONValue>(jsonValue.GetArray(), "Array<JSONValue>");
- else
- {
- Vector<JSONValue> values;
- if (jsonValue.IsObject())
- {
- for (ConstJSONObjectIterator i = jsonValue.Begin(); i != jsonValue.End(); ++i)
- values.Push(i->second_);
- }
- return VectorToArray<JSONValue>(values, "Array<JSONValue>");
- }
- }
- }
|