71 lines
1.5 KiB
C
71 lines
1.5 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdint.h>
|
|
|
|
#include "../src/types.h"
|
|
|
|
#define MAPDIR "map/"
|
|
#define MAPNAME "mt_map"
|
|
|
|
#define FBUF_SIZE 1024*256
|
|
|
|
char *filebuf;
|
|
|
|
char *filesig =
|
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
|
"<map version=\"1.8\" tiledversion=\"1.8.2\" orientation=\"orthogonal\" renderorder=\"right-down\" width=\"256\" height=\"256\" tilewidth=\"32\" tileheight=\"32\" infinite=\"0\" nextlayerid=\"2\" nextobjectid=\"1\">";
|
|
|
|
int import_map(MapCollec *mapcollec, FILE *mapfile){
|
|
int32_t fbuf_pos = 0;
|
|
int32_t fbuf_max = fread(filebuf, 1, FBUF_SIZE, mapfile);
|
|
if(strncmp(filebuf, filesig, sizeof(filesig))){
|
|
printf("Error: Invalid file header.\n");
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
FILE *maps[100] = {NULL};
|
|
|
|
int import_maps(MapCollec *mapcollec){
|
|
char tmpname[256];
|
|
int i;
|
|
for(i = 0; i < 100; i++){
|
|
snprintf(tmpname, 256, MAPDIR MAPNAME "%d.tmx", i);
|
|
printf("Loading map \"%s\"...\n", tmpname);
|
|
maps[i] = fopen(tmpname, "r");
|
|
if(!maps[i]){
|
|
printf("Failed to load map, stopping here\n");
|
|
break;
|
|
}
|
|
if(import_map(mapcollec, maps[i]))
|
|
return 0;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
void clean_maps(){
|
|
for(int i = 0; i < 100; i++){
|
|
if(maps[i])
|
|
fclose(maps[i]);
|
|
}
|
|
}
|
|
|
|
int export_maps(MapCollec *mapcollec){
|
|
|
|
}
|
|
|
|
int main(){
|
|
MapCollec mapcollec;
|
|
filebuf = malloc(FBUF_SIZE);
|
|
if(!filebuf)
|
|
return 1;
|
|
if(!import_maps(&mapcollec))
|
|
return 1;
|
|
|
|
clean_maps();
|
|
free(filebuf);
|
|
|
|
return 0;
|
|
}
|