diff --git a/src/scene/assetmanager.cpp b/src/scene/assetmanager.cpp index 1a9c0ec6a7..755be4a9d9 100644 --- a/src/scene/assetmanager.cpp +++ b/src/scene/assetmanager.cpp @@ -555,29 +555,78 @@ void AssetManager::setUpAssetLuaTable(Asset* asset) { ); lua_setfield(*_luaState, assetTableIndex, "resource"); + // @DEPRECATED(abock) This should be removed after 0.20.0 + ghoul::lua::push(*_luaState, this, asset); lua_pushcclosure( *_luaState, [](lua_State* L) { - return ghoul::lua::luaError( - L, + LWARNING( "'asset.localResource' has been deprecrated and should be replaced with " "'asset.resource' instead. No change to the parameters are needed" ); + + AssetManager* manager = ghoul::lua::userData(L, 1); + Asset* thisAsset = ghoul::lua::userData(L, 2); + ghoul::lua::checkArgumentsAndThrow(L, { 0, 1 }, "lua::resource"); + + auto [name] = ghoul::lua::values>(L); + std::filesystem::path path = + name.has_value() ? + thisAsset->path().parent_path() / *name : + thisAsset->path().parent_path(); + ghoul::lua::push(L, path); + + return 1; }, - 0 + 2 ); lua_setfield(*_luaState, assetTableIndex, "localResource"); + // @DEPRECATED(abock) This should be removed after 0.20.0 + ghoul::lua::push(*_luaState, this, asset); lua_pushcclosure( *_luaState, [](lua_State* L) { - return ghoul::lua::luaError( - L, + LWARNING( "'asset.syncedResource' has been deprecrated and should be replaced with " "'asset.resource' instead. No change to the parameters are needed" ); + + AssetManager* manager = ghoul::lua::userData(L, 1); + Asset* thisAsset = ghoul::lua::userData(L, 2); + ghoul::lua::checkArgumentsAndThrow(L, { 0, 1 }, "lua::resource"); + + ghoul::Dictionary d = ghoul::lua::value(L); + std::unique_ptr s = + ResourceSynchronization::createFromDictionary(d); + + std::string uid = d.value("Type") + "/" + s->generateUid(); + SyncItem* syncItem = nullptr; + auto it = manager->_synchronizations.find(uid); + if (it == manager->_synchronizations.end()) { + auto si = std::make_unique(); + si->synchronization = std::move(s); + si->assets.push_back(thisAsset); + syncItem = si.get(); + manager->_synchronizations[uid] = std::move(si); + } + else { + syncItem = it->second.get(); + syncItem->assets.push_back(thisAsset); + } + + if (!syncItem->synchronization->isResolved()) { + manager->_unfinishedSynchronizations.push_back(syncItem); + } + + thisAsset->addSynchronization(syncItem->synchronization.get()); + std::filesystem::path path = syncItem->synchronization->directory(); + path += std::filesystem::path::preferred_separator; + ghoul::lua::push(L, path); + + return 1; }, - 0 + 2 ); lua_setfield(*_luaState, assetTableIndex, "syncedResource");