mirror of https://git.sr.ht/~kikoodx/sle
editing_area/main.c: restructured panic exit
This commit is contained in:
parent
db77c25935
commit
80c6531492
|
@ -24,6 +24,7 @@ int editing_area_main(int argc, char **argv,
|
|||
int error;
|
||||
struct Level level;
|
||||
level.data = NULL;
|
||||
Texture2D tileset;
|
||||
|
||||
/* initialize raylib */
|
||||
InitWindow(editor_window_width, editor_window_height,
|
||||
|
@ -31,40 +32,41 @@ int editing_area_main(int argc, char **argv,
|
|||
SetTargetFPS(editor_target_fps);
|
||||
init_mouse();
|
||||
/* load textures */
|
||||
const Texture2D tileset = LoadTexture(argv[1]);
|
||||
tileset = LoadTexture(argv[1]);
|
||||
|
||||
/* only proceed if tileset is large enough */
|
||||
if (tileset.width >= TILESET_MIN_WIDTH_PX &&
|
||||
tileset.height >= TILESET_MIN_HEIGHT_PX) {
|
||||
/* load level */
|
||||
error = level_read(&level, argv[2]);
|
||||
printf("%d\n", error);
|
||||
|
||||
while ((!WindowShouldClose()) && (error >= 0)) {
|
||||
/* update */
|
||||
update_mouse(&mouse_x, &mouse_y, level,
|
||||
shared_data);
|
||||
|
||||
/* draw */
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(BLACK);
|
||||
level_draw(level, tileset);
|
||||
editor_mouse_draw(mouse_x, mouse_y);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
if (error >= 0) {
|
||||
/* save level */
|
||||
error = level_write(level, argv[2]);
|
||||
}
|
||||
} else
|
||||
if (tileset.width < TILESET_MIN_WIDTH_PX ||
|
||||
tileset.height < TILESET_MIN_HEIGHT_PX) {
|
||||
fprintf(stderr,
|
||||
"ERROR: tileset size is invalid, expected at "
|
||||
"least [%d ; %d], got [%d ; %d]\n",
|
||||
TILESET_MIN_WIDTH_PX, TILESET_MIN_HEIGHT_PX,
|
||||
tileset.width, tileset.height);
|
||||
goto panic;
|
||||
}
|
||||
|
||||
/* load level */
|
||||
if (level_read(&level, argv[2]))
|
||||
goto panic;
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
/* update */
|
||||
update_mouse(&mouse_x, &mouse_y, level, shared_data);
|
||||
|
||||
/* draw */
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(BLACK);
|
||||
level_draw(level, tileset);
|
||||
editor_mouse_draw(mouse_x, mouse_y);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
/* save level */
|
||||
level_write(level, argv[2]);
|
||||
|
||||
panic:
|
||||
|
||||
/* deinit */
|
||||
level_free(&level);
|
||||
|
|
Loading…
Reference in New Issue