mirror of https://git.sr.ht/~kikoodx/sle
Fork and separation of tile picker and level editor.
This commit is contained in:
parent
5d3b1bfd01
commit
b487caeae3
|
@ -8,8 +8,10 @@ include_directories(include)
|
|||
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
src/level.c
|
||||
src/draw.c
|
||||
src/editing_area/main.c
|
||||
src/editing_area/level.c
|
||||
src/editing_area/draw.c
|
||||
src/tile_picker/main.c
|
||||
)
|
||||
|
||||
set(FLAGS
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
static const int window_width = 396;
|
||||
static const int window_height = 224;
|
||||
static const int game_window_width = 396;
|
||||
static const int game_window_height = 224;
|
||||
static const int draw_offset_x = -2;
|
||||
static const int draw_offset_y = -8;
|
||||
static const int tile_width = 16;
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
int editing_area_main(int argc, char **argv);
|
|
@ -0,0 +1,5 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
int tile_picker_main(int argc, char **argv);
|
|
@ -2,7 +2,7 @@
|
|||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "conf.h"
|
||||
#include "level.h"
|
||||
#include "editing_area/level.h"
|
||||
#include <raylib.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "level.h"
|
||||
#include "editing_area/level.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
|
@ -0,0 +1,54 @@
|
|||
/* 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 <assert.h>
|
||||
#include <raylib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int editing_area_main(int argc, char **argv)
|
||||
{
|
||||
struct Level level;
|
||||
level.data = NULL;
|
||||
|
||||
/* check for argument count */
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "ERROR: expected 2 arguments, got %d\n",
|
||||
argc - 1);
|
||||
return EXIT_FAILURE;
|
||||
};
|
||||
|
||||
/* initialize raylib */
|
||||
InitWindow(game_window_width, game_window_height,
|
||||
"SLE main window");
|
||||
SetTargetFPS(target_fps);
|
||||
/* load textures */
|
||||
const Texture2D tileset = LoadTexture(argv[1]);
|
||||
assert(tileset.width > 0);
|
||||
|
||||
/* 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]);
|
||||
|
||||
/* deinit */
|
||||
level_free(&level);
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
58
src/main.c
58
src/main.c
|
@ -1,53 +1,27 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "conf.h"
|
||||
#include "draw.h"
|
||||
#include "level.h"
|
||||
#include <assert.h>
|
||||
#include <raylib.h>
|
||||
#include "editing_area/main.h"
|
||||
#include "tile_picker/main.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* The editor fork to create two windows. One will be the level editor
|
||||
* and the other the tile selection. This is done to allow the user to
|
||||
* organize these panels in the way they want to. */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct Level level;
|
||||
level.data = NULL;
|
||||
pid_t child_process = fork();
|
||||
|
||||
/* check for argument count */
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "ERROR: expected 2 arguments, got %d\n",
|
||||
argc - 1);
|
||||
if (child_process < 0) {
|
||||
fprintf(stderr, "ERROR: process couldn't fork");
|
||||
return EXIT_FAILURE;
|
||||
};
|
||||
|
||||
/* initialize raylib */
|
||||
InitWindow(window_width, window_height, "SLE");
|
||||
SetTargetFPS(target_fps);
|
||||
/* load textures */
|
||||
const Texture2D tileset = LoadTexture(argv[1]);
|
||||
assert(tileset.width > 0);
|
||||
|
||||
/* 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]);
|
||||
|
||||
/* deinit */
|
||||
level_free(&level);
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
} else if (child_process == 0)
|
||||
/* child process, start the tile picker */
|
||||
return tile_picker_main(argc, argv);
|
||||
else
|
||||
/* main process, start the editing area */
|
||||
return editing_area_main(argc, argv);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "editing_area/main.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int tile_picker_main(int argc, char **argv)
|
||||
{
|
||||
printf("hello you :)\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue