mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-13 13:18:43 +02:00
Possibility to load maps from any folder
This commit is contained in:
parent
e43f26de59
commit
480b58c80a
@ -165,3 +165,17 @@ void CFilesystemList::addLoader(ISimpleResourceLoader * loader, bool writeable)
|
||||
if (writeable)
|
||||
writeableLoaders.insert(loader);
|
||||
}
|
||||
|
||||
bool CFilesystemList::removeLoader(ISimpleResourceLoader * loader)
|
||||
{
|
||||
for(auto loaderIterator = loaders.begin(); loaderIterator != loaders.end(); ++loaderIterator)
|
||||
{
|
||||
if(loaderIterator->get() == loader)
|
||||
{
|
||||
loaders.erase(loaderIterator);
|
||||
writeableLoaders.erase(loader);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -84,4 +84,14 @@ public:
|
||||
* @param writeable - resource shall be treated as writeable
|
||||
*/
|
||||
void addLoader(ISimpleResourceLoader * loader, bool writeable);
|
||||
|
||||
/**
|
||||
* Removes loader from the loader list
|
||||
* Take care about memory deallocation
|
||||
*
|
||||
* @param loader The simple resource loader object to remove
|
||||
*
|
||||
* @return if loader was successfully removed
|
||||
*/
|
||||
bool removeLoader(ISimpleResourceLoader * loader);
|
||||
};
|
||||
|
@ -225,6 +225,21 @@ void CResourceHandler::addFilesystem(const std::string & parent, const std::stri
|
||||
knownLoaders[identifier] = loader;
|
||||
}
|
||||
|
||||
bool CResourceHandler::removeFilesystem(const std::string & parent, const std::string & identifier)
|
||||
{
|
||||
if(knownLoaders.count(identifier) == 0)
|
||||
return false;
|
||||
|
||||
if(knownLoaders.count(parent) == 0)
|
||||
return false;
|
||||
|
||||
auto list = dynamic_cast<CFilesystemList *>(knownLoaders.at(parent));
|
||||
assert(list);
|
||||
list->removeLoader(knownLoaders[identifier]);
|
||||
knownLoaders.erase(identifier);
|
||||
return true;
|
||||
}
|
||||
|
||||
ISimpleResourceLoader * CResourceHandler::createFileSystem(const std::string & prefix, const JsonNode &fsConfig)
|
||||
{
|
||||
CFilesystemGenerator generator(prefix);
|
||||
|
@ -87,6 +87,14 @@ public:
|
||||
* @param loader resource loader to add
|
||||
*/
|
||||
static void addFilesystem(const std::string & parent, const std::string & identifier, ISimpleResourceLoader * loader);
|
||||
|
||||
/**
|
||||
* @brief removeFilesystem removes reviously added filesyste, from global resouce holder
|
||||
* @param parent parent loader containing filesystem
|
||||
* @param identifier name of this loader
|
||||
* @return if filesystem was successfully removed
|
||||
*/
|
||||
static bool removeFilesystem(const std::string & parent, const std::string & identifier);
|
||||
|
||||
/**
|
||||
* @brief createModFileSystem - creates filesystem out of config file
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "../lib/mapping/CMapEditManager.h"
|
||||
#include "../lib/Terrain.h"
|
||||
#include "../lib/mapObjects/CObjectClassesHandler.h"
|
||||
#include "../lib/filesystem/CFilesystemLoader.h"
|
||||
|
||||
|
||||
#include "CGameInfo.h"
|
||||
@ -214,14 +215,16 @@ void MainWindow::on_actionOpen_triggered()
|
||||
QFileInfo fi(filenameSelect);
|
||||
std::string fname = fi.fileName().toStdString();
|
||||
std::string fdir = fi.dir().path().toStdString();
|
||||
ResourceID resId("MAPS/" + fname, EResType::MAP);
|
||||
//ResourceID resId("MAPS/SomeMap.vmap", EResType::MAP);
|
||||
|
||||
if(!CResourceHandler::get()->existsResource(resId))
|
||||
{
|
||||
QMessageBox::information(this, "Failed to open map", "Only map folder is supported");
|
||||
return;
|
||||
}
|
||||
ResourceID resId("MAPEDITOR/" + fname, EResType::MAP);
|
||||
|
||||
//addFilesystem takes care about memory deallocation if case of failure, no memory leak here
|
||||
auto * mapEditorFilesystem = new CFilesystemLoader("MAPEDITOR/", fdir, 0);
|
||||
CResourceHandler::removeFilesystem("local", "mapEditor");
|
||||
CResourceHandler::addFilesystem("local", "mapEditor", mapEditorFilesystem);
|
||||
|
||||
if(!CResourceHandler::get("mapEditor")->existsResource(resId))
|
||||
QMessageBox::warning(this, "Failed to open map", "Cannot open map from this folder");
|
||||
|
||||
CMapService mapService;
|
||||
try
|
||||
|
Loading…
x
Reference in New Issue
Block a user