Browse Source

More changes following review.

krs 2 years ago
parent
commit
d516a5f529

+ 3 - 4
lib/filesystem/CArchiveLoader.cpp

@@ -28,10 +28,9 @@ ArchiveEntry::ArchiveEntry()
 
 
 CArchiveLoader::CArchiveLoader(std::string _mountPoint, bfs::path _archive, bool extractArchives) :
 CArchiveLoader::CArchiveLoader(std::string _mountPoint, bfs::path _archive, bool extractArchives) :
     archive(std::move(_archive)),
     archive(std::move(_archive)),
-    mountPoint(std::move(_mountPoint))
+    mountPoint(std::move(_mountPoint)),
+	extractArchives(extractArchives)
 {
 {
-	this->extractArchives = extractArchives;
-
 	// Open archive file(.snd, .vid, .lod)
 	// Open archive file(.snd, .vid, .lod)
 	CFileInputStream fileStream(archive);
 	CFileInputStream fileStream(archive);
 
 
@@ -246,7 +245,7 @@ void CArchiveLoader::extractToFolder(std::string outputSubFolder, const std::str
 	out.write(data.get(), entry.fullSize);
 	out.write(data.get(), entry.fullSize);
 }
 }
 
 
-bfs::path createExtractedFilePath(std::string outputSubFolder, std::string entryName)
+bfs::path createExtractedFilePath(const std::string & outputSubFolder, const std::string & entryName)
 {
 {
 	bfs::path extractionFolderPath = VCMIDirs::get().userCachePath() / "extracted" / outputSubFolder;
 	bfs::path extractionFolderPath = VCMIDirs::get().userCachePath() / "extracted" / outputSubFolder;
 	bfs::path extractedFilePath = extractionFolderPath / entryName;
 	bfs::path extractedFilePath = extractionFolderPath / entryName;

+ 1 - 1
lib/filesystem/CArchiveLoader.h

@@ -105,6 +105,6 @@ private:
 };
 };
 
 
 /** Constructs the file path for the extracted file. Creates the subfolder hierarchy aswell **/
 /** Constructs the file path for the extracted file. Creates the subfolder hierarchy aswell **/
-boost::filesystem::path createExtractedFilePath(std::string outputSubFolder, std::string entryName);
+boost::filesystem::path createExtractedFilePath(const std::string & outputSubFolder, const std::string & entryName);
 
 
 VCMI_LIB_NAMESPACE_END
 VCMI_LIB_NAMESPACE_END

+ 1 - 1
lib/filesystem/Filesystem.cpp

@@ -210,7 +210,7 @@ void CResourceHandler::load(const std::string &fsConfigURI, bool extractArchives
 	addFilesystem("data", "core", createFileSystem("", fsConfig["filesystem"], extractArchives));
 	addFilesystem("data", "core", createFileSystem("", fsConfig["filesystem"], extractArchives));
 }
 }
 
 
-void CResourceHandler::addFilesystem(const std::string & parent, const std::string & identifier, ISimpleResourceLoader * loader, bool extractArchives)
+void CResourceHandler::addFilesystem(const std::string & parent, const std::string & identifier, ISimpleResourceLoader * loader)
 {
 {
 	if(knownLoaders.count(identifier) != 0)
 	if(knownLoaders.count(identifier) != 0)
 	{
 	{

+ 1 - 1
lib/filesystem/Filesystem.h

@@ -92,7 +92,7 @@ public:
 	 * @param identifier name of this loader by which it can be retrieved later
 	 * @param identifier name of this loader by which it can be retrieved later
 	 * @param loader resource loader to add
 	 * @param loader resource loader to add
 	 */
 	 */
-	static void addFilesystem(const std::string & parent, const std::string & identifier, ISimpleResourceLoader * loader, bool extractArchives = false);
+	static void addFilesystem(const std::string & parent, const std::string & identifier, ISimpleResourceLoader * loader);
 	
 	
 	/**
 	/**
 	 * @brief removeFilesystem removes previously added filesystem from global resouce holder
 	 * @brief removeFilesystem removes previously added filesystem from global resouce holder

+ 2 - 11
mapeditor/Animation.cpp

@@ -719,7 +719,7 @@ void Animation::exportBitmaps(const bfs::path & path, bool prependResourceName)
 				fileName = name + "_" + fileName;
 				fileName = name + "_" + fileName;
 
 
 			auto s = img->size();
 			auto s = img->size();
-			img->save(QStringFromPath(actualPath / fileName), "PNG");
+			img->save(pathToQString(actualPath / fileName), "PNG");
 
 
 			counter++;
 			counter++;
 		}
 		}
@@ -816,13 +816,4 @@ void Animation::createFlippedGroup(const size_t sourceGroup, const size_t target
 		auto image = getImage(frame, targetGroup);
 		auto image = getImage(frame, targetGroup);
 		*image = image->transformed(QTransform::fromScale(1, -1));
 		*image = image->transformed(QTransform::fromScale(1, -1));
 	}
 	}
-}
-
-QString QStringFromPath(const bfs::path& filePath)
-{
-#ifdef _WIN32
-	return QString::fromStdWString(filePath.generic_wstring());
-#else
-	return QString::fromStdString(filePath.native());
-#endif
-}
+}

+ 0 - 3
mapeditor/Animation.h

@@ -94,6 +94,3 @@ public:
 
 
 	void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
 	void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
 };
 };
-
-// ToDo: krs - temp location for this function. Need to move to right lib and see if it works on other platforms.
-QString QStringFromPath(const boost::filesystem::path& filePath);

+ 5 - 12
mapeditor/mainwindow.cpp

@@ -109,17 +109,10 @@ void MainWindow::parseCommandLine()
 	if (!positionalArgs.isEmpty())
 	if (!positionalArgs.isEmpty())
 		mapFilePath = positionalArgs.at(0);
 		mapFilePath = positionalArgs.at(0);
 
 
-	if (parser.isSet("e"))
-		extractArchives = true;
-
-	if (parser.isSet("s"))
-		splitDefs = true;
-
-	if (parser.isSet("c"))
-		convertPcxToPng = true;
-
-	if (parser.isSet("d"))
-		deleteOriginals = true;
+	extractArchives = parser.isSet("e");
+	splitDefs = parser.isSet("s");
+	convertPcxToPng = parser.isSet("c");
+	deleteOriginals = parser.isSet("d");
 }
 }
 
 
 MainWindow::MainWindow(QWidget *parent) :
 MainWindow::MainWindow(QWidget *parent) :
@@ -176,7 +169,7 @@ MainWindow::MainWindow(QWidget *parent) :
 	graphics = new Graphics(); // should be before curh->init()
 	graphics = new Graphics(); // should be before curh->init()
 	graphics->load();//must be after Content loading but should be in main thread
 	graphics->load();//must be after Content loading but should be in main thread
 
 
-	ConvertExtractedResourceFiles(splitDefs, convertPcxToPng, deleteOriginals);
+	convertExtractedResourceFiles(splitDefs, convertPcxToPng, deleteOriginals);
 	
 	
 	ui->mapView->setScene(controller.scene(0));
 	ui->mapView->setScene(controller.scene(0));
 	ui->mapView->setController(&controller);
 	ui->mapView->setController(&controller);

+ 37 - 29
mapeditor/resourceExtractor/ResourceConverter.cpp

@@ -1,3 +1,13 @@
+/*
+ * ResourceConverter.h, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+
 #include "StdInc.h"
 #include "StdInc.h"
 
 
 #include "ResourceConverter.h"
 #include "ResourceConverter.h"
@@ -15,12 +25,14 @@
 namespace bfs = boost::filesystem;
 namespace bfs = boost::filesystem;
 
 
 // converts all pcx files from /Images into PNG
 // converts all pcx files from /Images into PNG
-void ConvertPcxToPng(bool deleteOriginals)
+void doConvertPcxToPng(bool deleteOriginals)
 {
 {
-	bfs::path imagesPath = VCMIDirs::get().userCachePath() / "extracted" / "Images";
+	std::string filename;
+
+	bfs::path imagesPath = VCMIDirs::get().userCachePath() / "extracted" / "IMAGES";
 	bfs::directory_iterator end_iter;
 	bfs::directory_iterator end_iter;
 
 
-	for ( bfs::directory_iterator dir_itr(imagesPath); dir_itr != end_iter; ++dir_itr )
+	for(bfs::directory_iterator dir_itr(imagesPath); dir_itr != end_iter; ++dir_itr)
 	{
 	{
 		try
 		try
 		{
 		{
@@ -29,33 +41,32 @@ void ConvertPcxToPng(bool deleteOriginals)
 
 
 			std::string filePath = dir_itr->path().string();
 			std::string filePath = dir_itr->path().string();
 			std::string fileStem = dir_itr->path().stem().string();
 			std::string fileStem = dir_itr->path().stem().string();
-			std::string filename = dir_itr->path().filename().string();
-			filename = boost::locale::to_lower(filename);
+			filename = dir_itr->path().filename().string();
+			std::string filenameLowerCase = boost::locale::to_lower(filename);
 
 
-			if(filename.find(".pcx") != std::string::npos)
+			if(bfs::extension(filenameLowerCase) == ".pcx")
 			{
 			{
-				auto img = BitmapHandler::loadBitmap(filename);
+				auto img = BitmapHandler::loadBitmap(filenameLowerCase);
 				bfs::path pngFilePath = imagesPath / (fileStem + ".png");
 				bfs::path pngFilePath = imagesPath / (fileStem + ".png");
-				img.save(QStringFromPath(pngFilePath), "PNG");
+				img.save(pathToQString(pngFilePath), "PNG");
 
 
-				if (deleteOriginals)
+				if(deleteOriginals)
 					bfs::remove(filePath);
 					bfs::remove(filePath);
 			}
 			}
 		}
 		}
-		catch ( const std::exception & ex )
+		catch(const std::exception & ex)
 		{
 		{
-			logGlobal->info(dir_itr->path().filename().string() + " " + ex.what() + "\n");
+			logGlobal->info(filename + " " + ex.what() + "\n");
 		}
 		}
 	}
 	}
 }
 }
 
 
 // splits a def file into individual parts and converts the output to PNG format
 // splits a def file into individual parts and converts the output to PNG format
-void SplitDefFile(std::string fileName, bfs::path spritesPath, bool deleteOriginals)
+void splitDefFile(const std::string & fileName, const bfs::path & spritesPath, bool deleteOriginals)
 {
 {
-	if (CResourceHandler::get()->existsResource(ResourceID("SPRITES/" + fileName)))
+	if(CResourceHandler::get()->existsResource(ResourceID("SPRITES/" + fileName)))
 	{
 	{
-		std::string URI = fileName;
-		std::unique_ptr<Animation> anim = make_unique<Animation>(URI);
+		std::unique_ptr<Animation> anim = make_unique<Animation>(fileName);
 		anim->preload();
 		anim->preload();
 		anim->exportBitmaps(VCMIDirs::get().userCachePath() / "extracted", true);
 		anim->exportBitmaps(VCMIDirs::get().userCachePath() / "extracted", true);
 
 
@@ -66,26 +77,23 @@ void SplitDefFile(std::string fileName, bfs::path spritesPath, bool deleteOrigin
 		logGlobal->error("Def File Split error! " + fileName);
 		logGlobal->error("Def File Split error! " + fileName);
 }
 }
 
 
-// splits def files (TwCrPort, CPRSMALL, FlagPort, ITPA, ITPt, Un32 and Un44), this way faction resources are independent
+// splits def files (TwCrPort, CPRSMALL, FlagPort, ITPA, ITPt, Un32 and Un44) so that faction resources are independent
+// (town creature portraits, hero army creature portraits, adventure map dwellings, small town icons, big town icons, 
+// hero speciality small icons, hero speciality large icons)
 void splitDefFiles(bool deleteOriginals)
 void splitDefFiles(bool deleteOriginals)
 {
 {
 	bfs::path extractedPath = VCMIDirs::get().userDataPath() / "extracted";
 	bfs::path extractedPath = VCMIDirs::get().userDataPath() / "extracted";
-	bfs::path spritesPath = extractedPath / "Sprites";
-
-	SplitDefFile("TwCrPort.def", spritesPath, deleteOriginals);	// split town creature portraits
-	SplitDefFile("CPRSMALL.def", spritesPath, deleteOriginals);	// split hero army creature portraits 
-	SplitDefFile("FlagPort.def", spritesPath, deleteOriginals);	// adventure map dwellings
-	SplitDefFile("ITPA.def", spritesPath, deleteOriginals);		// small town icons
-	SplitDefFile("ITPt.def", spritesPath, deleteOriginals);		// big town icons
-	SplitDefFile("Un32.def", spritesPath, deleteOriginals);		// big town icons
-	SplitDefFile("Un44.def", spritesPath, deleteOriginals);		// big town icons
+	bfs::path spritesPath = extractedPath / "SPRITES";
+
+	for(std::string defFilename : {"TwCrPort.def", "CPRSMALL.def", "FlagPort.def", "ITPA.def", "ITPt.def", "Un32.def", "Un44.def"})
+		splitDefFile(defFilename, spritesPath, deleteOriginals);
 }
 }
 
 
-void ConvertExtractedResourceFiles(bool splitDefs, bool convertPcxToPng, bool deleteOriginals)
+void convertExtractedResourceFiles(bool splitDefs, bool convertPcxToPng, bool deleteOriginals)
 {
 {
-	if (splitDefs)
+	if(splitDefs)
 		splitDefFiles(deleteOriginals);
 		splitDefFiles(deleteOriginals);
 
 
-	if (convertPcxToPng)
-		ConvertPcxToPng(deleteOriginals);
+	if(convertPcxToPng)
+		doConvertPcxToPng(deleteOriginals);
 }
 }

+ 3 - 4
mapeditor/resourceExtractor/ResourceConverter.h

@@ -1,7 +1,5 @@
-#pragma once
-
 /*
 /*
- * VCMI_Lib.cpp, part of VCMI engine
+ * ResourceConverter.h, part of VCMI engine
  *
  *
  * Authors: listed in file AUTHORS in main folder
  * Authors: listed in file AUTHORS in main folder
  *
  *
@@ -9,6 +7,7 @@
  * Full text of license available in license.txt file, in main folder
  * Full text of license available in license.txt file, in main folder
  *
  *
  */
  */
+#pragma once
  
  
  // Splits def files that are shared between factions and converts pcx to bmp
  // Splits def files that are shared between factions and converts pcx to bmp
-void ConvertExtractedResourceFiles(bool splitDefs, bool convertPcxToPng, bool deleteOriginals);
+void convertExtractedResourceFiles(bool splitDefs, bool convertPcxToPng, bool deleteOriginals);