Provide a warning instead of erroring out with the localResource/syncedResource -> resource change

This commit is contained in:
Alexander Bock
2024-01-12 10:10:49 +01:00
parent cae9834ec7
commit 04a06520e5
+55 -6
View File
@@ -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<AssetManager>(L, 1);
Asset* thisAsset = ghoul::lua::userData<Asset>(L, 2);
ghoul::lua::checkArgumentsAndThrow(L, { 0, 1 }, "lua::resource");
auto [name] = ghoul::lua::values<std::optional<std::string>>(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<AssetManager>(L, 1);
Asset* thisAsset = ghoul::lua::userData<Asset>(L, 2);
ghoul::lua::checkArgumentsAndThrow(L, { 0, 1 }, "lua::resource");
ghoul::Dictionary d = ghoul::lua::value<ghoul::Dictionary>(L);
std::unique_ptr<ResourceSynchronization> s =
ResourceSynchronization::createFromDictionary(d);
std::string uid = d.value<std::string>("Type") + "/" + s->generateUid();
SyncItem* syncItem = nullptr;
auto it = manager->_synchronizations.find(uid);
if (it == manager->_synchronizations.end()) {
auto si = std::make_unique<SyncItem>();
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");