mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
ResourceExtractor code moved to a static class.
This commit is contained in:
parent
8377944fd1
commit
c32cd190f2
@ -41,15 +41,8 @@
|
|||||||
#include "resourceExtractor/ResourceConverter.h"
|
#include "resourceExtractor/ResourceConverter.h"
|
||||||
|
|
||||||
static CBasicLogConfigurator * logConfig;
|
static CBasicLogConfigurator * logConfig;
|
||||||
ExtractionOptions * extractionOptions; // All command line options for resource extractor
|
|
||||||
|
|
||||||
ExtractionOptions::ExtractionOptions(const bool extractArchives, const bool splitDefs, const bool convertPcxToPng, const bool deleteOriginals) :
|
ExtractionOptions extractionOptions;
|
||||||
extractArchives(extractArchives),
|
|
||||||
splitDefs(splitDefs),
|
|
||||||
convertPcxToPng(convertPcxToPng),
|
|
||||||
deleteOriginals(deleteOriginals)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonValue jsonFromPixmap(const QPixmap &p)
|
QJsonValue jsonFromPixmap(const QPixmap &p)
|
||||||
{
|
{
|
||||||
@ -118,10 +111,10 @@ void MainWindow::parseCommandLine()
|
|||||||
if (!positionalArgs.isEmpty())
|
if (!positionalArgs.isEmpty())
|
||||||
mapFilePath = positionalArgs.at(0);
|
mapFilePath = positionalArgs.at(0);
|
||||||
|
|
||||||
extractionOptions = new ExtractionOptions(parser.isSet("e"), parser.isSet("s"), parser.isSet("c"), parser.isSet("d"));
|
extractionOptions = {parser.isSet("e"), {parser.isSet("s"), parser.isSet("c"), parser.isSet("d")}};
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget* parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow),
|
ui(new Ui::MainWindow),
|
||||||
controller(this)
|
controller(this)
|
||||||
@ -144,7 +137,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
logGlobal->info("The log file will be saved to %s", logPath);
|
logGlobal->info("The log file will be saved to %s", logPath);
|
||||||
|
|
||||||
//init
|
//init
|
||||||
preinitDLL(::console, false, extractionOptions->extractArchives);
|
preinitDLL(::console, false, extractionOptions.extractArchives);
|
||||||
settings.init();
|
settings.init();
|
||||||
|
|
||||||
// Initialize logging based on settings
|
// Initialize logging based on settings
|
||||||
@ -161,7 +154,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!testFile("DATA/HELP.TXT", "Heroes III data") ||
|
if (!testFile("DATA/HELP.TXT", "Heroes III data") ||
|
||||||
!testFile("MODS/VCMI/MOD.JSON", "VCMI data"))
|
!testFile("MODS/VCMI/MOD.JSON", "VCMI data"))
|
||||||
{
|
{
|
||||||
QApplication::quit();
|
QApplication::quit();
|
||||||
@ -175,8 +168,8 @@ 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
|
||||||
|
|
||||||
if (extractionOptions->extractArchives)
|
if (extractionOptions.extractArchives)
|
||||||
convertExtractedResourceFiles(extractionOptions->splitDefs, extractionOptions->convertPcxToPng, extractionOptions->deleteOriginals);
|
ResourceConverter::convertExtractedResourceFiles(extractionOptions.conversionOptions);
|
||||||
|
|
||||||
ui->mapView->setScene(controller.scene(0));
|
ui->mapView->setScene(controller.scene(0));
|
||||||
ui->mapView->setController(&controller);
|
ui->mapView->setController(&controller);
|
||||||
|
@ -148,13 +148,3 @@ private:
|
|||||||
// command line options
|
// command line options
|
||||||
QString mapFilePath; // FilePath to the H3 or VCMI map to open
|
QString mapFilePath; // FilePath to the H3 or VCMI map to open
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExtractionOptions
|
|
||||||
{
|
|
||||||
ExtractionOptions(const bool extractArchives, const bool splitDefs, const bool convertPcxToPng, const bool deleteOriginals);
|
|
||||||
|
|
||||||
bool extractArchives = false; // extract original H3 archives into a separate folder
|
|
||||||
bool splitDefs = false; // splits TwCrPort, CPRSMALL, FlagPort, ITPA, ITPt, Un32 and Un44 into individual PNG's
|
|
||||||
bool convertPcxToPng = false; // converts single Images (found in Images folder) from .pcx to png.
|
|
||||||
bool deleteOriginals = false; // delete original files, for the ones splitted / converted.
|
|
||||||
};
|
|
||||||
|
@ -22,10 +22,16 @@
|
|||||||
#include "boost/filesystem/path.hpp"
|
#include "boost/filesystem/path.hpp"
|
||||||
#include "boost/locale.hpp"
|
#include "boost/locale.hpp"
|
||||||
|
|
||||||
namespace bfs = boost::filesystem;
|
void ResourceConverter::convertExtractedResourceFiles(ConversionOptions conversionOptions)
|
||||||
|
{
|
||||||
|
if (conversionOptions.splitDefs)
|
||||||
|
splitDefFiles(conversionOptions.deleteOriginals);
|
||||||
|
|
||||||
// converts all pcx files from /Images into PNG
|
if (conversionOptions.convertPcxToPng)
|
||||||
void doConvertPcxToPng(bool deleteOriginals)
|
doConvertPcxToPng(conversionOptions.deleteOriginals);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceConverter::doConvertPcxToPng(bool deleteOriginals)
|
||||||
{
|
{
|
||||||
std::string filename;
|
std::string filename;
|
||||||
|
|
||||||
@ -61,8 +67,7 @@ void doConvertPcxToPng(bool deleteOriginals)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// splits a def file into individual parts and converts the output to PNG format
|
void ResourceConverter::splitDefFile(const std::string & fileName, const 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)))
|
||||||
{
|
{
|
||||||
@ -77,22 +82,10 @@ void splitDefFile(const std::string & fileName, const bfs::path & spritesPath, b
|
|||||||
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) so that faction resources are independent
|
void ResourceConverter::splitDefFiles(bool deleteOriginals)
|
||||||
// (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)
|
|
||||||
{
|
{
|
||||||
bfs::path spritesPath = VCMIDirs::get().userExtractedPath() / "SPRITES";
|
bfs::path spritesPath = VCMIDirs::get().userExtractedPath() / "SPRITES";
|
||||||
|
|
||||||
for(std::string defFilename : {"TwCrPort.def", "CPRSMALL.def", "FlagPort.def", "ITPA.def", "ITPt.def", "Un32.def", "Un44.def"})
|
for(std::string defFilename : {"TwCrPort.def", "CPRSMALL.def", "FlagPort.def", "ITPA.def", "ITPt.def", "Un32.def", "Un44.def"})
|
||||||
splitDefFile(defFilename, spritesPath, deleteOriginals);
|
splitDefFile(defFilename, spritesPath, deleteOriginals);
|
||||||
}
|
}
|
||||||
|
|
||||||
void convertExtractedResourceFiles(bool splitDefs, bool convertPcxToPng, bool deleteOriginals)
|
|
||||||
{
|
|
||||||
if(splitDefs)
|
|
||||||
splitDefFiles(deleteOriginals);
|
|
||||||
|
|
||||||
if(convertPcxToPng)
|
|
||||||
doConvertPcxToPng(deleteOriginals);
|
|
||||||
}
|
|
@ -9,5 +9,41 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Splits def files that are shared between factions and converts pcx to bmp
|
namespace bfs = boost::filesystem;
|
||||||
void convertExtractedResourceFiles(bool splitDefs, bool convertPcxToPng, bool deleteOriginals);
|
|
||||||
|
// Struct for holding all Convertor Options
|
||||||
|
struct ConversionOptions
|
||||||
|
{
|
||||||
|
bool splitDefs = false; // splits TwCrPort, CPRSMALL, FlagPort, ITPA, ITPt, Un32 and Un44 into individual PNG's
|
||||||
|
bool convertPcxToPng = false; // converts single Images (found in Images folder) from .pcx to png.
|
||||||
|
bool deleteOriginals = false; // delete original files, for the ones splitted / converted.
|
||||||
|
};
|
||||||
|
|
||||||
|
// Struct for holding all Resource Extractor / Converter options
|
||||||
|
struct ExtractionOptions
|
||||||
|
{
|
||||||
|
bool extractArchives = false; // if set, original H3 archives will be extracted into a separate folder
|
||||||
|
ConversionOptions conversionOptions;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ResourceConverter
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Splits def files that are shared between factions and converts pcx to bmp depending on Extraction Options
|
||||||
|
static void convertExtractedResourceFiles(ConversionOptions conversionOptions);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// converts all pcx files from /Images into PNG
|
||||||
|
static void doConvertPcxToPng(bool deleteOriginals);
|
||||||
|
|
||||||
|
// splits a def file into individual parts and converts the output to PNG format
|
||||||
|
static void splitDefFile(const std::string& fileName, const bfs::path& spritesPath, bool deleteOriginals);
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
static void splitDefFiles(bool deleteOriginals);
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user