Files
GDevelop/Core/GDCore/IDE/Project/ProjectResourcesAdder.cpp
Florian Rival 763d8e8175 Fix renaming resources breaking objects or events using it
* Also fix the Bitmap Font field not shown in the parameters of the action to change it.
2021-09-24 00:09:32 +01:00

49 lines
1.6 KiB
C++

/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "ProjectResourcesAdder.h"
#include "GDCore/CommonTools.h"
#include "GDCore/IDE/Project/ResourcesInUseHelper.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Tools/Localization.h"
#include "GDCore/Tools/Log.h"
using namespace std;
namespace gd {
std::vector<gd::String> ProjectResourcesAdder::GetAllUseless(
gd::Project& project, const gd::String& resourceType) {
std::vector<gd::String> unusedResources;
// Search for resources used in the project
gd::ResourcesInUseHelper resourcesInUse;
project.ExposeResources(resourcesInUse);
std::set<gd::String>& usedResources = resourcesInUse.GetAll(resourceType);
// Search all resources not used
const std::vector<std::shared_ptr<Resource>>& resources =
project.GetResourcesManager().GetAllResources();
for (std::size_t i = 0; i < resources.size(); i++) {
if (resources[i]->GetKind() != resourceType) continue;
if (usedResources.find(resources[i]->GetName()) == usedResources.end())
unusedResources.push_back(resources[i]->GetName());
}
return unusedResources;
}
void ProjectResourcesAdder::RemoveAllUseless(gd::Project& project,
const gd::String& resourceType) {
std::vector<gd::String> unusedResources =
GetAllUseless(project, resourceType);
for (std::size_t i = 0; i < unusedResources.size(); ++i) {
project.GetResourcesManager().RemoveResource(unusedResources[i]);
}
}
} // namespace gd