浏览代码

remove resource

Laserlicht 1 年之前
父节点
当前提交
d8869a33da

+ 4 - 8
client/render/AssetGenerator.cpp

@@ -31,10 +31,6 @@ void AssetGenerator::createAdventureOptionsCleanBackground()
 	if(!CResourceHandler::get("local")->createResource(filename))
 	if(!CResourceHandler::get("local")->createResource(filename))
 		return;
 		return;
 	ResourcePath savePath(filename, EResType::IMAGE);
 	ResourcePath savePath(filename, EResType::IMAGE);
-	
-	if(boost::filesystem::exists(*CResourceHandler::get("local")->getResourceName(savePath)) &&
-	   boost::filesystem::file_size(*CResourceHandler::get("local")->getResourceName(savePath)))
-		return;   
 
 
 	auto res = ImagePath::builtin("ADVOPTBK");
 	auto res = ImagePath::builtin("ADVOPTBK");
 	res.setOriginalResource(true);
 	res.setOriginalResource(true);
@@ -53,6 +49,8 @@ void AssetGenerator::createAdventureOptionsCleanBackground()
 	std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
 	std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
 
 
 	image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
 	image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
+
+	CResourceHandler::get("local")->removeResource(savePath); // remove resource -> may overridden by mod later
 }
 }
 
 
 void AssetGenerator::createBigSpellBook()
 void AssetGenerator::createBigSpellBook()
@@ -62,10 +60,6 @@ void AssetGenerator::createBigSpellBook()
 	if(!CResourceHandler::get("local")->createResource(filename))
 	if(!CResourceHandler::get("local")->createResource(filename))
 		return;
 		return;
 	ResourcePath savePath(filename, EResType::IMAGE);
 	ResourcePath savePath(filename, EResType::IMAGE);
-	
-	if(boost::filesystem::exists(*CResourceHandler::get("local")->getResourceName(savePath)) &&
-	   boost::filesystem::file_size(*CResourceHandler::get("local")->getResourceName(savePath)))
-		return;   
 
 
 	auto res = ImagePath::builtin("SpelBack");
 	auto res = ImagePath::builtin("SpelBack");
 	res.setOriginalResource(true);
 	res.setOriginalResource(true);
@@ -117,4 +111,6 @@ void AssetGenerator::createBigSpellBook()
 	std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
 	std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
 
 
 	image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
 	image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
+
+	CResourceHandler::get("local")->removeResource(savePath); // remove resource -> may overridden by mod later
 }
 }

+ 1 - 1
client/render/AssetGenerator.h

@@ -16,4 +16,4 @@ class AssetGenerator
 
 
 public:
 public:
     static void generate();
     static void generate();
-};
+};

+ 5 - 0
lib/filesystem/CFilesystemLoader.cpp

@@ -108,6 +108,11 @@ bool CFilesystemLoader::createResource(const std::string & requestedFilename, bo
 	return true;
 	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
 std::unordered_map<ResourcePath, boost::filesystem::path> CFilesystemLoader::listFiles(const std::string &mountPoint, size_t depth, bool initial) const
 {
 {
 	static const EResType initArray[] = {
 	static const EResType initArray[] = {

+ 1 - 0
lib/filesystem/CFilesystemLoader.h

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

+ 5 - 0
lib/filesystem/ISimpleResourceLoader.h

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