Remove LevelMetadata as a concept
parent
002ac714b3
commit
4c7f51c3ab
|
@ -127,8 +127,6 @@ add_executable(nothing
|
|||
src/ui/slider.c
|
||||
src/ui/grid.h
|
||||
src/ui/grid.c
|
||||
src/game/level_metadata.h
|
||||
src/game/level_metadata.c
|
||||
src/game/level/level_editor.h
|
||||
src/game/level/level_editor.c
|
||||
src/game/level/level_editor/color_picker.h
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
1
|
||||
Level 01
|
||||
2
|
||||
fffda5
|
||||
28.578053 -456.515228 ff8080
|
||||
23
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
1
|
||||
Level 02
|
||||
2
|
||||
0a2b2a
|
||||
0.000000 0.000000 f2ff80
|
||||
1
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
1
|
||||
Platforms
|
||||
2
|
||||
073642
|
||||
117.106163 417.591919 b58900
|
||||
22
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include "src/ui/wiggly_text.c"
|
||||
#include "src/ui/slider.c"
|
||||
#include "src/ui/grid.c"
|
||||
#include "src/game/level_metadata.c"
|
||||
#include "src/game/level/level_editor.c"
|
||||
#include "src/game/level/level_editor/color_picker.c"
|
||||
#include "src/game/level/level_editor/rect_layer.c"
|
||||
|
|
|
@ -26,6 +26,6 @@
|
|||
#define METADATA_VERSION_MAX_SIZE 256
|
||||
#define METADATA_FILEPATH_MAX_SIZE 512
|
||||
|
||||
#define VERSION "1"
|
||||
#define VERSION "2"
|
||||
|
||||
#endif // CONFIG_H_
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "game/level/player.h"
|
||||
#include "game/level/regions.h"
|
||||
#include "game/level/rigid_bodies.h"
|
||||
#include "game/level_metadata.h"
|
||||
#include "game/level/level_editor/rect_layer.h"
|
||||
#include "game/level/level_editor/point_layer.h"
|
||||
#include "game/level/level_editor/player_layer.h"
|
||||
|
@ -40,7 +39,6 @@ struct Level
|
|||
Lt *lt;
|
||||
|
||||
LevelState state;
|
||||
LevelMetadata *metadata;
|
||||
Background background;
|
||||
RigidBodies *rigid_bodies;
|
||||
Player *player;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "game/camera.h"
|
||||
#include "game/sound_samples.h"
|
||||
#include "game/level_metadata.h"
|
||||
#include "game/level/boxes.h"
|
||||
#include "game/level/level_editor/action_picker.h"
|
||||
#include "game/level/level_editor/color_picker.h"
|
||||
|
@ -60,16 +59,6 @@ LevelEditor *create_level_editor(Cursor *cursor)
|
|||
RETURN_LT(lt, NULL);
|
||||
}
|
||||
|
||||
memset(level_editor->metadata.version, 0, METADATA_VERSION_MAX_SIZE);
|
||||
memcpy(level_editor->metadata.version,
|
||||
VERSION,
|
||||
MIN(size_t, sizeof(VERSION), METADATA_VERSION_MAX_SIZE - 1));
|
||||
|
||||
memset(level_editor->metadata.title, 0, METADATA_TITLE_MAX_SIZE);
|
||||
memcpy(level_editor->metadata.title,
|
||||
DEFAULT_LEVEL_TITLE,
|
||||
MIN(size_t, sizeof(DEFAULT_LEVEL_TITLE), METADATA_TITLE_MAX_SIZE - 1));
|
||||
|
||||
level_editor->background_layer = create_background_layer(hexstr("fffda5"));
|
||||
|
||||
level_editor->player_layer =
|
||||
|
@ -196,7 +185,21 @@ LevelEditor *create_level_editor_from_file(const char *file_name, Cursor *cursor
|
|||
RETURN_LT(lt, NULL);
|
||||
}
|
||||
|
||||
if (metadata_load_from_line_stream(&level_editor->metadata, level_stream, level_editor->file_name) < 0) {
|
||||
const char *line = line_stream_next(level_stream);
|
||||
if (line == NULL) {
|
||||
RETURN_LT(lt, NULL);
|
||||
}
|
||||
|
||||
char version[METADATA_VERSION_MAX_SIZE] = {0};
|
||||
memcpy(version, line,
|
||||
MIN(size_t,
|
||||
strlen(line),
|
||||
METADATA_VERSION_MAX_SIZE - 1));
|
||||
trim_endline(version);
|
||||
|
||||
if (strcmp(version, VERSION) != 0) {
|
||||
log_fail("Version `%s` is not supported. Expected version `%s`.\n",
|
||||
version, VERSION);
|
||||
RETURN_LT(lt, NULL);
|
||||
}
|
||||
|
||||
|
@ -565,11 +568,7 @@ static int level_editor_dump(LevelEditor *level_editor)
|
|||
fopen(level_editor->file_name, "w"),
|
||||
fclose_lt);
|
||||
|
||||
if (fprintf(filedump, "%s\n", level_editor->metadata.version) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fprintf(filedump, "%s\n", level_editor->metadata.title) < 0) {
|
||||
if (fprintf(filedump, "%s", VERSION) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "game/level/level_editor/layer_picker.h"
|
||||
#include "game/level/level_editor/undo_history.h"
|
||||
#include "game/level/level_editor/action_picker.h"
|
||||
#include "game/level_metadata.h"
|
||||
#include "ui/wiggly_text.h"
|
||||
#include "ui/cursor.h"
|
||||
|
||||
|
@ -31,7 +30,6 @@ struct LevelEditor
|
|||
LayerPicker layer_picker;
|
||||
FadingWigglyText notice;
|
||||
|
||||
LevelMetadata metadata;
|
||||
RectLayer *boxes_layer;
|
||||
RectLayer *platforms_layer;
|
||||
RectLayer *back_platforms_layer;
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "system/str.h"
|
||||
#include "system/file.h"
|
||||
#include "dynarray.h"
|
||||
#include "game/level_metadata.h"
|
||||
|
||||
#include "./level_folder.h"
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef LEVEL_FOLDER_H_
|
||||
#define LEVEL_FOLDER_H_
|
||||
|
||||
#include "level_metadata.h"
|
||||
|
||||
typedef struct {
|
||||
Dynarray filepaths;
|
||||
} LevelFolder;
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "system/stacktrace.h"
|
||||
#include "system/nth_alloc.h"
|
||||
#include "system/lt.h"
|
||||
#include "system/line_stream.h"
|
||||
#include "system/str.h"
|
||||
#include "level_metadata.h"
|
||||
#include "math/extrema.h"
|
||||
|
||||
int metadata_load_from_line_stream(LevelMetadata *metadata,
|
||||
LineStream *line_stream,
|
||||
const char *filepath)
|
||||
{
|
||||
trace_assert(metadata);
|
||||
trace_assert(line_stream);
|
||||
|
||||
memset(metadata->version, 0, METADATA_VERSION_MAX_SIZE);
|
||||
memset(metadata->title, 0, METADATA_TITLE_MAX_SIZE);
|
||||
memset(metadata->filepath, 0, METADATA_FILEPATH_MAX_SIZE);
|
||||
|
||||
const char *line = line_stream_next(line_stream);
|
||||
if (line == NULL) return -1;
|
||||
|
||||
memcpy(metadata->version,
|
||||
line,
|
||||
min_size_t(strlen(line), METADATA_VERSION_MAX_SIZE - 1));
|
||||
trim_endline(metadata->version);
|
||||
|
||||
line = line_stream_next(line_stream);
|
||||
if (line == NULL) return -1;
|
||||
|
||||
memcpy(metadata->title,
|
||||
line,
|
||||
min_size_t(strlen(line), METADATA_VERSION_MAX_SIZE - 1));
|
||||
trim_endline(metadata->title);
|
||||
|
||||
memcpy(metadata->filepath,
|
||||
filepath,
|
||||
min_size_t(strlen(filepath), METADATA_FILEPATH_MAX_SIZE - 1));
|
||||
trim_endline(metadata->filepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int metadata_load_from_file(LevelMetadata *metadata, const char *filepath)
|
||||
{
|
||||
trace_assert(metadata);
|
||||
trace_assert(filepath);
|
||||
|
||||
LineStream *line_stream = create_line_stream(filepath, "r", 256);
|
||||
if (line_stream == NULL) return -1;
|
||||
|
||||
int err = metadata_load_from_line_stream(metadata, line_stream, filepath);
|
||||
destroy_line_stream(line_stream);
|
||||
return err;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef LEVEL_METADATA_H_
|
||||
#define LEVEL_METADATA_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
typedef struct LineStream LineStream;
|
||||
|
||||
typedef struct {
|
||||
char filepath[METADATA_FILEPATH_MAX_SIZE];
|
||||
char version[METADATA_VERSION_MAX_SIZE];
|
||||
char title[METADATA_TITLE_MAX_SIZE];
|
||||
} LevelMetadata;
|
||||
|
||||
int metadata_load_from_file(LevelMetadata *metadata, const char *filepath);
|
||||
int metadata_load_from_line_stream(LevelMetadata *metadata, LineStream *line_stream, const char *filepath);
|
||||
|
||||
#endif // LEVEL_METADATA_H_
|
|
@ -26,13 +26,6 @@ struct LevelPicker
|
|||
ListSelector list_selector;
|
||||
};
|
||||
|
||||
static inline
|
||||
const char *list_item_text(void *element)
|
||||
{
|
||||
trace_assert(element);
|
||||
return ((LevelMetadata *)element)->title;
|
||||
}
|
||||
|
||||
LevelPicker *create_level_picker(const char *dirpath)
|
||||
{
|
||||
trace_assert(dirpath);
|
||||
|
|
Loading…
Reference in New Issue