1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Support for overriding victory/defeat conditions from h3m map or

campaign:
- new file MapFormatJson that implements small subset of Json map
format, as described on wiki
- vcmi will read overrides from file config/mapOverrides.json (currently
empty)
- Json writer for logical expressions

TODO: write data for map overrides
This commit is contained in:
Ivan Savenko
2013-12-30 23:09:58 +00:00
parent a03d01bd3f
commit 7e02f6b670
13 changed files with 406 additions and 18 deletions

View File

@@ -8,30 +8,47 @@
#include "CMap.h"
#include "MapFormatH3M.h"
#include "MapFormatJson.h"
std::unique_ptr<CMap> CMapService::loadMap(const std::string & name)
{
auto stream = getStreamFromFS(name);
return getMapLoader(stream)->loadMap();
std::unique_ptr<CMap> map(getMapLoader(stream)->loadMap());
std::unique_ptr<CMapHeader> header(map.get());
getMapPatcher(name)->patchMapHeader(header);
header.release();
return std::move(map);
}
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const std::string & name)
{
auto stream = getStreamFromFS(name);
return getMapLoader(stream)->loadMapHeader();
std::unique_ptr<CMapHeader> header = getMapLoader(stream)->loadMapHeader();
getMapPatcher(name)->patchMapHeader(header);
return std::move(header);
}
std::unique_ptr<CMap> CMapService::loadMap(const ui8 * buffer, int size)
std::unique_ptr<CMap> CMapService::loadMap(const ui8 * buffer, int size, const std::string & name)
{
auto stream = getStreamFromMem(buffer, size);
return getMapLoader(stream)->loadMap();
std::unique_ptr<CMap> map(getMapLoader(stream)->loadMap());
std::unique_ptr<CMapHeader> header(map.get());
getMapPatcher(name)->patchMapHeader(header);
header.release();
return std::move(map);
}
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ui8 * buffer, int size)
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ui8 * buffer, int size, const std::string & name)
{
auto stream = getStreamFromMem(buffer, size);
return getMapLoader(stream)->loadMapHeader();
std::unique_ptr<CMapHeader> header = getMapLoader(stream)->loadMapHeader();
getMapPatcher(name)->patchMapHeader(header);
return std::move(header);
}
std::unique_ptr<CInputStream> CMapService::getStreamFromFS(const std::string & name)
@@ -68,3 +85,11 @@ std::unique_ptr<IMapLoader> CMapService::getMapLoader(std::unique_ptr<CInputStre
throw std::runtime_error("Unknown map format");
}
}
std::unique_ptr<IMapPatcher> CMapService::getMapPatcher(std::string scenarioName)
{
boost::to_lower(scenarioName);
logGlobal->debugStream() << "Request to patch map " << scenarioName;
JsonNode node = JsonUtils::assembleFromFiles("config/mapOverrides.json");
return std::unique_ptr<IMapPatcher>(new CMapLoaderJson(node[scenarioName]));
}