fixed problems with the tilelayer dumping. Closes #86. Closes #149

This commit is contained in:
oy 2010-09-07 02:06:11 +02:00
parent 3857096a20
commit 5ff7836638

View file

@ -1,7 +1,8 @@
#include <stdio.h>
#include <engine/graphics.h>
#include <engine/keys.h> //temp
#include <engine/keys.h>
#include <engine/serverbrowser.h>
#include <engine/shared/config.h>
#include <engine/storage.h>
#include <game/layers.h>
#include <game/client/gameclient.h>
@ -126,20 +127,30 @@ void CMapLayers::OnRender()
Render = true;
}
if(pLayer->m_Type == LAYERTYPE_TILES && Input()->KeyPressed(KEY_KP0))
if(Render && pLayer->m_Type == LAYERTYPE_TILES && Input()->KeyPressed(KEY_LCTRL) && Input()->KeyPressed(KEY_LSHIFT) && Input()->KeyDown(KEY_KP0))
{
CMapItemLayerTilemap *pTMap = (CMapItemLayerTilemap *)pLayer;
CTile *pTiles = (CTile *)m_pLayers->Map()->GetData(pTMap->m_Data);
char buf[256];
str_format(buf, sizeof(buf), "%d%d_%dx%d", g, l, pTMap->m_Width, pTMap->m_Height);
FILE *f = fopen(buf, "w");
for(int y = 0; y < pTMap->m_Height; y++)
CServerInfo CurrentServerInfo;
Client()->GetServerInfo(&CurrentServerInfo);
char aFilename[256];
str_format(aFilename, sizeof(aFilename), "dumps/tilelayer_dump_%s-%d-%d-%dx%d.txt", CurrentServerInfo.m_aMap, g, l, pTMap->m_Width, pTMap->m_Height);
IOHANDLE File = Storage()->OpenFile(aFilename, IOFLAG_WRITE);
if(File)
{
for(int x = 0; x < pTMap->m_Width; x++)
fprintf(f, "%d,", pTiles[y*pTMap->m_Width + x].m_Index);
fprintf(f, "\n");
#if defined(CONF_FAMILY_WINDOWS)
static const char Newline[] = "\r\n";
#else
static const char Newline[] = "\n";
#endif
for(int y = 0; y < pTMap->m_Height; y++)
{
for(int x = 0; x < pTMap->m_Width; x++)
io_write(File, &(pTiles[y*pTMap->m_Width + x].m_Index), sizeof(pTiles[y*pTMap->m_Width + x].m_Index));
io_write(File, Newline, sizeof(Newline)-1);
}
io_close(File);
}
fclose(f);
}
if(Render && !IsGameLayer)