2011-07-26 21:27:31 -07:00
|
|
|
// tool "framework"
|
2011-07-26 17:38:38 -07:00
|
|
|
#include "maplib.h"
|
|
|
|
#include "pngsave.h"
|
|
|
|
#include "mapload.h"
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2011-07-27 16:35:41 -07:00
|
|
|
char *filename, *p_filename;
|
|
|
|
char *base, tmpFile[PATH_MAX];
|
2011-07-26 21:27:31 -07:00
|
|
|
|
2011-07-26 17:38:38 -07:00
|
|
|
GAMEMAP *map;
|
2011-07-27 16:35:41 -07:00
|
|
|
|
2011-07-26 17:38:38 -07:00
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
printf("Usage: %s <map>\n", argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-07-27 16:35:41 -07:00
|
|
|
physfs_init(argv[0]);
|
|
|
|
filename = physfs_addmappath(argv[1]);
|
|
|
|
p_filename = strrchr(filename, '/');
|
|
|
|
if (p_filename)
|
|
|
|
{
|
|
|
|
p_filename++;
|
|
|
|
base = strdup(p_filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
base = strdup(filename);
|
|
|
|
}
|
|
|
|
if (!PHYSFS_exists(base))
|
|
|
|
{
|
|
|
|
PHYSFS_mkdir(base);
|
|
|
|
}
|
|
|
|
|
2011-07-26 17:38:38 -07:00
|
|
|
map = mapLoad(filename);
|
2011-07-27 16:35:41 -07:00
|
|
|
free(filename);
|
|
|
|
|
2011-07-26 21:27:31 -07:00
|
|
|
if (!map)
|
2011-07-26 17:38:38 -07:00
|
|
|
{
|
2011-07-27 16:35:41 -07:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint x, y;
|
|
|
|
uint8_t *pixels = (uint8_t *)malloc(map->width * map->height);
|
2011-07-26 17:38:38 -07:00
|
|
|
|
2011-07-27 16:35:41 -07:00
|
|
|
for (x = 0; x < map->width; x++)
|
|
|
|
{
|
|
|
|
for (y = 0; y < map->height; y++)
|
|
|
|
{
|
|
|
|
MAPTILE *psTile = mapTile(map, x, y);
|
|
|
|
int pixpos = y * map->width + x;
|
2011-07-26 17:38:38 -07:00
|
|
|
|
2011-07-27 16:35:41 -07:00
|
|
|
pixels[pixpos++] = psTile->height;
|
|
|
|
}
|
|
|
|
}
|
2011-07-26 21:27:31 -07:00
|
|
|
|
2011-07-27 16:35:41 -07:00
|
|
|
strcpy(tmpFile, base);
|
|
|
|
strcat(tmpFile, "/height.png");
|
|
|
|
|
|
|
|
savePngI8(tmpFile, pixels, map->width, map->height);
|
|
|
|
free(pixels);
|
2011-07-26 21:27:31 -07:00
|
|
|
|
2011-07-27 16:35:41 -07:00
|
|
|
mapFree(map);
|
2011-07-26 21:27:31 -07:00
|
|
|
|
2011-07-27 16:35:41 -07:00
|
|
|
physfs_shutdown();
|
2011-07-26 17:38:38 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|