mirror of https://git.sr.ht/~kikoodx/sle
Add four launch flags: editor-width/height & tile-width/height
Details will be added to README soon
This commit is contained in:
parent
7f0b593498
commit
baff9fe66d
|
@ -8,6 +8,7 @@ set(SOURCES
|
|||
src/main.c
|
||||
src/options.c
|
||||
src/mouse.c
|
||||
src/strtoint.c
|
||||
src/editing_area/main.c
|
||||
src/editing_area/level.c
|
||||
src/editing_area/draw.c
|
||||
|
|
|
@ -11,8 +11,8 @@ struct Options {
|
|||
int tile_height;
|
||||
int tileset_width;
|
||||
int tileset_height;
|
||||
int editor_window_width;
|
||||
int editor_window_height;
|
||||
int editor_width;
|
||||
int editor_height;
|
||||
int editor_target_fps;
|
||||
int editor_draw_offset_x;
|
||||
int editor_draw_offset_y;
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
/* Attempt to convert a string to positive integer. Return -1 on error. */
|
||||
int strtoint(char *string);
|
|
@ -27,8 +27,8 @@ int editing_area_main(struct Options options,
|
|||
Texture2D tileset;
|
||||
|
||||
/* initialize raylib */
|
||||
InitWindow(options.editor_window_width,
|
||||
options.editor_window_height, "SLE main window");
|
||||
InitWindow(options.editor_width,
|
||||
options.editor_height, "SLE main window");
|
||||
SetTargetFPS(options.editor_target_fps);
|
||||
init_mouse(options);
|
||||
/* load textures */
|
||||
|
|
29
src/main.c
29
src/main.c
|
@ -5,6 +5,7 @@
|
|||
#include "options.h"
|
||||
#include "shared_data.h"
|
||||
#include "tile_picker/main.h"
|
||||
#include "strtoint.h"
|
||||
#include <getopt.h>
|
||||
#include <raylib.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -89,6 +90,10 @@ static void process_arguments(int argc, char **argv,
|
|||
static struct option long_options[] = {
|
||||
{"level", required_argument, 0, 'l'},
|
||||
{"tileset", required_argument, 0, 't'},
|
||||
{"tile-width", required_argument, 0, 'w'},
|
||||
{"tile-height", required_argument, 0, 'h'},
|
||||
{"editor-width", required_argument, 0, 'W'},
|
||||
{"editor-height", required_argument, 0, 'H'},
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
/* getopt_long stores the option index here */
|
||||
|
@ -101,14 +106,34 @@ static void process_arguments(int argc, char **argv,
|
|||
break;
|
||||
|
||||
switch (opt) {
|
||||
case 'l':
|
||||
case 'l': /* level */
|
||||
overflow_prevention();
|
||||
strcpy(options->level_path, optarg);
|
||||
break;
|
||||
case 't':
|
||||
case 't': /* tileset */
|
||||
overflow_prevention();
|
||||
strcpy(options->tileset_path, optarg);
|
||||
break;
|
||||
case 'w': /* tile width */
|
||||
options->tile_width = strtoint(optarg);
|
||||
if (options->tile_width <= 0)
|
||||
exit(EXIT_FAILURE);
|
||||
break;
|
||||
case 'h': /* tile height */
|
||||
options->tile_height = strtoint(optarg);
|
||||
if (options->tile_height <= 0)
|
||||
exit(EXIT_FAILURE);
|
||||
break;
|
||||
case 'W': /* editor width */
|
||||
options->editor_width = strtoint(optarg);
|
||||
if (options->editor_width <= 0)
|
||||
exit(EXIT_FAILURE);
|
||||
break;
|
||||
case 'H': /* editor height */
|
||||
options->editor_height = strtoint(optarg);
|
||||
if (options->editor_height <= 0)
|
||||
exit(EXIT_FAILURE);
|
||||
break;
|
||||
case '?':
|
||||
/* getopt_long already printed an error message
|
||||
*/
|
||||
|
|
|
@ -10,8 +10,8 @@ struct Options options_defaults(void)
|
|||
.tile_height = TILE_HEIGHT,
|
||||
.tileset_width = 0,
|
||||
.tileset_height = 0,
|
||||
.editor_window_width = EDITOR_WINDOW_WIDTH,
|
||||
.editor_window_height = EDITOR_WINDOW_HEIGHT,
|
||||
.editor_width = EDITOR_WINDOW_WIDTH,
|
||||
.editor_height = EDITOR_WINDOW_HEIGHT,
|
||||
.editor_target_fps = EDITOR_TARGET_FPS,
|
||||
.editor_draw_offset_x = EDITOR_DRAW_OFFSET_X,
|
||||
.editor_draw_offset_y = EDITOR_DRAW_OFFSET_Y,
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "strtoint.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Attempt to convert a string to positive integer. Return -1 on error. */
|
||||
int strtoint(char *string) {
|
||||
char character;
|
||||
int i;
|
||||
const size_t string_len = strlen(string);
|
||||
int sum = 0;
|
||||
int multiplier = 1;
|
||||
for (i = string_len - 1; i >= 0; i -= 1) {
|
||||
character = string[i];
|
||||
if (character < '0' || character > '9') {
|
||||
fprintf(stderr, "ERROR: flag expected a positive number argument, got \"%s\"\n", string);
|
||||
return -1;
|
||||
}
|
||||
sum += multiplier * (character - '0');
|
||||
multiplier *= 10;
|
||||
}
|
||||
return sum;
|
||||
}
|
Loading…
Reference in New Issue