src/game/level/level_editor/undo_history.c
src/game/level/level_editor/action_picker.h
src/game/level/level_editor/action_picker.c
- src/system/line_stream.h
- src/system/line_stream.c
src/system/log.h
src/system/log.c
src/system/lt.h
#include "src/game/level/level_editor/background_layer.c"
#include "src/game/level/level_editor/undo_history.c"
#include "src/game/level/level_editor/action_picker.c"
-#include "src/system/line_stream.c"
#include "src/system/log.c"
#include "src/system/lt_adapters.c"
#include "src/system/nth_alloc.c"
#include "game/level/level_editor/player_layer.h"
#include "game/level/level_editor/label_layer.h"
#include "game/level/level_editor/background_layer.h"
-#include "system/line_stream.h"
#include "system/log.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "game/level/background.h"
#include "math/rand.h"
#include "math/rect.h"
-#include "system/line_stream.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "system/log.h"
#include "game/level/player.h"
#include "game/level/rigid_bodies.h"
#include "math/rand.h"
-#include "system/line_stream.h"
#include "system/log.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "goals.h"
#include "math/pi.h"
#include "math/triangle.h"
-#include "system/line_stream.h"
#include "system/log.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "game/camera.h"
#include "game/level/labels.h"
#include "game/level/level_editor/label_layer.h"
-#include "system/line_stream.h"
#include "system/log.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "lava.h"
#include "math/rect.h"
#include "system/lt.h"
-#include "system/line_stream.h"
#include "system/nth_alloc.h"
#include "system/log.h"
#include "game/level/level_editor/rect_layer.h"
#include <time.h>
#include "math/pi.h"
-#include "system/line_stream.h"
#include "system/log.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "system/str.h"
#include "config.h"
#include "math/extrema.h"
+#include "system/file.h"
#include "level_editor.h"
#define LEVEL_FOLDER_MAX_LENGTH 512
-#define LEVEL_LINE_MAX_LENGTH 512
#define LEVEL_EDITOR_EDIT_FIELD_SIZE vec(5.0f, 5.0f)
#define LEVEL_EDITOR_EDIT_FIELD_COLOR COLOR_BLACK
return layer;
}
-int background_layer_read_from_line_stream(BackgroundLayer *layer,
- LineStream *line_stream)
-{
- if (color_picker_read_from_line_stream(
- &layer->color_picker,
- line_stream) < 0) {
- return -1;
- }
-
- layer->prev_color = color_picker_rgba(&layer->color_picker);
-
- return 0;
-}
-
BackgroundLayer chop_background_layer(String *input)
{
String line = trim(chop_by_delim(input, '\n'));
} BackgroundLayer;
BackgroundLayer create_background_layer(Color color);
-int background_layer_read_from_line_stream(BackgroundLayer *layer,
- LineStream *line_stream);
BackgroundLayer chop_background_layer(String *input);
static inline
#include "game/level/boxes.h"
#include "system/stacktrace.h"
-#include "system/line_stream.h"
#include "system/log.h"
#include "game/camera.h"
#include "color_picker.h"
return color_picker;
}
-int color_picker_read_from_line_stream(ColorPicker *color_picker,
- LineStream *line_stream)
-{
- char color[7];
- const char *line = line_stream_next(line_stream);
- if (line == NULL) {
- return -1;
- }
-
- if (sscanf(line, "%6s", color) == EOF) {
- log_fail("Could not read color\n");
- }
-
- *color_picker = create_color_picker_from_rgba(hexstr(color));
-
- return 0;
-}
-
int color_picker_render(const ColorPicker *color_picker,
const Camera *camera)
{
Slider sliders[COLOR_SLIDER_N];
} ColorPicker;
-typedef struct LineStream LineStream;
ColorPicker create_color_picker_from_rgba(Color color);
-int color_picker_read_from_line_stream(ColorPicker *color_picker,
- LineStream *line_stream);
-
int color_picker_render(const ColorPicker *color_picker,
const Camera *camera);
int color_picker_event(ColorPicker *color_picker,
#include <SDL.h>
-#include "system/line_stream.h"
#include "system/stacktrace.h"
#include "system/nth_alloc.h"
#include "system/lt.h"
return label_layer;
}
-LabelLayer *create_label_layer_from_line_stream(LineStream *line_stream, const char *id_name_prefix)
-{
- trace_assert(line_stream);
- LabelLayer *label_layer = create_label_layer(id_name_prefix);
-
- if (label_layer == NULL) {
- RETURN_LT(label_layer->lt, NULL);
- }
-
- const char *line = line_stream_next(line_stream);
- if (line == NULL) {
- log_fail("Could not read amount of labels\n");
- RETURN_LT(label_layer->lt, NULL);
- }
-
- size_t n = 0;
- if (sscanf(line, "%zu", &n) == EOF) {
- log_fail("Could not parse amount of labels\n");
- RETURN_LT(label_layer->lt, NULL);
- }
-
- for (size_t i = 0; i < n; ++i) {
- char hex[7];
- char id[LABEL_LAYER_ID_MAX_SIZE];
- Vec2f position;
-
- line = line_stream_next(line_stream);
- if (line == NULL) {
- log_fail("Could not read label meta info\n");
- RETURN_LT(label_layer->lt, NULL);
- }
-
- if (sscanf(
- line,
- "%"STRINGIFY(LABEL_LAYER_ID_MAX_SIZE)"s%f%f%6s\n",
- id, &position.x, &position.y, hex) == EOF) {
- log_fail("Could not parse label meta info\n");
- RETURN_LT(label_layer->lt, NULL);
- }
-
- Color color = hexstr(hex);
-
- dynarray_push(&label_layer->ids, id);
- dynarray_push(&label_layer->positions, &position);
- dynarray_push(&label_layer->colors, &color);
-
- line = line_stream_next(line_stream);
- if (line == NULL) {
- log_fail("Could not read label text\n");
- }
-
- char label_text[LABEL_LAYER_TEXT_MAX_SIZE] = {0};
- memcpy(label_text, line, LABEL_LAYER_TEXT_MAX_SIZE - 1);
- trim_endline(label_text);
- dynarray_push(&label_layer->texts, &label_text);
- }
-
- return label_layer;
-}
-
LabelLayer *chop_label_layer(Memory *memory,
String *input,
const char *id_name_prefix)
#define LABEL_LAYER_TEXT_MAX_SIZE 256
typedef struct LabelLayer LabelLayer;
-typedef struct LineStream LineStream;
LayerPtr label_layer_as_layer(LabelLayer *label_layer);
// NOTE: create_label_layer and create_label_layer_from_line_stream do
// not own id_name_prefix
LabelLayer *create_label_layer(const char *id_name_prefix);
-LabelLayer *create_label_layer_from_line_stream(LineStream *line_stream,
- const char *id_name_prefix);
LabelLayer *chop_label_layer(Memory *memory,
String *input,
const char *id_name_prefix);
};
}
-PlayerLayer create_player_layer_from_line_stream(LineStream *line_stream)
-{
- trace_assert(line_stream);
-
- const char *line = line_stream_next(line_stream);
- trace_assert(line);
-
- char colorstr[7] = "000000";
- Vec2f position = vec(0.0f, 0.0f);
-
- const int bound =
- sscanf(line, "%f%f%6s", &position.x, &position.y, colorstr);
-
-#define BOUND_EXPECTED 3
- if (bound != BOUND_EXPECTED) {
- log_fail("Could not read Player Layer properly. Parsed tokens: %d. Expected: %d\n",
- bound, BOUND_EXPECTED);
- }
-#undef BOUND_EXPECTED
-
- return create_player_layer(position, hexstr(colorstr));
-}
-
PlayerLayer chop_player_layer(Memory *memory, String *input)
{
trace_assert(memory);
#include "color_picker.h"
#include "layer.h"
#include "system/lt.h"
-#include "system/line_stream.h"
#include "system/memory.h"
#include "system/s.h"
} PlayerLayer;
PlayerLayer create_player_layer(Vec2f position, Color color);
-PlayerLayer create_player_layer_from_line_stream(LineStream *line_stream);
PlayerLayer chop_player_layer(Memory *memory, String *input);
LayerPtr player_layer_as_layer(PlayerLayer *player_layer);
#include "dynarray.h"
#include "game/camera.h"
-#include "system/line_stream.h"
#include "system/log.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
return point_layer;
}
-PointLayer *create_point_layer_from_line_stream(LineStream *line_stream,
- const char *id_name_prefix)
-{
- trace_assert(line_stream);
-
- PointLayer *point_layer = create_point_layer(id_name_prefix);
-
- size_t count = 0;
- if (sscanf(
- line_stream_next(line_stream),
- "%zu",
- &count) == EOF) {
- log_fail("Could not read amount of points");
- RETURN_LT(point_layer->lt, NULL);
- }
-
- char color_name[7];
- char id[ID_MAX_SIZE];
- float x, y;
- for (size_t i = 0; i < count; ++i) {
- if (sscanf(
- line_stream_next(line_stream),
- "%"STRINGIFY(ID_MAX_SIZE)"s%f%f%6s",
- id, &x, &y, color_name) < 0) {
- log_fail("Could not read %dth goal\n", i);
- RETURN_LT(point_layer->lt, NULL);
- }
- const Color color = hexstr(color_name);
- const Vec2f point = vec(x, y);
-
- dynarray_push(&point_layer->colors, &color);
- dynarray_push(&point_layer->positions, &point);
- dynarray_push(&point_layer->ids, id);
- }
-
- point_layer->selection = -1;
-
- point_layer->color_picker = create_color_picker_from_rgba(COLOR_RED);
-
- return point_layer;
-}
-
PointLayer *chop_point_layer(Memory *memory,
String *input,
const char *id_name_prefix)
#define ID_MAX_SIZE 36
typedef struct PointLayer PointLayer;
-typedef struct LineStream LineStream;
LayerPtr point_layer_as_layer(PointLayer *point_layer);
// NOTE: create_point_layer and create_point_layer_from_line_stream do
// not own id_name_prefix
PointLayer *create_point_layer(const char *id_name_prefix);
-PointLayer *create_point_layer_from_line_stream(LineStream *line_stream,
- const char *id_name_prefix);
PointLayer *chop_point_layer(Memory *memory,
String *input,
const char *id_name_prefix);
#include "color.h"
#include "rect_layer.h"
#include "dynarray.h"
-#include "system/line_stream.h"
#include "color_picker.h"
#include "system/str.h"
#include "ui/edit_field.h"
#include "game/level/action.h"
#include "action_picker.h"
#include "game.h"
+#include "math/extrema.h"
#define RECT_LAYER_SELECTION_THICCNESS 15.0f
#define RECT_LAYER_ID_LABEL_SIZE vec(3.0f, 3.0f)
return layer;
}
-RectLayer *create_rect_layer_from_line_stream(LineStream *line_stream,
- const char *id_name_prefix,
- Cursor *cursor)
-{
- trace_assert(line_stream);
-
- RectLayer *layer = create_rect_layer(id_name_prefix, cursor);
- if (layer == NULL) {
- return NULL;
- }
-
- const char *line = line_stream_next(line_stream);
- if (line == NULL) {
- RETURN_LT(layer->lt, NULL);
- }
-
- size_t count = 0;
- if (sscanf(line, "%zu", &count) < 0) {
- RETURN_LT(layer->lt, NULL);
- }
-
- for (size_t i = 0; i < count; ++i) {
- line = line_stream_next(line_stream);
- if (line == NULL) {
- RETURN_LT(layer->lt, NULL);
- }
-
- char hex[7];
- Rect rect;
- char id[ENTITY_MAX_ID_SIZE];
-
- int n = 0;
- if (sscanf(line,
- "%"STRINGIFY(ENTITY_MAX_ID_SIZE)"s%f%f%f%f%6s%n",
- id,
- &rect.x, &rect.y,
- &rect.w, &rect.h,
- hex, &n) <= 0) {
- log_fail("%s\n", strerror(errno));
- RETURN_LT(layer->lt, NULL);
- }
- line += n;
-
- Color color = hexstr(hex);
- dynarray_push(&layer->rects, &rect);
- dynarray_push(&layer->ids, id);
- dynarray_push(&layer->colors, &color);
-
- Action action = {
- .type = ACTION_NONE,
- .entity_id = {0}
- };
-
- if (sscanf(line, "%d%n", (int*)&action.type, &n) > 0) {
- line += n;
- switch (action.type) {
- case ACTION_NONE: break;
-
- case ACTION_TOGGLE_GOAL:
- case ACTION_HIDE_LABEL: {
- if (sscanf(line, "%"STRINGIFY(ENTITY_MAX_ID_SIZE)"s", action.entity_id) <= 0) {
- log_fail("%s\n", strerror(errno));
- RETURN_LT(layer->lt, NULL);
- }
- } break;
-
- case ACTION_N: break;
- }
- }
-
- dynarray_push(&layer->actions, &action);
- }
-
- return layer;
-}
-
RectLayer *chop_rect_layer(Memory *memory,
String *input,
const char *id_name_prefix,
#include "ui/cursor.h"
typedef struct RectLayer RectLayer;
-typedef struct LineStream LineStream;
LayerPtr rect_layer_as_layer(RectLayer *layer);
// NOTE: create_rect_layer and create_rect_layer_from_line_stream does
// not own id_name_prefix
RectLayer *create_rect_layer(const char *id_name_prefix,
Cursor *cursor);
-RectLayer *create_rect_layer_from_line_stream(
- LineStream *line_stream,
- const char *id_name_prefix,
- Cursor *cursor);
RectLayer *chop_rect_layer(Memory *memory,
String *input,
const char *id_name_prefix,
#include "platforms.h"
#include "system/lt.h"
-#include "system/line_stream.h"
#include "system/nth_alloc.h"
#include "system/log.h"
#include "game/level/level_editor/rect_layer.h"
#include "math/vec.h"
#include "platforms.h"
#include "player.h"
-#include "system/line_stream.h"
#include "system/log.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "player.h"
#include "regions.h"
#include "system/str.h"
-#include "system/line_stream.h"
#include "system/log.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "system/stacktrace.h"
-#include "system/line_stream.h"
#include "system/str.h"
#include "system/log.h"
return -1;
}
- snprintf(text_buffer, 256,
+ snprintf(text_buffer, 256,
"id: %zd\n"
"p:(%.2f, %.2f)\n"
"v:(%.2f, %.2f)\n"
+++ /dev/null
-#include "system/stacktrace.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <stdbool.h>
-
-#include "line_stream.h"
-#include "lt.h"
-#include "lt_adapters.h"
-#include "system/nth_alloc.h"
-#include "system/log.h"
-#include "system/str.h"
-
-struct LineStream
-{
- Lt *lt;
- FILE *stream;
- char *buffer;
- size_t capacity;
- bool unfinished;
-};
-
-// TODO(#905): create_line_stream probably does not need mode
-// Because LineStream interface doesn't even have anything
-// for writing to files. So we can just hardcode the mode
-// inside of the ctor.
-LineStream *create_line_stream(const char *filename,
- const char *mode,
- size_t capacity)
-{
- trace_assert(filename);
- trace_assert(mode);
-
- Lt *lt = create_lt();
-
- LineStream *line_stream = PUSH_LT(
- lt,
- nth_calloc(1, sizeof(LineStream)),
- free);
- if (line_stream == NULL) {
- RETURN_LT(lt, NULL);
- }
- line_stream->lt = lt;
-
- line_stream->stream = PUSH_LT(
- lt,
- fopen(filename, mode),
- fclose_lt);
- if (line_stream->stream == NULL) {
- log_fail("Could not open file '%s': %s\n", filename, strerror(errno));
- RETURN_LT(lt, NULL);
- }
-
- line_stream->buffer = PUSH_LT(
- lt,
- nth_calloc(1, sizeof(char) * capacity),
- free);
- if (line_stream->buffer == NULL) {
- RETURN_LT(lt, NULL);
- }
-
- line_stream->capacity = capacity;
- line_stream->unfinished = false;
-
- return line_stream;
-}
-
-void destroy_line_stream(LineStream *line_stream)
-{
- trace_assert(line_stream);
-
- RETURN_LT0(line_stream->lt);
-}
-
-
-const char *line_stream_next_chunk(LineStream *line_stream)
-{
- trace_assert(line_stream);
-
- const char *s = fgets(line_stream->buffer,
- (int) line_stream->capacity,
- line_stream->stream);
- if (s == NULL) {
- return NULL;
- }
- size_t n = strlen(s);
- line_stream->unfinished = s[n - 1] != '\n';
-
- return s;
-}
-
-const char *line_stream_next(LineStream *line_stream)
-{
- trace_assert(line_stream);
-
- while (line_stream->unfinished) {
- line_stream_next_chunk(line_stream);
- }
-
- return line_stream_next_chunk(line_stream);
-}
-
-char *line_stream_collect_n_lines(LineStream *line_stream, size_t n)
-{
- char *result = string_append(NULL, "");
- for (size_t i = 0; i < n; ++i) {
- const char *line = line_stream_next(line_stream);
- if (line == NULL) {
- free(result);
- return NULL;
- }
-
- result = string_append(result, line);
- }
-
- return result;
-}
-
-char *line_stream_collect_until_end(LineStream *line_stream)
-{
- char *result = string_append(NULL, "");
- const char *line = line_stream_next(line_stream);
-
- /* TODO(#906): line_stream_collect_until_end does not distinguish between EOF and error during reading */
- while (line != NULL) {
- result = string_append(result, line);
- line = line_stream_next(line_stream);
- }
-
- return result;
-}
+++ /dev/null
-#ifndef LINE_STREAM_H_
-#define LINE_STREAM_H_
-
-#include <stdlib.h>
-
-typedef struct LineStream LineStream;
-
-LineStream *create_line_stream(const char *filename,
- const char *mode,
- size_t capacity);
-void destroy_line_stream(LineStream *line_stream);
-
-const char *line_stream_next_chunk(LineStream *line_stream);
-const char *line_stream_next(LineStream *line_stream);
-char *line_stream_collect_n_lines(LineStream *line_stream, size_t n);
-char *line_stream_collect_until_end(LineStream *line_stream);
-
-#endif // LINE_STREAM_H_
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include "system/stacktrace.h"
#include "system/memory.h"
return s;
}
-
-char *string_append(char *prefix, const char *suffix)
-{
- trace_assert(suffix);
-
- if (prefix == NULL) {
- return string_duplicate(suffix, NULL);
- }
-
- prefix = nth_realloc(prefix, strlen(prefix) + strlen(suffix) + 1);
- return strcat(prefix, suffix);
-}
char *string_duplicate(const char *str,
const char *str_end);
-char *string_append(char *prefix,
- const char *suffix);
char *trim_endline(char *s);
#endif // STR_H_