sle/src/editing_area/main.c

67 lines
1.5 KiB
C

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright (C) 2021 KikooDX */
#include "conf.h"
#include "editing_area/draw.h"
#include "editing_area/level.h"
#include "shared_data.h"
#include <raylib.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
int editing_area_main(int argc, char **argv,
struct SharedData *shared_data)
{
struct Level level;
level.data = NULL;
/* initialize raylib */
InitWindow(editor_window_width, editor_window_height,
"SLE main window");
SetTargetFPS(editor_target_fps);
/* load textures */
const Texture2D 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 */
level_read(&level, argv[2]);
while (!WindowShouldClose()) {
/* draw */
BeginDrawing();
ClearBackground(BLACK);
level_draw(level, tileset);
EndDrawing();
}
/* save level */
level_write(level, argv[2]);
} else
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);
/* deinit */
level_free(&level);
/* unload textures */
UnloadTexture(tileset);
CloseWindow();
/* tell to the child process it can end */
shared_data->end_child = true;
/* wait for child process to exit */
wait(NULL);
return EXIT_SUCCESS;
}