diff --git a/client/render/AssetGenerator.cpp b/client/render/AssetGenerator.cpp index 4e88a106d..5e0dce22b 100644 --- a/client/render/AssetGenerator.cpp +++ b/client/render/AssetGenerator.cpp @@ -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 img = GH.renderHandler().loadImage(res, EImageBlitMode::OPAQUE); @@ -49,20 +52,21 @@ void AssetGenerator::createAdventureOptionsCleanBackground() std::shared_ptr 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 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 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 } diff --git a/lib/filesystem/CFilesystemLoader.cpp b/lib/filesystem/CFilesystemLoader.cpp index 3bc339898..c877bffd4 100644 --- a/lib/filesystem/CFilesystemLoader.cpp +++ b/lib/filesystem/CFilesystemLoader.cpp @@ -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 CFilesystemLoader::listFiles(const std::string &mountPoint, size_t depth, bool initial) const { static const EResType initArray[] = { diff --git a/lib/filesystem/CFilesystemLoader.h b/lib/filesystem/CFilesystemLoader.h index 6eb21809c..ec75c62a0 100644 --- a/lib/filesystem/CFilesystemLoader.h +++ b/lib/filesystem/CFilesystemLoader.h @@ -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 getResourceName(const ResourcePath & resourceName) const override; void updateFilteredFiles(std::function filter) const override; std::unordered_set getFilteredFiles(std::function filter) const override; diff --git a/lib/filesystem/Filesystem.cpp b/lib/filesystem/Filesystem.cpp index ff4f2bf5a..e3df56e34 100644 --- a/lib/filesystem/Filesystem.cpp +++ b/lib/filesystem/Filesystem.cpp @@ -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"); diff --git a/lib/filesystem/ISimpleResourceLoader.h b/lib/filesystem/ISimpleResourceLoader.h index 23e27b0e0..06b7c9a65 100644 --- a/lib/filesystem/ISimpleResourceLoader.h +++ b/lib/filesystem/ISimpleResourceLoader.h @@ -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 *