mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Start integration of map format into engine
This commit is contained in:
parent
6db94ab74c
commit
0c21efb202
7
Mods/vcmi/Sprites/ScSelC.json
Normal file
7
Mods/vcmi/Sprites/ScSelC.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"basepath" : "mapFormatIcons/",
|
||||
"images" :
|
||||
[
|
||||
{ "group" : 1, "frame" : 0, "file" : "vcmi1.png"}
|
||||
]
|
||||
}
|
BIN
Mods/vcmi/Sprites/mapFormatIcons/vcmi1.png
Normal file
BIN
Mods/vcmi/Sprites/mapFormatIcons/vcmi1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
@ -1117,8 +1117,9 @@ void SelectionTab::parseMaps(const std::unordered_set<ResourceID> &files)
|
||||
CMapInfo mapInfo;
|
||||
mapInfo.mapInit(file.getName());
|
||||
|
||||
// ignore unsupported map versions (e.g. WoG maps without WoG
|
||||
if (mapInfo.mapHeader->version <= CGI->modh->settings.data["textData"]["mapVersion"].Float())
|
||||
// ignore unsupported map versions (e.g. WoG maps without WoG)
|
||||
// but accept VCMI maps
|
||||
if((mapInfo.mapHeader->version >= EMapFormat::VCMI) || (mapInfo.mapHeader->version <= CGI->modh->settings.data["textData"]["mapVersion"].Float()))
|
||||
allItems.push_back(std::move(mapInfo));
|
||||
}
|
||||
catch(std::exception & e)
|
||||
@ -1283,7 +1284,9 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const std::function<void(CM
|
||||
|
||||
slider = new CSlider(Point(372, 86), tabType != CMenuScreen::saveGame ? 480 : 430, std::bind(&SelectionTab::sliderMove, this, _1), positions, curItems.size(), 0, false, CSlider::BLUE);
|
||||
slider->addUsedEvents(WHEEL);
|
||||
format = CDefHandler::giveDef("SCSELC.DEF");
|
||||
|
||||
formatIcons = new CAnimation("SCSELC.DEF");
|
||||
formatIcons->load();
|
||||
|
||||
sortingBy = _format;
|
||||
ascending = true;
|
||||
@ -1312,7 +1315,7 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const std::function<void(CM
|
||||
|
||||
SelectionTab::~SelectionTab()
|
||||
{
|
||||
delete format;
|
||||
delete formatIcons;
|
||||
}
|
||||
|
||||
void SelectionTab::sortBy( int criteria )
|
||||
@ -1437,27 +1440,34 @@ void SelectionTab::printMaps(SDL_Surface *to)
|
||||
}
|
||||
printAtMiddleLoc(temp2, 70, 128 + line * 25, FONT_SMALL, itemColor, to);
|
||||
|
||||
int temp=-1;
|
||||
int frame = -1, group = 0;
|
||||
switch (currentItem->mapHeader->version)
|
||||
{
|
||||
case EMapFormat::ROE:
|
||||
temp=0;
|
||||
frame = 0;
|
||||
break;
|
||||
case EMapFormat::AB:
|
||||
temp=1;
|
||||
frame = 1;
|
||||
break;
|
||||
case EMapFormat::SOD:
|
||||
temp=2;
|
||||
frame = 2;
|
||||
break;
|
||||
case EMapFormat::WOG:
|
||||
temp=3;
|
||||
frame = 3;
|
||||
break;
|
||||
case EMapFormat::VCMI:
|
||||
frame = 0;
|
||||
group = 1;
|
||||
break;
|
||||
default:
|
||||
// Unknown version. Be safe and ignore that map
|
||||
logGlobal->warnStream() << "Warning: " << currentItem->fileURI << " has wrong version!";
|
||||
continue;
|
||||
}
|
||||
blitAtLoc(format->ourImages[temp].bitmap, 88, 117 + line * 25, to);
|
||||
IImage * icon = formatIcons->getImage(frame,group);
|
||||
if(icon)
|
||||
icon->draw(to, pos.x + 88, pos.y + 117 + line * 25);
|
||||
|
||||
|
||||
//victory conditions
|
||||
blitAtLoc(CGP->victory->ourImages[currentItem->mapHeader->victoryIconIndex].bitmap, 306, 117 + line * 25, to);
|
||||
|
@ -149,7 +149,7 @@ public:
|
||||
class SelectionTab : public CIntObject
|
||||
{
|
||||
private:
|
||||
CDefHandler *format; //map size
|
||||
CAnimation * formatIcons;
|
||||
|
||||
void parseMaps(const std::unordered_set<ResourceID> &files);
|
||||
void parseGames(const std::unordered_set<ResourceID> &files, bool multi);
|
||||
|
@ -136,7 +136,8 @@ EResType::Type EResTypeHelper::getTypeFromExtension(std::string extension)
|
||||
{".VSGM1", EResType::SERVER_SAVEGAME},
|
||||
{".ERM", EResType::ERM},
|
||||
{".ERT", EResType::ERT},
|
||||
{".ERS", EResType::ERS}
|
||||
{".ERS", EResType::ERS},
|
||||
{".VMAP", EResType::MAP}
|
||||
};
|
||||
|
||||
auto iter = stringToRes.find(extension);
|
||||
|
@ -215,7 +215,8 @@ enum EMapFormat
|
||||
AB = 0x15, // 21
|
||||
SOD = 0x1c, // 28
|
||||
// HOTA = 0x1e ... 0x20 // 28 ... 30
|
||||
WOG = 0x33 // 51
|
||||
WOG = 0x33, // 51
|
||||
VCMI = 0xF0
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -68,21 +68,32 @@ std::unique_ptr<IMapLoader> CMapService::getMapLoader(std::unique_ptr<CInputStre
|
||||
ui32 header = reader.readUInt32();
|
||||
reader.getStream()->seek(0);
|
||||
|
||||
// Check which map format is used
|
||||
// gzip header is 3 bytes only in size
|
||||
switch(header & 0xffffff)
|
||||
//check for ZIP magic. Zip files are VCMI maps
|
||||
switch(header)
|
||||
{
|
||||
// gzip header magic number, reversed for LE
|
||||
case 0x00088B1F:
|
||||
stream = std::unique_ptr<CInputStream>(new CCompressedStream(std::move(stream), true));
|
||||
return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
|
||||
case EMapFormat::WOG :
|
||||
case EMapFormat::AB :
|
||||
case EMapFormat::ROE :
|
||||
case EMapFormat::SOD :
|
||||
return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
|
||||
default :
|
||||
throw std::runtime_error("Unknown map format");
|
||||
case 0x06054b50:
|
||||
case 0x04034b50:
|
||||
case 0x02014b50:
|
||||
//return std::unique_ptr<IMapLoader>(new CMapLoaderJson(stream.get()));
|
||||
throw std::runtime_error("Not implemented map format");
|
||||
break;
|
||||
default:
|
||||
// Check which map format is used
|
||||
// gzip header is 3 bytes only in size
|
||||
switch(header & 0xffffff)
|
||||
{
|
||||
// gzip header magic number, reversed for LE
|
||||
case 0x00088B1F:
|
||||
stream = std::unique_ptr<CInputStream>(new CCompressedStream(std::move(stream), true));
|
||||
return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
|
||||
case EMapFormat::WOG :
|
||||
case EMapFormat::AB :
|
||||
case EMapFormat::ROE :
|
||||
case EMapFormat::SOD :
|
||||
return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
|
||||
default :
|
||||
throw std::runtime_error("Unknown map format");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -299,8 +299,7 @@ void CMapLoaderJson::readHeader()
|
||||
//do not use map field here, use only mapHeader
|
||||
const JsonNode header = readJson(HEADER_FILE_NAME);
|
||||
|
||||
//TODO: read such data like map name & size
|
||||
//mapHeader->version = ??? //todo: new version field
|
||||
mapHeader->version = EMapFormat::VCMI;//todo: new version field
|
||||
|
||||
//todo: multilevel map load support
|
||||
const JsonNode levels = header["mapLevels"];
|
||||
|
@ -578,7 +578,7 @@ void CMapGenerator::createConnections()
|
||||
|
||||
void CMapGenerator::addHeaderInfo()
|
||||
{
|
||||
map->version = EMapFormat::SOD;
|
||||
map->version = EMapFormat::VCMI;
|
||||
map->width = mapGenOptions->getWidth();
|
||||
map->height = mapGenOptions->getHeight();
|
||||
map->twoLevel = mapGenOptions->getHasTwoLevels();
|
||||
|
Loading…
Reference in New Issue
Block a user