1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

switch CMapService API to ResourceID

This commit is contained in:
AlexVinS 2017-06-04 22:42:48 +03:00
parent e25ed4f358
commit c82afe7156
12 changed files with 22 additions and 29 deletions

View File

@ -16,7 +16,6 @@
#include "StartInfo.h"
#include "NetPacks.h"
#include "registerTypes/RegisterTypes.h"
#include "mapping/CMapInfo.h"
#include "BattleInfo.h"
#include "JsonNode.h"
#include "filesystem/Filesystem.h"
@ -840,7 +839,8 @@ void CGameState::initNewGame(bool allowSavingRandomMap)
else
{
logGlobal->infoStream() << "Open map file: " << scenarioOps->mapname;
map = CMapService::loadMap(scenarioOps->mapname).release();
const ResourceID mapURI(scenarioOps->mapname, EResType::MAP);
map = CMapService::loadMap(mapURI).release();
}
}

View File

@ -1,6 +1,7 @@
#include "StdInc.h"
#include "CMapInfo.h"
#include "../filesystem/ResourceID.h"
#include "../StartInfo.h"
#include "../GameConstants.h"
#include "CMapService.h"
@ -58,7 +59,7 @@ CMapInfo::~CMapInfo()
void CMapInfo::mapInit(const std::string & fname)
{
fileURI = fname;
mapHeader = CMapService::loadMapHeader(fname);
mapHeader = CMapService::loadMapHeader(ResourceID(fname, EResType::MAP));
countPlayers();
}
@ -81,3 +82,4 @@ CMapInfo & CMapInfo::operator=(CMapInfo &&tmp)
return *this;
}
#undef STEAL

View File

@ -13,24 +13,16 @@
#include "MapFormatJson.h"
std::unique_ptr<CMap> CMapService::loadMap(const std::string & name)
std::unique_ptr<CMap> CMapService::loadMap(const ResourceID & name)
{
auto stream = getStreamFromFS(name);
std::unique_ptr<CMap> map(getMapLoader(stream)->loadMap());
std::unique_ptr<CMapHeader> header(map.get());
getMapPatcher(name)->patchMapHeader(header);
header.release();
return map;
return getMapLoader(stream)->loadMap();
}
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const std::string & name)
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ResourceID & name)
{
auto stream = getStreamFromFS(name);
std::unique_ptr<CMapHeader> header = getMapLoader(stream)->loadMapHeader();
getMapPatcher(name)->patchMapHeader(header);
return header;
return getMapLoader(stream)->loadMapHeader();
}
std::unique_ptr<CMap> CMapService::loadMap(const ui8 * buffer, int size, const std::string & name)
@ -39,6 +31,7 @@ std::unique_ptr<CMap> CMapService::loadMap(const ui8 * buffer, int size, const s
std::unique_ptr<CMap> map(getMapLoader(stream)->loadMap());
std::unique_ptr<CMapHeader> header(map.get());
//might be original campaign and require patch
getMapPatcher(name)->patchMapHeader(header);
header.release();
@ -49,6 +42,8 @@ std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ui8 * buffer, int s
{
auto stream = getStreamFromMem(buffer, size);
std::unique_ptr<CMapHeader> header = getMapLoader(stream)->loadMapHeader();
//might be original campaign and require patch
getMapPatcher(name)->patchMapHeader(header);
return header;
}
@ -70,9 +65,9 @@ void CMapService::saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::
}
}
std::unique_ptr<CInputStream> CMapService::getStreamFromFS(const std::string & name)
std::unique_ptr<CInputStream> CMapService::getStreamFromFS(const ResourceID & name)
{
return CResourceHandler::get()->load(ResourceID(name, EResType::MAP));
return CResourceHandler::get()->load(name);
}
std::unique_ptr<CInputStream> CMapService::getStreamFromMem(const ui8 * buffer, int size)

View File

@ -11,6 +11,8 @@
#pragma once
class ResourceID;
class CMap;
class CMapHeader;
class CInputStream;
@ -31,7 +33,7 @@ public:
* @param name the name of the map
* @return a unique ptr to the loaded map class
*/
static std::unique_ptr<CMap> loadMap(const std::string & name);
static std::unique_ptr<CMap> loadMap(const ResourceID & name);
/**
* Loads the VCMI/H3 map header specified by the name.
@ -39,7 +41,7 @@ public:
* @param name the name of the map
* @return a unique ptr to the loaded map header class
*/
static std::unique_ptr<CMapHeader> loadMapHeader(const std::string & name);
static std::unique_ptr<CMapHeader> loadMapHeader(const ResourceID & name);
/**
* Loads the VCMI/H3 map file from a buffer. This method is temporarily
@ -77,7 +79,7 @@ private:
* @param name the name of the map
* @return a unique ptr to the input stream class
*/
static std::unique_ptr<CInputStream> getStreamFromFS(const std::string & name);
static std::unique_ptr<CInputStream> getStreamFromFS(const ResourceID & name);
/**
* Gets a map input stream from a buffer.

View File

@ -1,7 +1,6 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "../mapping/CMapInfo.h"
#include "../StartInfo.h"
#include "../CGameState.h"
#include "../mapping/CMap.h"

View File

@ -1,7 +1,6 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "../mapping/CMapInfo.h"
#include "../StartInfo.h"
#include "../CStack.h"
#include "../BattleInfo.h"

View File

@ -1,7 +1,6 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "../mapping/CMapInfo.h"
#include "../StartInfo.h"
#include "../CGameState.h"
#include "../mapping/CMap.h"

View File

@ -1,7 +1,6 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "../mapping/CMapInfo.h"
#include "../StartInfo.h"
#include "../CStack.h"
#include "../BattleInfo.h"

View File

@ -1,7 +1,6 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "../mapping/CMapInfo.h"
#include "../StartInfo.h"
#include "../CGameState.h"
#include "../mapping/CMap.h"

View File

@ -1,7 +1,6 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "../mapping/CMapInfo.h"
#include "../StartInfo.h"
#include "../CGameState.h"
#include "../mapping/CMap.h"

View File

@ -74,7 +74,6 @@ public:
std::list<CPackForSelectionScreen*> toAnnounce;
boost::recursive_mutex mx;
//std::vector<CMapInfo> maps;
TAcceptor *acceptor;
TSocket *upcomingConnection;

View File

@ -115,9 +115,10 @@ BOOST_AUTO_TEST_CASE(CMapEditManager_DrawTerrain_View)
logGlobal->info("CMapEditManager_DrawTerrain_View start");
try
{
const ResourceID testMap("test/TerrainViewTest", EResType::MAP);
// Load maps and json config
const auto originalMap = CMapService::loadMap("test/TerrainViewTest");
auto map = CMapService::loadMap("test/TerrainViewTest");
const auto originalMap = CMapService::loadMap(testMap);
auto map = CMapService::loadMap(testMap);
logGlobal->info("Loaded test map successfully.");
// Validate edit manager