Soport per a osx, s'ha d'arreglar en windows
This commit is contained in:
22
main.cpp
22
main.cpp
@@ -50,6 +50,8 @@ char map_filename[100] = { 0 };
|
||||
int tilemap_width = 0;
|
||||
int tilemap_height = 0;
|
||||
|
||||
char path[400] = {0};
|
||||
|
||||
unsigned char* map = nullptr;
|
||||
int map_x = 0;
|
||||
int map_y = 0;
|
||||
@@ -57,6 +59,13 @@ int map_y = 0;
|
||||
int tile_sel = 0;
|
||||
int tile_back = 0;
|
||||
|
||||
const char* GetPath(const char* filename) {
|
||||
static char fullpath[400];
|
||||
strcpy(fullpath, path);
|
||||
strcat(fullpath, filename);
|
||||
return fullpath;
|
||||
}
|
||||
|
||||
int StrToInt(const char* str) {
|
||||
int val = 0;
|
||||
int size = strlen(str);
|
||||
@@ -68,7 +77,7 @@ int StrToInt(const char* str) {
|
||||
}
|
||||
|
||||
void LoadConfig() {
|
||||
FILE* f = fopen("config.ini", "r");
|
||||
FILE* f = fopen(GetPath("config.ini"), "r");
|
||||
if (!f) { error = 1; return; }
|
||||
char key[50];
|
||||
char val[255];
|
||||
@@ -121,7 +130,7 @@ void Init() {
|
||||
free(pixels);
|
||||
|
||||
int c;
|
||||
FILE* f = fopen(tiles_filename, "rb");
|
||||
FILE* f = fopen(GetPath(tiles_filename), "rb");
|
||||
if (!f) { error = 2; return; }
|
||||
buffer = stbi_load_from_file(f, &tilemap_width, &tilemap_height, &c, 4);
|
||||
sdlTilesTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, tilemap_width, tilemap_height);
|
||||
@@ -153,7 +162,7 @@ void Init() {
|
||||
}
|
||||
stbi_image_free(buffer);
|
||||
|
||||
f = fopen(map_filename, "rb");
|
||||
f = fopen(GetPath(map_filename), "rb");
|
||||
map = (unsigned char*)malloc(map_width*map_height);
|
||||
if (f) {
|
||||
int old_map_width = 0, old_map_height = 0;
|
||||
@@ -176,7 +185,7 @@ void Init() {
|
||||
}
|
||||
fclose(f);
|
||||
} else {
|
||||
f = fopen(map_filename, "wb");
|
||||
f = fopen(GetPath(map_filename), "wb");
|
||||
if (!f) { error = 3; return; }
|
||||
fwrite(&map_width, 1, 1, f);
|
||||
fwrite(&map_height, 1, 1, f);
|
||||
@@ -368,7 +377,7 @@ void DoTileMap() {
|
||||
if (keyJustPressed == SDL_SCANCODE_TAB) { menu = false; return; }
|
||||
FillRect(0, 0, screen_width, screen_height, 0, 0, 0, 192);
|
||||
if (Button(6, 6, "Save")) {
|
||||
FILE* f = fopen(map_filename, "wb");
|
||||
FILE* f = fopen(GetPath(map_filename), "wb");
|
||||
fwrite(&map_width, 1, 1, f);
|
||||
fwrite(&map_height, 1, 1, f);
|
||||
fwrite(map, map_width*map_height, 1, f);
|
||||
@@ -454,6 +463,9 @@ void DoMiniMap() {
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
const int len = strlen(argv[0])-30;
|
||||
memcpy(path, argv[0], len);
|
||||
path[len] = '\0';
|
||||
Init();
|
||||
|
||||
while (!Update()) {
|
||||
|
||||
Reference in New Issue
Block a user