X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fgame%2Flevel%2Flevel_editor%2Fpoint_layer.c;h=5eac7322fa226f4b27193d6d54f9f9ba99ecdec3;hb=4ec300f8a614ee0438d8f55edc30a82a7d5b1d7a;hp=0050d95edb7e9b70286dfc2f9499d0331015e226;hpb=c009e61c1b46239b2cf1b8f34cc8a4402e66b479;p=nothing.git diff --git a/src/game/level/level_editor/point_layer.c b/src/game/level/level_editor/point_layer.c index 0050d95e..5eac7322 100644 --- a/src/game/level/level_editor/point_layer.c +++ b/src/game/level/level_editor/point_layer.c @@ -239,6 +239,43 @@ PointLayer *create_point_layer_from_line_stream(LineStream *line_stream, return point_layer; } +PointLayer *chop_point_layer(Memory *memory, + String *input, + const char *id_name_prefix) +{ + trace_assert(memory); + trace_assert(input); + trace_assert(id_name_prefix); + + PointLayer *point_layer = create_point_layer(id_name_prefix); + + int n = atoi(string_to_cstr(memory, trim(chop_by_delim(input, '\n')))); + char id[ENTITY_MAX_ID_SIZE]; + for (int i = 0; i < n; ++i) { + String line = trim(chop_by_delim(input, '\n')); + String string_id = trim(chop_word(&line)); + Vec2f point; + point.x = strtof(string_to_cstr(memory, trim(chop_word(&line))), NULL); + point.y = strtof(string_to_cstr(memory, trim(chop_word(&line))), NULL); + Color color = hexs(trim(chop_word(&line))); + + memset(id, 0, ENTITY_MAX_ID_SIZE); + memcpy( + id, + string_id.data, + min_size_t(ENTITY_MAX_ID_SIZE - 1, string_id.count)); + + dynarray_push(&point_layer->positions, &point); + dynarray_push(&point_layer->colors, &color); + dynarray_push(&point_layer->ids, id); + } + + point_layer->selection = -1; + point_layer->color_picker = create_color_picker_from_rgba(COLOR_RED); + + return point_layer; +} + void destroy_point_layer(PointLayer *point_layer) { trace_assert(point_layer);