]> git.lizzy.rs Git - nothing.git/blobdiff - src/game/level/level_editor/player_layer.c
Delete LineStream from the existance
[nothing.git] / src / game / level / level_editor / player_layer.c
index 4b50a00b40e38621a5353338e98f865a9933cd1c..0e7bd8d8e635a9920e7e66ae07c37ba7e84eca3c 100644 (file)
@@ -8,17 +8,18 @@
 #include "system/nth_alloc.h"
 #include "system/log.h"
 #include "undo_history.h"
+#include "system/memory.h"
 
 typedef struct {
     PlayerLayer *layer;
-    Point position;
+    Vec2f position;
     Color color;
-} UndoContext;
+} PlayerUndoContext;
 
 static
-UndoContext player_layer_create_undo_context(PlayerLayer *player_layer)
+PlayerUndoContext player_layer_create_undo_context(PlayerLayer *player_layer)
 {
-    UndoContext context = {
+    PlayerUndoContext context = {
         .layer = player_layer,
         .position = player_layer->position,
         .color = player_layer->prev_color
@@ -31,9 +32,9 @@ static
 void player_layer_undo(void *context, size_t context_size)
 {
     trace_assert(context);
-    trace_assert(sizeof(UndoContext) == context_size);
+    trace_assert(sizeof(PlayerUndoContext) == context_size);
 
-    UndoContext *undo_context = context;
+    PlayerUndoContext *undo_context = context;
     PlayerLayer *player_layer = undo_context->layer;
 
     player_layer->position = undo_context->position;
@@ -41,7 +42,7 @@ void player_layer_undo(void *context, size_t context_size)
     player_layer->prev_color = undo_context->color;
 }
 
-PlayerLayer create_player_layer(Vec position, Color color)
+PlayerLayer create_player_layer(Vec2f position, Color color)
 {
     return (PlayerLayer) {
         .position = position,
@@ -50,27 +51,17 @@ PlayerLayer create_player_layer(Vec position, Color color)
     };
 }
 
-PlayerLayer create_player_layer_from_line_stream(LineStream *line_stream)
+PlayerLayer chop_player_layer(Memory *memory, String *input)
 {
-    trace_assert(line_stream);
+    trace_assert(memory);
+    trace_assert(input);
 
-    const char *line = line_stream_next(line_stream);
-    trace_assert(line);
+    String line = chop_by_delim(input, '\n');
+    float x = strtof(string_to_cstr(memory, chop_word(&line)), NULL);
+    float y = strtof(string_to_cstr(memory, chop_word(&line)), NULL);
+    Color color = hexs(chop_word(&line));
 
-    char colorstr[7] = "000000";
-    Point 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));
+    return create_player_layer(vec(x, y), color);
 }
 
 LayerPtr player_layer_as_layer(PlayerLayer *player_layer)
@@ -129,7 +120,7 @@ int player_layer_event(PlayerLayer *player_layer,
     }
 
     if (selected && !color_picker_drag(&player_layer->color_picker)) {
-        UndoContext context =
+        PlayerUndoContext context =
             player_layer_create_undo_context(player_layer);
         undo_history_push(
             undo_history,
@@ -143,7 +134,7 @@ int player_layer_event(PlayerLayer *player_layer,
         event->type == SDL_MOUSEBUTTONDOWN &&
         event->button.button == SDL_BUTTON_LEFT) {
 
-        UndoContext context =
+        PlayerUndoContext context =
             player_layer_create_undo_context(player_layer);
 
         undo_history_push(