1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00
This commit is contained in:
Laserlicht 2024-08-21 23:01:32 +02:00
parent 02002ce69d
commit c2290f5f6e
5 changed files with 11 additions and 17 deletions

View File

@ -28,12 +28,15 @@ void AssetGenerator::createAdventureOptionsCleanBackground()
{
std::string filename = "data/ADVOPTBC.bmp";
if(CResourceHandler::get()->existsResource(ResourcePath(filename))) // overridden by mod, no generation
return;
if(!CResourceHandler::get("local")->createResource(filename))
return;
ResourcePath savePath(filename, EResType::IMAGE);
auto res = ImagePath::builtin("ADVOPTBK");
res.setOriginalResource(true);
res = res.setOriginalResource(true);
std::shared_ptr<IImage> img = GH.renderHandler().loadImage(res, EImageBlitMode::OPAQUE);
@ -49,20 +52,21 @@ void AssetGenerator::createAdventureOptionsCleanBackground()
std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
CResourceHandler::get("local")->removeResource(savePath); // remove resource -> may overridden by mod later
}
void AssetGenerator::createBigSpellBook()
{
std::string filename = "data/SpelBk2.bmp";
if(CResourceHandler::get()->existsResource(ResourcePath(filename))) // overridden by mod, no generation
return;
if(!CResourceHandler::get("local")->createResource(filename))
return;
ResourcePath savePath(filename, EResType::IMAGE);
auto res = ImagePath::builtin("SpelBack");
res.setOriginalResource(true);
res = res.setOriginalResource(true);
std::shared_ptr<IImage> img = GH.renderHandler().loadImage(res, EImageBlitMode::OPAQUE);
Canvas canvas = Canvas(Point(800, 600), CanvasScalingPolicy::IGNORE);
@ -111,6 +115,4 @@ void AssetGenerator::createBigSpellBook()
std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
CResourceHandler::get("local")->removeResource(savePath); // remove resource -> may overridden by mod later
}

View File

@ -108,11 +108,6 @@ bool CFilesystemLoader::createResource(const std::string & requestedFilename, bo
return true;
}
void CFilesystemLoader::removeResource(const ResourcePath & resourceName)
{
fileList.erase(resourceName);
}
std::unordered_map<ResourcePath, boost::filesystem::path> CFilesystemLoader::listFiles(const std::string &mountPoint, size_t depth, bool initial) const
{
static const EResType initArray[] = {

View File

@ -38,7 +38,6 @@ public:
bool existsResource(const ResourcePath & resourceName) const override;
std::string getMountPoint() const override;
bool createResource(const std::string & filename, bool update = false) override;
void removeResource(const ResourcePath & resourceName) override;
std::optional<boost::filesystem::path> getResourceName(const ResourcePath & resourceName) const override;
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override;
std::unordered_set<ResourcePath> getFilteredFiles(std::function<bool(const ResourcePath &)> filter) const override;

View File

@ -182,6 +182,9 @@ void CResourceHandler::initialize()
knownLoaders["root"] = globalResourceHandler.rootLoader.get();
knownLoaders["saves"] = new CFilesystemLoader("SAVES/", VCMIDirs::get().userSavePath());
knownLoaders["config"] = new CFilesystemLoader("CONFIG/", VCMIDirs::get().userConfigPath());
if(boost::filesystem::is_directory(VCMIDirs::get().userDataPath() / "Generated"))
boost::filesystem::remove_all(VCMIDirs::get().userDataPath() / "Generated");
knownLoaders["gen_data"] = new CFilesystemLoader("DATA/", VCMIDirs::get().userDataPath() / "Generated" / "Data");
knownLoaders["gen_sprites"] = new CFilesystemLoader("SPRITES/", VCMIDirs::get().userDataPath() / "Generated" / "Sprites");

View File

@ -95,11 +95,6 @@ public:
return false;
}
/**
* Remove resources from cached list.
*/
virtual void removeResource(const ResourcePath & resourceName) { };
/**
* @brief Returns all loaders that have resource with such name
*