mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-16 02:47:36 +02:00
73019c204d
grep -r --include \*.h --include \*.cpp "= std::" * | grep -v auto | grep -Po ".*[^ ]+ [^ ]+ [^ ]*[ ]*=.*;" | grep -v "auto\|int\|char\|bool\|float|\double\|for\|if\|googletest\|fuzzylite\|size_t\|using\|return" | grep -v double | grep -v si64 | grep -v si32 | grep -v ui32 | grep \< | grep -v float | tr -d '\t' | grep -v assert > redundant_types.txt import re with open("redundant_types.txt") as f: for line in f: line = line.strip() path = line.split(":", 1)[0] original_code = ":".join(line.split(":")[1:]).strip() print() print(path) print(original_code) prefix = "auto " if original_code.startswith("static"): static = True else: static = False cpp_type = " ".join(original_code.split("=")[0].strip().split(" ")[0:-1]) print(cpp_type) if static: new_code = "static auto "+ " ".join(original_code.split(" ")[2:]) else: new_code = "auto "+ " ".join(original_code.split(" ")[1:]) print(new_code) if True: with open(path, "r") as f: filedata = f.read() filedata = filedata.replace(original_code, new_code) with open(path, "w") as f: f.write(filedata)
92 lines
2.9 KiB
C++
92 lines
2.9 KiB
C++
/*
|
|
* ResourceConverter.cpp, 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 "ResourceConverter.h"
|
|
|
|
#include "../lib/JsonNode.h"
|
|
#include "../lib/VCMIDirs.h"
|
|
#include "../lib/filesystem/Filesystem.h"
|
|
|
|
#include "BitmapHandler.h"
|
|
#include "Animation.h"
|
|
|
|
#include <boost/filesystem/path.hpp>
|
|
#include <boost/locale.hpp>
|
|
|
|
void ResourceConverter::convertExtractedResourceFiles(ConversionOptions conversionOptions)
|
|
{
|
|
boost::filesystem::path spritesPath = VCMIDirs::get().userExtractedPath() / "SPRITES";
|
|
boost::filesystem::path imagesPath = VCMIDirs::get().userExtractedPath() / "IMAGES";
|
|
std::vector<std::string> defFiles = { "TwCrPort.def", "CPRSMALL.def", "FlagPort.def", "ITPA.def", "ITPt.def", "Un32.def", "Un44.def" };
|
|
|
|
if(conversionOptions.splitDefs)
|
|
splitDefFiles(defFiles, spritesPath, conversionOptions.deleteOriginals);
|
|
|
|
if(conversionOptions.convertPcxToPng)
|
|
doConvertPcxToPng(imagesPath, conversionOptions.deleteOriginals);
|
|
}
|
|
|
|
void ResourceConverter::doConvertPcxToPng(const boost::filesystem::path & sourceFolder, bool deleteOriginals)
|
|
{
|
|
logGlobal->info("Converting .pcx to .png from folder: %s ...\n", sourceFolder);
|
|
|
|
for(const auto & directoryEntry : boost::filesystem::directory_iterator(sourceFolder))
|
|
{
|
|
const auto filename = directoryEntry.path().filename();
|
|
try
|
|
{
|
|
if(!boost::filesystem::is_regular_file(directoryEntry))
|
|
continue;
|
|
|
|
std::string fileStem = directoryEntry.path().stem().string();
|
|
std::string filenameLowerCase = boost::algorithm::to_lower_copy(filename.string());
|
|
|
|
if(boost::algorithm::to_lower_copy(filename.extension().string()) == ".pcx")
|
|
{
|
|
auto img = BitmapHandler::loadBitmap(filenameLowerCase);
|
|
boost::filesystem::path pngFilePath = sourceFolder / (fileStem + ".png");
|
|
img.save(pathToQString(pngFilePath), "PNG");
|
|
|
|
if(deleteOriginals)
|
|
boost::filesystem::remove(directoryEntry.path());
|
|
}
|
|
}
|
|
catch(const std::exception& ex)
|
|
{
|
|
logGlobal->info(filename.string() + " " + ex.what() + "\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
void ResourceConverter::splitDefFile(const std::string & fileName, const boost::filesystem::path & sourceFolder, bool deleteOriginals)
|
|
{
|
|
if(CResourceHandler::get()->existsResource(ResourcePath("SPRITES/" + fileName)))
|
|
{
|
|
auto anim = std::make_unique<Animation>(fileName);
|
|
anim->preload();
|
|
anim->exportBitmaps(pathToQString(sourceFolder));
|
|
|
|
if(deleteOriginals)
|
|
boost::filesystem::remove(sourceFolder / fileName);
|
|
}
|
|
else
|
|
logGlobal->error("Def File Split error! " + fileName);
|
|
}
|
|
|
|
void ResourceConverter::splitDefFiles(const std::vector<std::string> & defFileNames, const boost::filesystem::path & sourceFolder, bool deleteOriginals)
|
|
{
|
|
logGlobal->info("Splitting Def Files from folder: %s ...\n", sourceFolder);
|
|
|
|
for(const auto & defFilename : defFileNames)
|
|
splitDefFile(defFilename, sourceFolder, deleteOriginals);
|
|
}
|