3 #include "system/stacktrace.h"
4 #include "system/line_stream.h"
5 #include "system/log.h"
7 #include "system/nth_alloc.h"
8 #include "system/str.h"
10 #include "game/camera.h"
11 #include "./point_layer.h"
21 // TODO(#837): PointLayer does not allow to edit itself
23 PointLayer *create_point_layer_from_line_stream(LineStream *line_stream)
25 trace_assert(line_stream);
32 PointLayer *point_layer = PUSH_LT(lt, nth_calloc(1, sizeof(PointLayer)), free);
33 if (point_layer == NULL) {
38 point_layer->points = PUSH_LT(lt, create_dynarray(sizeof(Point)), destroy_dynarray);
39 if (point_layer->points == NULL) {
43 point_layer->colors = PUSH_LT(lt, create_dynarray(sizeof(Color)), destroy_dynarray);
44 if (point_layer->colors == NULL) {
48 point_layer->ids = PUSH_LT(lt, create_dynarray(sizeof(char) * ID_MAX_SIZE), destroy_dynarray);
49 if (point_layer->ids == NULL) {
55 line_stream_next(line_stream),
58 log_fail("Could not read amount of points");
65 for (size_t i = 0; i < count; ++i) {
67 line_stream_next(line_stream),
68 "%"STRINGIFY(ID_MAX_SIZE)"s%f%f%6s",
69 id, &x, &y, color_name) < 0) {
70 log_fail("Could not read %dth goal\n", i);
73 const Color color = hexstr(color_name);
74 const Point point = vec(x, y);
76 dynarray_push(point_layer->colors, &color);
77 dynarray_push(point_layer->points, &point);
78 dynarray_push(point_layer->ids, id);
84 void destroy_point_layer(PointLayer *point_layer)
86 trace_assert(point_layer);
87 RETURN_LT0(point_layer->lt);
90 int point_layer_render(const PointLayer *point_layer,
93 trace_assert(point_layer);
99 int point_layer_mouse_button(PointLayer *point_layer,
100 const SDL_MouseButtonEvent *event)
102 trace_assert(point_layer);
104 log_info("Clicked %d %d\n", event->x, event->y);
109 int point_layer_event(PointLayer *point_layer,
110 const SDL_Event *event)
112 trace_assert(point_layer);
117 size_t point_layer_count(const PointLayer *point_layer)
119 trace_assert(point_layer);
120 return dynarray_count(point_layer->points);
123 const Point *point_layer_points(const PointLayer *point_layer)
125 trace_assert(point_layer);
126 return dynarray_data(point_layer->points);
129 const Color *point_layer_colors(const PointLayer *point_layer)
131 trace_assert(point_layer);
132 return dynarray_data(point_layer->colors);
135 const char *point_layer_ids(const PointLayer *point_layer)
137 trace_assert(point_layer);
138 return dynarray_data(point_layer->ids);