diff --git a/client/CMT.cpp b/client/CMT.cpp index 649ae3c98..cbb98bd75 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -59,7 +59,6 @@ #include "../lib/serializer/Connection.h" #include "CServerHandler.h" #include "gui/NotificationHandler.h" -#include "resourceExtractor/ResourceConverter.h" #include @@ -466,7 +465,7 @@ int main(int argc, char * argv[]) CCS->curh = new CCursorHandler(); graphics = new Graphics(); // should be before curh->init() - ConvertOriginalResourceFiles(); + // ConvertOriginalResourceFiles(); CCS->curh->initCursor(); logGlobal->info("Screen handler: %d ms", pomtime.getDiff()); diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index faa155529..07fd813ae 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -54,8 +54,6 @@ set(client_SRCS lobby/OptionsTab.cpp lobby/RandomMapTab.cpp lobby/SelectionTab.cpp - - resourceExtractor/ResourceConverter.cpp CBitmapHandler.cpp CreatureCostBox.cpp @@ -130,8 +128,6 @@ set(client_HEADERS lobby/OptionsTab.h lobby/RandomMapTab.h lobby/SelectionTab.h - - resourceExtractor/ResourceConverter.h CBitmapHandler.h CreatureCostBox.h diff --git a/mapeditor/Animation.cpp b/mapeditor/Animation.cpp index ec844d3d5..8ff4bbde9 100644 --- a/mapeditor/Animation.cpp +++ b/mapeditor/Animation.cpp @@ -19,10 +19,23 @@ #include "../lib/filesystem/ISimpleResourceLoader.h" #include "../lib/JsonNode.h" #include "../lib/CRandomGenerator.h" +#include "../lib/VCMIDirs.h" +#include +namespace bfs = boost::filesystem; typedef std::map> 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 /// After loading will store general info (palette and frame offsets) and pointer to file itself class DefFile @@ -686,6 +699,44 @@ std::shared_ptr Animation::getImage(size_t frame, size_t group, bool ver 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() { for (auto & elem : source) diff --git a/mapeditor/Animation.h b/mapeditor/Animation.h index 8ffe9203a..744caebc2 100644 --- a/mapeditor/Animation.h +++ b/mapeditor/Animation.h @@ -83,6 +83,8 @@ public: void load (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) size_t size(size_t group = 0) const; diff --git a/mapeditor/CMakeLists.txt b/mapeditor/CMakeLists.txt index d72c32855..6914d4785 100644 --- a/mapeditor/CMakeLists.txt +++ b/mapeditor/CMakeLists.txt @@ -24,6 +24,7 @@ set(editor_SRCS inspector/messagewidget.cpp inspector/rewardswidget.cpp inspector/questwidget.cpp + resourceExtractor/ResourceConverter.cpp ) set(editor_HEADERS @@ -51,6 +52,7 @@ set(editor_HEADERS inspector/messagewidget.h inspector/rewardswidget.h inspector/questwidget.h + resourceExtractor/ResourceConverter.h ) set(editor_FORMS diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index 91b0798fd..6efd10315 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -38,6 +38,7 @@ #include "mapsettings.h" #include "playersettings.h" #include "validator.h" +#include "resourceExtractor/ResourceConverter.h" static CBasicLogConfigurator * logConfig; @@ -110,6 +111,9 @@ MainWindow::MainWindow(QWidget *parent) : //init preinitDLL(::console); + + //ConvertOriginalResourceFiles(); + settings.init(); // Initialize logging based on settings @@ -139,6 +143,7 @@ MainWindow::MainWindow(QWidget *parent) : graphics = new Graphics(); // should be before curh->init() graphics->load();//must be after Content loading but should be in main thread + ConvertOriginalResourceFiles(); ui->mapView->setScene(controller.scene(0)); ui->mapView->setController(&controller); diff --git a/client/resourceExtractor/ResourceConverter.cpp b/mapeditor/resourceExtractor/ResourceConverter.cpp similarity index 54% rename from client/resourceExtractor/ResourceConverter.cpp rename to mapeditor/resourceExtractor/ResourceConverter.cpp index 15bc8152b..f1051e5cc 100644 --- a/client/resourceExtractor/ResourceConverter.cpp +++ b/mapeditor/resourceExtractor/ResourceConverter.cpp @@ -6,9 +6,9 @@ #include "../lib/VCMIDirs.h" #include "../lib/filesystem/Filesystem.h" -#include "SDL.h" -#include "./gui/CAnimation.h" -#include "CBitmapHandler.h" +//#include "SDL.h" +#include "Animation.h" +//#include "CBitmapHandler.h" #include "boost/filesystem/path.hpp" #include "boost/locale.hpp" @@ -16,51 +16,51 @@ namespace bfs = boost::filesystem; 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 delete_source_files = 1; // delete source files or leave a copy in place. +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 = 0; // delete source files or leave a copy in place. // converts all pcx files into bmp (H3 saves images as .pcx) -void convertPcxToBmp() -{ - bfs::path extractedPath = VCMIDirs::get().userDataPath() / "extracted"; - bfs::path imagesPath = extractedPath / "Images"; - - bfs::directory_iterator end_iter; - - for ( bfs::directory_iterator dir_itr(imagesPath); dir_itr != end_iter; ++dir_itr ) - { - try - { - if ( bfs::is_regular_file( dir_itr->status() ) ) - { - std::string filename = dir_itr->path().filename().string(); - filename = boost::locale::to_lower(filename); - - if(filename.find(".pcx") != std::string::npos) - { - SDL_Surface *bitmap; - - bitmap = BitmapHandler::loadBitmap(filename); - - if(delete_source_files) - bfs::remove(imagesPath / filename); - - bfs::path outFilePath = imagesPath / filename; - outFilePath.replace_extension(".bmp"); - SDL_SaveBMP(bitmap, outFilePath.string().c_str()); - } - } - else - { - logGlobal->info(dir_itr->path().filename().string() + " [other]\n"); - } - } - catch ( const std::exception & ex ) - { - logGlobal->info(dir_itr->path().filename().string() + " " + ex.what() + "\n"); - } - } -} +//void convertPcxToBmp() +//{ +// bfs::path extractedPath = VCMIDirs::get().userDataPath() / "extracted"; +// bfs::path imagesPath = extractedPath / "Images"; +// +// bfs::directory_iterator end_iter; +// +// for ( bfs::directory_iterator dir_itr(imagesPath); dir_itr != end_iter; ++dir_itr ) +// { +// try +// { +// if ( bfs::is_regular_file( dir_itr->status() ) ) +// { +// std::string filename = dir_itr->path().filename().string(); +// filename = boost::locale::to_lower(filename); +// +// if(filename.find(".pcx") != std::string::npos) +// { +// SDL_Surface *bitmap; +// +// bitmap = BitmapHandler::loadBitmap(filename); +// +// if(delete_source_files) +// bfs::remove(imagesPath / filename); +// +// bfs::path outFilePath = imagesPath / filename; +// outFilePath.replace_extension(".bmp"); +// SDL_SaveBMP(bitmap, outFilePath.string().c_str()); +// } +// } +// else +// { +// logGlobal->info(dir_itr->path().filename().string() + " [other]\n"); +// } +// } +// catch ( const std::exception & ex ) +// { +// logGlobal->info(dir_itr->path().filename().string() + " " + ex.what() + "\n"); +// } +// } +//} // splits a def file into individual parts 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))) { std::string URI = fileName; - std::unique_ptr anim = make_unique(URI); + std::unique_ptr anim = make_unique(URI); anim->preload(); anim->exportBitmaps(VCMIDirs::get().userCachePath() / "extracted", true); @@ -100,8 +100,8 @@ void ConvertOriginalResourceFiles() if (split_def_files) splitDefFiles(); - if (convert_pcx_to_bmp) - convertPcxToBmp(); + //if (convert_pcx_to_bmp) + // convertPcxToBmp(); } diff --git a/client/resourceExtractor/ResourceConverter.h b/mapeditor/resourceExtractor/ResourceConverter.h similarity index 100% rename from client/resourceExtractor/ResourceConverter.h rename to mapeditor/resourceExtractor/ResourceConverter.h