mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Removed some usages of std string as resource path
This commit is contained in:
parent
8dfdfffd87
commit
0f88b8969b
@ -59,10 +59,7 @@ AdventureMapWidget::AdventureMapWidget( std::shared_ptr<AdventureMapShortcuts> s
|
|||||||
const JsonNode config(JsonPath::builtin("config/widgets/adventureMap.json"));
|
const JsonNode config(JsonPath::builtin("config/widgets/adventureMap.json"));
|
||||||
|
|
||||||
for(const auto & entry : config["options"]["imagesPlayerColored"].Vector())
|
for(const auto & entry : config["options"]["imagesPlayerColored"].Vector())
|
||||||
{
|
playerColorerImages.push_back(ImagePath::fromJson(entry));
|
||||||
ResourcePath resourceName(entry.String(), EResType::IMAGE);
|
|
||||||
playerColorerImages.push_back(resourceName.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
build(config);
|
build(config);
|
||||||
addUsedEvents(KEYBOARD);
|
addUsedEvents(KEYBOARD);
|
||||||
@ -131,20 +128,20 @@ std::shared_ptr<IImage> AdventureMapWidget::loadImage(const JsonNode & name)
|
|||||||
{
|
{
|
||||||
ImagePath resource = ImagePath::fromJson(name);
|
ImagePath resource = ImagePath::fromJson(name);
|
||||||
|
|
||||||
if(images.count(resource.getName()) == 0)
|
if(images.count(resource) == 0)
|
||||||
images[resource.getName()] = IImage::createFromFile(resource);
|
images[resource] = IImage::createFromFile(resource);
|
||||||
|
|
||||||
return images[resource.getName()];
|
return images[resource];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CAnimation> AdventureMapWidget::loadAnimation(const JsonNode & name)
|
std::shared_ptr<CAnimation> AdventureMapWidget::loadAnimation(const JsonNode & name)
|
||||||
{
|
{
|
||||||
AnimationPath resource = AnimationPath::fromJson(name);
|
AnimationPath resource = AnimationPath::fromJson(name);
|
||||||
|
|
||||||
if(animations.count(resource.getName()) == 0)
|
if(animations.count(resource) == 0)
|
||||||
animations[resource.getName()] = std::make_shared<CAnimation>(resource);
|
animations[resource] = std::make_shared<CAnimation>(resource);
|
||||||
|
|
||||||
return animations[resource.getName()];
|
return animations[resource];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CIntObject> AdventureMapWidget::buildInfobox(const JsonNode & input)
|
std::shared_ptr<CIntObject> AdventureMapWidget::buildInfobox(const JsonNode & input)
|
||||||
|
@ -29,11 +29,11 @@ class AdventureMapWidget : public InterfaceObjectConfigurable
|
|||||||
std::vector<Rect> subwidgetSizes;
|
std::vector<Rect> subwidgetSizes;
|
||||||
|
|
||||||
/// list of images on which player-colored palette will be applied
|
/// list of images on which player-colored palette will be applied
|
||||||
std::vector<std::string> playerColorerImages;
|
std::vector<ImagePath> playerColorerImages;
|
||||||
|
|
||||||
/// list of named images shared between widgets
|
/// list of named images shared between widgets
|
||||||
std::map<std::string, std::shared_ptr<IImage>> images;
|
std::map<ImagePath, std::shared_ptr<IImage>> images;
|
||||||
std::map<std::string, std::shared_ptr<CAnimation>> animations;
|
std::map<AnimationPath, std::shared_ptr<CAnimation>> animations;
|
||||||
|
|
||||||
/// Widgets that require access from adventure map
|
/// Widgets that require access from adventure map
|
||||||
std::shared_ptr<CHeroList> heroList;
|
std::shared_ptr<CHeroList> heroList;
|
||||||
|
@ -69,7 +69,7 @@ bool CAnimation::loadFrame(size_t frame, size_t group)
|
|||||||
// still here? image is missing
|
// still here? image is missing
|
||||||
|
|
||||||
printError(frame, group, "LoadFrame");
|
printError(frame, group, "LoadFrame");
|
||||||
images[group][frame] = std::make_shared<SDLImage>("DEFAULT", EImageBlitMode::ALPHA);
|
images[group][frame] = std::make_shared<SDLImage>(ImagePath::builtin("DEFAULT"), EImageBlitMode::ALPHA);
|
||||||
}
|
}
|
||||||
else //load from separate file
|
else //load from separate file
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@ namespace BitmapHandler
|
|||||||
{
|
{
|
||||||
SDL_Surface * loadH3PCX(ui8 * data, size_t size);
|
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
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fname)
|
SDL_Surface * BitmapHandler::loadBitmapFromDir(const ImagePath & path)
|
||||||
{
|
{
|
||||||
if(!fname.size())
|
if (!CResourceHandler::get()->existsResource(path))
|
||||||
{
|
|
||||||
logGlobal->warn("Call to loadBitmap with void fname!");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
if (!CResourceHandler::get()->existsResource(ResourcePath(path + fname, EResType::IMAGE)))
|
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface * ret=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()))
|
if (isPCX(readFile.first.get()))
|
||||||
{//H3-style PCX
|
{//H3-style PCX
|
||||||
ret = loadH3PCX(readFile.first.get(), readFile.second);
|
ret = loadH3PCX(readFile.first.get(), readFile.second);
|
||||||
if (!ret)
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +141,7 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
|
|||||||
}
|
}
|
||||||
else
|
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());
|
logGlobal->error("Reason: %s", IMG_GetError());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -187,19 +182,29 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
|
|||||||
{
|
{
|
||||||
CSDL_Ext::setDefaultColorKey(ret);
|
CSDL_Ext::setDefaultColorKey(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface * BitmapHandler::loadBitmap(std::string fname)
|
SDL_Surface * BitmapHandler::loadBitmap(const ImagePath & fname)
|
||||||
{
|
{
|
||||||
SDL_Surface * bitmap = nullptr;
|
if(fname.empty())
|
||||||
|
|
||||||
if (!(bitmap = loadBitmapFromDir("DATA/", fname)) &&
|
|
||||||
!(bitmap = loadBitmapFromDir("SPRITES/", fname)))
|
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,12 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../lib/filesystem/ResourcePath.h"
|
||||||
|
|
||||||
struct SDL_Surface;
|
struct SDL_Surface;
|
||||||
|
|
||||||
namespace BitmapHandler
|
namespace BitmapHandler
|
||||||
{
|
{
|
||||||
//Load file from /DATA or /SPRITES
|
//Load file from /DATA or /SPRITES
|
||||||
SDL_Surface * loadBitmap(std::string fname);
|
SDL_Surface * loadBitmap(const ImagePath & fname);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ std::shared_ptr<IImage> IImage::createFromFile( const ImagePath & path )
|
|||||||
|
|
||||||
std::shared_ptr<IImage> IImage::createFromFile( const ImagePath & path, EImageBlitMode mode )
|
std::shared_ptr<IImage> IImage::createFromFile( const ImagePath & path, EImageBlitMode mode )
|
||||||
{
|
{
|
||||||
return std::shared_ptr<IImage>(new SDLImage(path.getName(), mode));
|
return std::shared_ptr<IImage>(new SDLImage(path, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<IImage> IImage::createFromSurface( SDL_Surface * source )
|
std::shared_ptr<IImage> IImage::createFromSurface( SDL_Surface * source )
|
||||||
@ -89,9 +89,7 @@ SDLImage::SDLImage(const JsonNode & conf, EImageBlitMode mode)
|
|||||||
fullSize(0, 0),
|
fullSize(0, 0),
|
||||||
originalPalette(nullptr)
|
originalPalette(nullptr)
|
||||||
{
|
{
|
||||||
std::string filename = conf["file"].String();
|
surf = BitmapHandler::loadBitmap(ImagePath::fromJson(conf["file"]));
|
||||||
|
|
||||||
surf = BitmapHandler::loadBitmap(filename);
|
|
||||||
|
|
||||||
if(surf == nullptr)
|
if(surf == nullptr)
|
||||||
return;
|
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),
|
: surf(nullptr),
|
||||||
margins(0, 0),
|
margins(0, 0),
|
||||||
fullSize(0, 0),
|
fullSize(0, 0),
|
||||||
@ -128,7 +126,7 @@ SDLImage::SDLImage(std::string filename, EImageBlitMode mode)
|
|||||||
|
|
||||||
if(surf == nullptr)
|
if(surf == nullptr)
|
||||||
{
|
{
|
||||||
logGlobal->error("Error: failed to load image %s", filename);
|
logGlobal->error("Error: failed to load image %s", filename.getOriginalName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
//Load image from def file
|
//Load image from def file
|
||||||
SDLImage(CDefFile *data, size_t frame, size_t group=0);
|
SDLImage(CDefFile *data, size_t frame, size_t group=0);
|
||||||
//Load from bitmap file
|
//Load from bitmap file
|
||||||
SDLImage(std::string filename, EImageBlitMode blitMode);
|
SDLImage(const ImagePath & filename, EImageBlitMode blitMode);
|
||||||
|
|
||||||
SDLImage(const JsonNode & conf, EImageBlitMode blitMode);
|
SDLImage(const JsonNode & conf, EImageBlitMode blitMode);
|
||||||
//Create using existing surface, extraRef will increase refcount on SDL_Surface
|
//Create using existing surface, extraRef will increase refcount on SDL_Surface
|
||||||
|
@ -618,7 +618,7 @@ static const std::string QUICK_EXCHANGE_BG = QUICK_EXCHANGE_MOD_PREFIX + "/TRADE
|
|||||||
|
|
||||||
static bool isQuickExchangeLayoutAvailable()
|
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)
|
CExchangeController::CExchangeController(CExchangeWindow * view, ObjectInstanceID hero1, ObjectInstanceID hero2)
|
||||||
|
@ -56,7 +56,7 @@ void MapIdentifiersH3M::loadMapping(const JsonNode & mapping)
|
|||||||
std::string h3mName = boost::to_lower_copy(entryTemplate.second.String());
|
std::string h3mName = boost::to_lower_copy(entryTemplate.second.String());
|
||||||
std::string vcmiName = boost::to_lower_copy(entryTemplate.first);
|
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);
|
logMod->warn("Template animation file %s was not found!", vcmiName);
|
||||||
|
|
||||||
mappingObjectTemplate[h3mName] = vcmiName;
|
mappingObjectTemplate[h3mName] = vcmiName;
|
||||||
|
@ -290,9 +290,8 @@ static ui32 calculateModChecksum(const std::string & modName, ISimpleResourceLoa
|
|||||||
// third - add all detected text files from this mod into checksum
|
// third - add all detected text files from this mod into checksum
|
||||||
auto files = filesystem->getFilteredFiles([](const ResourcePath & resID)
|
auto files = filesystem->getFilteredFiles([](const ResourcePath & resID)
|
||||||
{
|
{
|
||||||
return resID.getType() == EResType::TEXT &&
|
return (resID.getType() == EResType::TEXT || resID.getType() == EResType::JSON) &&
|
||||||
( boost::starts_with(resID.getName(), "DATA") ||
|
( boost::starts_with(resID.getName(), "DATA") || boost::starts_with(resID.getName(), "CONFIG"));
|
||||||
boost::starts_with(resID.getName(), "CONFIG"));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const ResourcePath & file : files)
|
for (const ResourcePath & file : files)
|
||||||
|
@ -169,7 +169,7 @@ DefFile::DefFile(std::string Name):
|
|||||||
qRgba(0, 0, 0, 128), // 50% - shadow body below selection
|
qRgba(0, 0, 0, 128), // 50% - shadow body below selection
|
||||||
qRgba(0, 0, 0, 64) // 75% - shadow border 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<QVector<QRgb>>(256);
|
palette = std::make_unique<QVector<QRgb>>(256);
|
||||||
int it = 0;
|
int it = 0;
|
||||||
@ -656,7 +656,7 @@ Animation::Animation(std::string Name):
|
|||||||
name.erase(dotPos);
|
name.erase(dotPos);
|
||||||
std::transform(name.begin(), name.end(), name.begin(), toupper);
|
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))
|
if(CResourceHandler::get()->existsResource(resource))
|
||||||
defFile = std::make_shared<DefFile>(name);
|
defFile = std::make_shared<DefFile>(name);
|
||||||
|
Loading…
Reference in New Issue
Block a user