mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Animation.cpp fixes after review
This commit is contained in:
parent
221a9e14b9
commit
f0b66b6192
@ -21,6 +21,8 @@
|
||||
#include "../lib/JsonNode.h"
|
||||
#include "../lib/CRandomGenerator.h"
|
||||
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
class SDLImageLoader;
|
||||
|
||||
typedef std::map <size_t, std::vector <JsonNode> > source_map;
|
||||
@ -95,7 +97,7 @@ public:
|
||||
void draw(SDL_Surface * where, int posX=0, int posY=0, Rect *src=nullptr, ui8 alpha=255) const override;
|
||||
void draw(SDL_Surface * where, SDL_Rect * dest, SDL_Rect * src, ui8 alpha=255) const override;
|
||||
std::shared_ptr<IImage> scaleFast(float scale) const override;
|
||||
void exportBitmap(const boost::filesystem::path & path) const override;
|
||||
void exportBitmap(const bfs::path & path) const override;
|
||||
void playerColored(PlayerColor player) override;
|
||||
void setFlagColor(PlayerColor player) override;
|
||||
int width() const override;
|
||||
@ -714,7 +716,7 @@ std::shared_ptr<IImage> SDLImage::scaleFast(float scale) const
|
||||
return std::shared_ptr<IImage>(ret);
|
||||
}
|
||||
|
||||
void SDLImage::exportBitmap(const boost::filesystem::path& path) const
|
||||
void SDLImage::exportBitmap(const bfs::path & path) const
|
||||
{
|
||||
SDL_SaveBMP(surf, path.string().c_str());
|
||||
}
|
||||
@ -951,7 +953,7 @@ void CAnimation::initFromJson(const JsonNode & config)
|
||||
}
|
||||
}
|
||||
|
||||
void CAnimation::exportBitmaps(const boost::filesystem::path& path, bool prependResourceName) const
|
||||
void CAnimation::exportBitmaps(const bfs::path & path, bool prependResourceName) const
|
||||
{
|
||||
if(images.empty())
|
||||
{
|
||||
@ -959,8 +961,8 @@ void CAnimation::exportBitmaps(const boost::filesystem::path& path, bool prepend
|
||||
return;
|
||||
}
|
||||
|
||||
boost::filesystem::path actualPath = path / "Sprites" / name;
|
||||
boost::filesystem::create_directories(actualPath);
|
||||
bfs::path actualPath = path / "Sprites" / name;
|
||||
bfs::create_directories(actualPath);
|
||||
|
||||
size_t counter = 0;
|
||||
|
||||
@ -974,9 +976,9 @@ void CAnimation::exportBitmaps(const boost::filesystem::path& path, bool prepend
|
||||
const auto img = imagePair.second;
|
||||
|
||||
boost::format fmt("%d_%d.bmp");
|
||||
fmt% group% frame;
|
||||
fmt % group % frame;
|
||||
std::string fileName = fmt.str();
|
||||
if (prependResourceName)
|
||||
if(prependResourceName)
|
||||
fileName = name + "_" + fileName;
|
||||
|
||||
img->exportBitmap(actualPath / fileName);
|
||||
|
@ -91,13 +91,13 @@ void CArchiveLoader::initLODArchive(const std::string &mountPoint, CFileInputStr
|
||||
boost::to_upper(fName);
|
||||
|
||||
if(fName.find(".PCX") != std::string::npos)
|
||||
extractToFolder("Images", mountPoint, entry);
|
||||
extractToFolder("IMAGES", mountPoint, entry);
|
||||
else if ((fName.find(".DEF") != std::string::npos ) || (fName.find(".MSK") != std::string::npos) || (fName.find(".FNT") != std::string::npos) || (fName.find(".PAL") != std::string::npos))
|
||||
extractToFolder("Sprites", mountPoint, entry);
|
||||
extractToFolder("SPRITES", mountPoint, entry);
|
||||
else if ((fName.find(".h3c") != std::string::npos))
|
||||
extractToFolder("Sprites", mountPoint, entry);
|
||||
extractToFolder("SPRITES", mountPoint, entry);
|
||||
else
|
||||
extractToFolder("Misc", mountPoint, entry);
|
||||
extractToFolder("MISC", mountPoint, entry);
|
||||
|
||||
fileStream.seek(currentPosition); // restore filestream position
|
||||
}
|
||||
@ -138,7 +138,7 @@ void CArchiveLoader::initVIDArchive(const std::string &mountPoint, CFileInputStr
|
||||
entry.second.fullSize = *it - entry.second.offset;
|
||||
|
||||
if(extractArchives)
|
||||
extractToFolder("Video", fileStream, entry.second);
|
||||
extractToFolder("VIDEO", fileStream, entry.second);
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ void CArchiveLoader::initSNDArchive(const std::string &mountPoint, CFileInputStr
|
||||
entries[ResourceID(mountPoint + entry.name)] = entry;
|
||||
|
||||
if(extractArchives)
|
||||
extractToFolder("Sound", fileStream, entry);
|
||||
extractToFolder("SOUND", fileStream, entry);
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ std::unordered_set<ResourceID> CArchiveLoader::getFilteredFiles(std::function<bo
|
||||
return foundID;
|
||||
}
|
||||
|
||||
void CArchiveLoader::extractToFolder( std::string outputSubFolder, CFileInputStream& fileStream, ArchiveEntry entry)
|
||||
void CArchiveLoader::extractToFolder(std::string outputSubFolder, CFileInputStream & fileStream, ArchiveEntry entry)
|
||||
{
|
||||
si64 currentPosition = fileStream.tell(); // save filestream position
|
||||
|
||||
@ -230,7 +230,7 @@ void CArchiveLoader::extractToFolder( std::string outputSubFolder, CFileInputStr
|
||||
fileStream.seek(currentPosition); // restore filestream position
|
||||
}
|
||||
|
||||
void CArchiveLoader::extractToFolder( std::string outputSubFolder, const std::string& mountPoint, ArchiveEntry entry)
|
||||
void CArchiveLoader::extractToFolder(std::string outputSubFolder, const std::string & mountPoint, ArchiveEntry entry)
|
||||
{
|
||||
|
||||
std::unique_ptr<CInputStream> inputStream = load(ResourceID(mountPoint + entry.name));
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "../lib/VCMIDirs.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
typedef std::map<size_t, std::vector<JsonNode>> source_map;
|
||||
@ -689,32 +690,32 @@ std::shared_ptr<QImage> Animation::getImage(size_t frame, size_t group, bool ver
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Animation::exportBitmaps(const bfs::path& path, bool prependResourceName) const
|
||||
void Animation::exportBitmaps(const bfs::path & path, bool prependResourceName) const
|
||||
{
|
||||
if (images.empty())
|
||||
if(images.empty())
|
||||
{
|
||||
logGlobal->error("Nothing to export, animation is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
boost::filesystem::path actualPath = path / "Sprites" / name;
|
||||
boost::filesystem::create_directories(actualPath);
|
||||
bfs::path actualPath = path / "SPRITES" / name;
|
||||
bfs::create_directories(actualPath);
|
||||
|
||||
size_t counter = 0;
|
||||
|
||||
for (const auto& groupPair : images)
|
||||
for(const auto& groupPair : images)
|
||||
{
|
||||
size_t group = groupPair.first;
|
||||
|
||||
for (const auto& imagePair : groupPair.second)
|
||||
for(const auto& imagePair : groupPair.second)
|
||||
{
|
||||
size_t frame = imagePair.first;
|
||||
const auto img = imagePair.second;
|
||||
|
||||
boost::format fmt("%d_%d.png");
|
||||
fmt% group% frame;
|
||||
fmt % group % frame;
|
||||
std::string fileName = fmt.str();
|
||||
if (prependResourceName)
|
||||
if(prependResourceName)
|
||||
fileName = name + "_" + fileName;
|
||||
|
||||
auto s = img->size();
|
||||
|
Loading…
Reference in New Issue
Block a user