1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Extractor moved to Editor

This commit is contained in:
krs
2022-11-14 21:32:29 +02:00
parent 93cf2682f3
commit 10ec486251
8 changed files with 110 additions and 55 deletions

View File

@@ -59,7 +59,6 @@
#include "../lib/serializer/Connection.h" #include "../lib/serializer/Connection.h"
#include "CServerHandler.h" #include "CServerHandler.h"
#include "gui/NotificationHandler.h" #include "gui/NotificationHandler.h"
#include "resourceExtractor/ResourceConverter.h"
#include <boost/asio.hpp> #include <boost/asio.hpp>
@@ -466,7 +465,7 @@ int main(int argc, char * argv[])
CCS->curh = new CCursorHandler(); CCS->curh = new CCursorHandler();
graphics = new Graphics(); // should be before curh->init() graphics = new Graphics(); // should be before curh->init()
ConvertOriginalResourceFiles(); // ConvertOriginalResourceFiles();
CCS->curh->initCursor(); CCS->curh->initCursor();
logGlobal->info("Screen handler: %d ms", pomtime.getDiff()); logGlobal->info("Screen handler: %d ms", pomtime.getDiff());

View File

@@ -54,8 +54,6 @@ set(client_SRCS
lobby/OptionsTab.cpp lobby/OptionsTab.cpp
lobby/RandomMapTab.cpp lobby/RandomMapTab.cpp
lobby/SelectionTab.cpp lobby/SelectionTab.cpp
resourceExtractor/ResourceConverter.cpp
CBitmapHandler.cpp CBitmapHandler.cpp
CreatureCostBox.cpp CreatureCostBox.cpp
@@ -130,8 +128,6 @@ set(client_HEADERS
lobby/OptionsTab.h lobby/OptionsTab.h
lobby/RandomMapTab.h lobby/RandomMapTab.h
lobby/SelectionTab.h lobby/SelectionTab.h
resourceExtractor/ResourceConverter.h
CBitmapHandler.h CBitmapHandler.h
CreatureCostBox.h CreatureCostBox.h

View File

@@ -19,10 +19,23 @@
#include "../lib/filesystem/ISimpleResourceLoader.h" #include "../lib/filesystem/ISimpleResourceLoader.h"
#include "../lib/JsonNode.h" #include "../lib/JsonNode.h"
#include "../lib/CRandomGenerator.h" #include "../lib/CRandomGenerator.h"
#include "../lib/VCMIDirs.h"
#include <boost/filesystem.hpp>
namespace bfs = boost::filesystem;
typedef std::map<size_t, std::vector<JsonNode>> source_map; typedef std::map<size_t, std::vector<JsonNode>> source_map;
// ToDo: krs - temp location for this function. Need to move to right lib and see if it works on other platforms.
QString QStringFromPath(const bfs::path& filePath)
{
#ifdef _WIN32
return QString::fromStdWString(filePath.generic_wstring());
#else
return QString::fromStdString(filePath.native());
#endif
}
/// Class for def loading /// Class for def loading
/// After loading will store general info (palette and frame offsets) and pointer to file itself /// After loading will store general info (palette and frame offsets) and pointer to file itself
class DefFile class DefFile
@@ -686,6 +699,44 @@ std::shared_ptr<QImage> Animation::getImage(size_t frame, size_t group, bool ver
return nullptr; return nullptr;
} }
void Animation::exportBitmaps(const bfs::path& path, bool prependResourceName) const
{
if (images.empty())
{
logGlobal->error("Nothing to export, animation is empty");
return;
}
boost::filesystem::path actualPath = path / "Sprites" / name;
boost::filesystem::create_directories(actualPath);
size_t counter = 0;
for (const auto& groupPair : images)
{
size_t group = groupPair.first;
for (const auto& imagePair : groupPair.second)
{
size_t frame = imagePair.first;
const auto img = imagePair.second;
boost::format fmt("%d_%d.bmp");
fmt% group% frame;
std::string fileName = fmt.str();
if (prependResourceName)
fileName = name + "_" + fileName;
auto s = img->size();
img->save(QStringFromPath(actualPath / fileName), "PNG");
counter++;
}
}
logGlobal->info("Exported %d frames to %s", counter, actualPath.string());
}
void Animation::load() void Animation::load()
{ {
for (auto & elem : source) for (auto & elem : source)

View File

@@ -83,6 +83,8 @@ public:
void load (size_t frame, size_t group = 0); void load (size_t frame, size_t group = 0);
void unload(size_t frame, size_t group = 0); void unload(size_t frame, size_t group = 0);
void exportBitmaps(const boost::filesystem::path& path, bool prependResourceName) const;
//total count of frames in group (including not loaded) //total count of frames in group (including not loaded)
size_t size(size_t group = 0) const; size_t size(size_t group = 0) const;

View File

@@ -24,6 +24,7 @@ set(editor_SRCS
inspector/messagewidget.cpp inspector/messagewidget.cpp
inspector/rewardswidget.cpp inspector/rewardswidget.cpp
inspector/questwidget.cpp inspector/questwidget.cpp
resourceExtractor/ResourceConverter.cpp
) )
set(editor_HEADERS set(editor_HEADERS
@@ -51,6 +52,7 @@ set(editor_HEADERS
inspector/messagewidget.h inspector/messagewidget.h
inspector/rewardswidget.h inspector/rewardswidget.h
inspector/questwidget.h inspector/questwidget.h
resourceExtractor/ResourceConverter.h
) )
set(editor_FORMS set(editor_FORMS

View File

@@ -38,6 +38,7 @@
#include "mapsettings.h" #include "mapsettings.h"
#include "playersettings.h" #include "playersettings.h"
#include "validator.h" #include "validator.h"
#include "resourceExtractor/ResourceConverter.h"
static CBasicLogConfigurator * logConfig; static CBasicLogConfigurator * logConfig;
@@ -110,6 +111,9 @@ MainWindow::MainWindow(QWidget *parent) :
//init //init
preinitDLL(::console); preinitDLL(::console);
//ConvertOriginalResourceFiles();
settings.init(); settings.init();
// Initialize logging based on settings // Initialize logging based on settings
@@ -139,6 +143,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
ConvertOriginalResourceFiles();
ui->mapView->setScene(controller.scene(0)); ui->mapView->setScene(controller.scene(0));
ui->mapView->setController(&controller); ui->mapView->setController(&controller);

View File

@@ -6,9 +6,9 @@
#include "../lib/VCMIDirs.h" #include "../lib/VCMIDirs.h"
#include "../lib/filesystem/Filesystem.h" #include "../lib/filesystem/Filesystem.h"
#include "SDL.h" //#include "SDL.h"
#include "./gui/CAnimation.h" #include "Animation.h"
#include "CBitmapHandler.h" //#include "CBitmapHandler.h"
#include "boost/filesystem/path.hpp" #include "boost/filesystem/path.hpp"
#include "boost/locale.hpp" #include "boost/locale.hpp"
@@ -16,51 +16,51 @@
namespace bfs = boost::filesystem; namespace bfs = boost::filesystem;
bool split_def_files = 1; bool split_def_files = 1;
bool convert_pcx_to_bmp = 1; // converts Images from .pcx to bmp. Can be used when you have .pcx converted already bool convert_pcx_to_bmp = 0; // converts Images from .pcx to bmp. Can be used when you have .pcx converted already
bool delete_source_files = 1; // delete source files or leave a copy in place. bool delete_source_files = 0; // delete source files or leave a copy in place.
// converts all pcx files into bmp (H3 saves images as .pcx) // converts all pcx files into bmp (H3 saves images as .pcx)
void convertPcxToBmp() //void convertPcxToBmp()
{ //{
bfs::path extractedPath = VCMIDirs::get().userDataPath() / "extracted"; // bfs::path extractedPath = VCMIDirs::get().userDataPath() / "extracted";
bfs::path imagesPath = extractedPath / "Images"; // bfs::path imagesPath = extractedPath / "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
{ // {
if ( bfs::is_regular_file( dir_itr->status() ) ) // if ( bfs::is_regular_file( dir_itr->status() ) )
{ // {
std::string filename = dir_itr->path().filename().string(); // std::string filename = dir_itr->path().filename().string();
filename = boost::locale::to_lower(filename); // filename = boost::locale::to_lower(filename);
//
if(filename.find(".pcx") != std::string::npos) // if(filename.find(".pcx") != std::string::npos)
{ // {
SDL_Surface *bitmap; // SDL_Surface *bitmap;
//
bitmap = BitmapHandler::loadBitmap(filename); // bitmap = BitmapHandler::loadBitmap(filename);
//
if(delete_source_files) // if(delete_source_files)
bfs::remove(imagesPath / filename); // bfs::remove(imagesPath / filename);
//
bfs::path outFilePath = imagesPath / filename; // bfs::path outFilePath = imagesPath / filename;
outFilePath.replace_extension(".bmp"); // outFilePath.replace_extension(".bmp");
SDL_SaveBMP(bitmap, outFilePath.string().c_str()); // SDL_SaveBMP(bitmap, outFilePath.string().c_str());
} // }
} // }
else // else
{ // {
logGlobal->info(dir_itr->path().filename().string() + " [other]\n"); // logGlobal->info(dir_itr->path().filename().string() + " [other]\n");
} // }
} // }
catch ( const std::exception & ex ) // catch ( const std::exception & ex )
{ // {
logGlobal->info(dir_itr->path().filename().string() + " " + ex.what() + "\n"); // logGlobal->info(dir_itr->path().filename().string() + " " + ex.what() + "\n");
} // }
} // }
} //}
// splits a def file into individual parts // splits a def file into individual parts
void splitDefFile(std::string fileName, bfs::path spritesPath) void splitDefFile(std::string fileName, bfs::path spritesPath)
@@ -68,7 +68,7 @@ void splitDefFile(std::string fileName, bfs::path spritesPath)
if (CResourceHandler::get()->existsResource(ResourceID("SPRITES/" + fileName))) if (CResourceHandler::get()->existsResource(ResourceID("SPRITES/" + fileName)))
{ {
std::string URI = fileName; std::string URI = fileName;
std::unique_ptr<CAnimation> anim = make_unique<CAnimation>(URI); std::unique_ptr<Animation> anim = make_unique<Animation>(URI);
anim->preload(); anim->preload();
anim->exportBitmaps(VCMIDirs::get().userCachePath() / "extracted", true); anim->exportBitmaps(VCMIDirs::get().userCachePath() / "extracted", true);
@@ -100,8 +100,8 @@ void ConvertOriginalResourceFiles()
if (split_def_files) if (split_def_files)
splitDefFiles(); splitDefFiles();
if (convert_pcx_to_bmp) //if (convert_pcx_to_bmp)
convertPcxToBmp(); // convertPcxToBmp();
} }