diff --git a/client/adventureMap/AdventureMapWidget.cpp b/client/adventureMap/AdventureMapWidget.cpp index ebff69812..aea6e80bd 100644 --- a/client/adventureMap/AdventureMapWidget.cpp +++ b/client/adventureMap/AdventureMapWidget.cpp @@ -59,10 +59,7 @@ AdventureMapWidget::AdventureMapWidget( std::shared_ptr s const JsonNode config(JsonPath::builtin("config/widgets/adventureMap.json")); for(const auto & entry : config["options"]["imagesPlayerColored"].Vector()) - { - ResourcePath resourceName(entry.String(), EResType::IMAGE); - playerColorerImages.push_back(resourceName.getName()); - } + playerColorerImages.push_back(ImagePath::fromJson(entry)); build(config); addUsedEvents(KEYBOARD); @@ -131,20 +128,20 @@ std::shared_ptr AdventureMapWidget::loadImage(const JsonNode & name) { ImagePath resource = ImagePath::fromJson(name); - if(images.count(resource.getName()) == 0) - images[resource.getName()] = IImage::createFromFile(resource); + if(images.count(resource) == 0) + images[resource] = IImage::createFromFile(resource); - return images[resource.getName()]; + return images[resource]; } std::shared_ptr AdventureMapWidget::loadAnimation(const JsonNode & name) { AnimationPath resource = AnimationPath::fromJson(name); - if(animations.count(resource.getName()) == 0) - animations[resource.getName()] = std::make_shared(resource); + if(animations.count(resource) == 0) + animations[resource] = std::make_shared(resource); - return animations[resource.getName()]; + return animations[resource]; } std::shared_ptr AdventureMapWidget::buildInfobox(const JsonNode & input) diff --git a/client/adventureMap/AdventureMapWidget.h b/client/adventureMap/AdventureMapWidget.h index 185440397..fca239ffc 100644 --- a/client/adventureMap/AdventureMapWidget.h +++ b/client/adventureMap/AdventureMapWidget.h @@ -29,11 +29,11 @@ class AdventureMapWidget : public InterfaceObjectConfigurable std::vector subwidgetSizes; /// list of images on which player-colored palette will be applied - std::vector playerColorerImages; + std::vector playerColorerImages; /// list of named images shared between widgets - std::map> images; - std::map> animations; + std::map> images; + std::map> animations; /// Widgets that require access from adventure map std::shared_ptr heroList; diff --git a/client/render/CAnimation.cpp b/client/render/CAnimation.cpp index 947cce37f..a99a9e306 100644 --- a/client/render/CAnimation.cpp +++ b/client/render/CAnimation.cpp @@ -69,7 +69,7 @@ bool CAnimation::loadFrame(size_t frame, size_t group) // still here? image is missing printError(frame, group, "LoadFrame"); - images[group][frame] = std::make_shared("DEFAULT", EImageBlitMode::ALPHA); + images[group][frame] = std::make_shared(ImagePath::builtin("DEFAULT"), EImageBlitMode::ALPHA); } else //load from separate file { diff --git a/client/render/CBitmapHandler.cpp b/client/render/CBitmapHandler.cpp index 9fc4e93ac..626d3d31f 100644 --- a/client/render/CBitmapHandler.cpp +++ b/client/render/CBitmapHandler.cpp @@ -21,7 +21,7 @@ namespace BitmapHandler { SDL_Surface * loadH3PCX(ui8 * data, size_t size); - SDL_Surface * loadBitmapFromDir(std::string path, std::string fname); + SDL_Surface * loadBitmapFromDir(const ImagePath & path); } bool isPCX(const ui8 *header)//check whether file can be PCX according to header @@ -103,28 +103,23 @@ SDL_Surface * BitmapHandler::loadH3PCX(ui8 * pcx, size_t size) return ret; } -SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fname) +SDL_Surface * BitmapHandler::loadBitmapFromDir(const ImagePath & path) { - if(!fname.size()) - { - logGlobal->warn("Call to loadBitmap with void fname!"); - return nullptr; - } - if (!CResourceHandler::get()->existsResource(ResourcePath(path + fname, EResType::IMAGE))) + if (!CResourceHandler::get()->existsResource(path)) { return nullptr; } SDL_Surface * ret=nullptr; - auto readFile = CResourceHandler::get()->load(ResourcePath(path + fname, EResType::IMAGE))->readAll(); + auto readFile = CResourceHandler::get()->load(path)->readAll(); if (isPCX(readFile.first.get())) {//H3-style PCX ret = loadH3PCX(readFile.first.get(), readFile.second); if (!ret) { - logGlobal->error("Failed to open %s as H3 PCX!", fname); + logGlobal->error("Failed to open %s as H3 PCX!", path.getOriginalName()); return nullptr; } } @@ -146,7 +141,7 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna } else { - logGlobal->error("Failed to open %s via SDL_Image", fname); + logGlobal->error("Failed to open %s via SDL_Image", path.getOriginalName()); logGlobal->error("Reason: %s", IMG_GetError()); return nullptr; } @@ -187,19 +182,29 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna { CSDL_Ext::setDefaultColorKey(ret); } - return ret; } -SDL_Surface * BitmapHandler::loadBitmap(std::string fname) +SDL_Surface * BitmapHandler::loadBitmap(const ImagePath & fname) { - SDL_Surface * bitmap = nullptr; - - if (!(bitmap = loadBitmapFromDir("DATA/", fname)) && - !(bitmap = loadBitmapFromDir("SPRITES/", fname))) + if(fname.empty()) { - logGlobal->error("Error: Failed to find file %s", fname); + logGlobal->warn("Call to loadBitmap with void fname!"); + return nullptr; } - return bitmap; + SDL_Surface * bitmap = loadBitmapFromDir(fname); + if (bitmap != nullptr) + return bitmap; + + SDL_Surface * bitmapData = loadBitmapFromDir(fname.addPrefix("DATA/")); + if (bitmapData != nullptr) + return bitmapData; + + SDL_Surface * bitmapSprites = loadBitmapFromDir(fname.addPrefix("SPRITES/")); + if (bitmapSprites != nullptr) + return bitmapSprites; + + logGlobal->error("Error: Failed to find file %s", fname.getOriginalName()); + return nullptr; } diff --git a/client/render/CBitmapHandler.h b/client/render/CBitmapHandler.h index b36156211..3bd8a7e82 100644 --- a/client/render/CBitmapHandler.h +++ b/client/render/CBitmapHandler.h @@ -9,10 +9,12 @@ */ #pragma once +#include "../../lib/filesystem/ResourcePath.h" + struct SDL_Surface; namespace BitmapHandler { //Load file from /DATA or /SPRITES - SDL_Surface * loadBitmap(std::string fname); + SDL_Surface * loadBitmap(const ImagePath & fname); } diff --git a/client/renderSDL/SDLImage.cpp b/client/renderSDL/SDLImage.cpp index 0a53abb23..dbbe7dd6d 100644 --- a/client/renderSDL/SDLImage.cpp +++ b/client/renderSDL/SDLImage.cpp @@ -31,7 +31,7 @@ std::shared_ptr IImage::createFromFile( const ImagePath & path ) std::shared_ptr IImage::createFromFile( const ImagePath & path, EImageBlitMode mode ) { - return std::shared_ptr(new SDLImage(path.getName(), mode)); + return std::shared_ptr(new SDLImage(path, mode)); } std::shared_ptr IImage::createFromSurface( SDL_Surface * source ) @@ -89,9 +89,7 @@ SDLImage::SDLImage(const JsonNode & conf, EImageBlitMode mode) fullSize(0, 0), originalPalette(nullptr) { - std::string filename = conf["file"].String(); - - surf = BitmapHandler::loadBitmap(filename); + surf = BitmapHandler::loadBitmap(ImagePath::fromJson(conf["file"])); if(surf == nullptr) return; @@ -118,7 +116,7 @@ SDLImage::SDLImage(const JsonNode & conf, EImageBlitMode mode) } } -SDLImage::SDLImage(std::string filename, EImageBlitMode mode) +SDLImage::SDLImage(const ImagePath & filename, EImageBlitMode mode) : surf(nullptr), margins(0, 0), fullSize(0, 0), @@ -128,7 +126,7 @@ SDLImage::SDLImage(std::string filename, EImageBlitMode mode) if(surf == nullptr) { - logGlobal->error("Error: failed to load image %s", filename); + logGlobal->error("Error: failed to load image %s", filename.getOriginalName()); return; } else diff --git a/client/renderSDL/SDLImage.h b/client/renderSDL/SDLImage.h index 74a28e003..10aecd70d 100644 --- a/client/renderSDL/SDLImage.h +++ b/client/renderSDL/SDLImage.h @@ -43,7 +43,7 @@ public: //Load image from def file SDLImage(CDefFile *data, size_t frame, size_t group=0); //Load from bitmap file - SDLImage(std::string filename, EImageBlitMode blitMode); + SDLImage(const ImagePath & filename, EImageBlitMode blitMode); SDLImage(const JsonNode & conf, EImageBlitMode blitMode); //Create using existing surface, extraRef will increase refcount on SDL_Surface diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index aae29023e..a83ec3640 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -618,7 +618,7 @@ static const std::string QUICK_EXCHANGE_BG = QUICK_EXCHANGE_MOD_PREFIX + "/TRADE static bool isQuickExchangeLayoutAvailable() { - return CResourceHandler::get()->existsResource(ResourcePath(std::string("SPRITES/") + QUICK_EXCHANGE_BG, EResType::IMAGE)); + return CResourceHandler::get()->existsResource(ImagePath::builtin("SPRITES/" + QUICK_EXCHANGE_BG)); } CExchangeController::CExchangeController(CExchangeWindow * view, ObjectInstanceID hero1, ObjectInstanceID hero2) diff --git a/lib/mapping/MapIdentifiersH3M.cpp b/lib/mapping/MapIdentifiersH3M.cpp index 2a50df036..70789a001 100644 --- a/lib/mapping/MapIdentifiersH3M.cpp +++ b/lib/mapping/MapIdentifiersH3M.cpp @@ -56,7 +56,7 @@ void MapIdentifiersH3M::loadMapping(const JsonNode & mapping) std::string h3mName = boost::to_lower_copy(entryTemplate.second.String()); std::string vcmiName = boost::to_lower_copy(entryTemplate.first); - if (!CResourceHandler::get()->existsResource(ResourcePath( "SPRITES/" + vcmiName, EResType::ANIMATION))) + if (!CResourceHandler::get()->existsResource(AnimationPath::builtin("SPRITES/" + vcmiName))) logMod->warn("Template animation file %s was not found!", vcmiName); mappingObjectTemplate[h3mName] = vcmiName; diff --git a/lib/modding/CModHandler.cpp b/lib/modding/CModHandler.cpp index ac1a7ad93..78fa70a5c 100644 --- a/lib/modding/CModHandler.cpp +++ b/lib/modding/CModHandler.cpp @@ -290,9 +290,8 @@ static ui32 calculateModChecksum(const std::string & modName, ISimpleResourceLoa // third - add all detected text files from this mod into checksum auto files = filesystem->getFilteredFiles([](const ResourcePath & resID) { - return resID.getType() == EResType::TEXT && - ( boost::starts_with(resID.getName(), "DATA") || - boost::starts_with(resID.getName(), "CONFIG")); + return (resID.getType() == EResType::TEXT || resID.getType() == EResType::JSON) && + ( boost::starts_with(resID.getName(), "DATA") || boost::starts_with(resID.getName(), "CONFIG")); }); for (const ResourcePath & file : files) diff --git a/mapeditor/Animation.cpp b/mapeditor/Animation.cpp index 412810328..7bced089f 100644 --- a/mapeditor/Animation.cpp +++ b/mapeditor/Animation.cpp @@ -169,7 +169,7 @@ DefFile::DefFile(std::string Name): qRgba(0, 0, 0, 128), // 50% - shadow body below selection qRgba(0, 0, 0, 64) // 75% - shadow border below selection }; - data = animationCache.getCachedFile(ResourcePath(std::string("SPRITES/") + Name, EResType::ANIMATION)); + data = animationCache.getCachedFile(AnimationPath::builtin("SPRITES/" + Name)); palette = std::make_unique>(256); int it = 0; @@ -656,7 +656,7 @@ Animation::Animation(std::string Name): name.erase(dotPos); std::transform(name.begin(), name.end(), name.begin(), toupper); - ResourcePath resource(std::string("SPRITES/") + name, EResType::ANIMATION); + auto resource = AnimationPath::builtin("SPRITES/" + name); if(CResourceHandler::get()->existsResource(resource)) defFile = std::make_shared(name);