improved formatting

This commit is contained in:
Luka Jankovic 2025-09-26 20:33:55 +02:00
parent 737ba58860
commit ccdd081d36
12 changed files with 46 additions and 37 deletions

View file

@ -24,8 +24,8 @@
#include <raylib.h> #include <raylib.h>
#include "kubo_context.h"
#include "kubo_command_bar.h" #include "kubo_command_bar.h"
#include "kubo_context.h"
void kubo_bar_render(struct kubo_context *context, bool snap_enabled); void kubo_bar_render(struct kubo_context *context, bool snap_enabled);

View file

@ -41,7 +41,7 @@ void kubo_camera_shift(Camera2D *camera, Vector2 delta) {
} }
void kubo_camera_reset(Camera2D *camera) { void kubo_camera_reset(Camera2D *camera) {
camera->target = (Vector2){.x = 0, .y = 0}; camera->target = (Vector2){ .x = 0, .y = 0 };
camera->offset = (Vector2){.x = 0, .y = 0}; camera->offset = (Vector2){ .x = 0, .y = 0 };
camera->zoom = 1.0f; camera->zoom = 1.0f;
} }

View file

@ -23,9 +23,10 @@ static inline void kubo_command_write(struct kubo_context *context, char *rest);
static inline void kubo_command_read(struct kubo_context *context, char *rest); static inline void kubo_command_read(struct kubo_context *context, char *rest);
static const struct kubo_command_data kubo_commands[] = { static const struct kubo_command_data kubo_commands[] = {
{":q", kubo_command_exit}, { ":q", kubo_command_exit },
{":w", kubo_command_write}, { ":w", kubo_command_write },
{":e", kubo_command_read}}; { ":e", kubo_command_read }
};
static const size_t kubo_commands_size = static const size_t kubo_commands_size =
sizeof(kubo_commands) / sizeof(kubo_commands[0]); sizeof(kubo_commands) / sizeof(kubo_commands[0]);

View file

@ -19,10 +19,11 @@
#include "kubo_context.h" #include "kubo_context.h"
static const struct kubo_context_state_data kubo_context_states[] = { static const struct kubo_context_state_data kubo_context_states[] = {
{.id = KUBO_CONTEXT_NORMAL, .label = "Normal", .color = BLACK}, { .id = KUBO_CONTEXT_NORMAL, .label = "Normal", .color = BLACK },
{.id = KUBO_CONTEXT_COMMAND, .label = "Command", .color = RED}, { .id = KUBO_CONTEXT_COMMAND, .label = "Command", .color = RED },
{.id = KUBO_CONTEXT_WALL_NEW, .label = "Wall New", .color = GREEN}, { .id = KUBO_CONTEXT_WALL_NEW, .label = "Wall New", .color = GREEN },
{.id = KUBO_CONTEXT_WALL_SELECT, .label = "Wall Select", .color = BLUE}}; { .id = KUBO_CONTEXT_WALL_SELECT, .label = "Wall Select", .color = BLUE }
};
void kubo_context_init(struct kubo_context *context) { void kubo_context_init(struct kubo_context *context) {
@ -45,16 +46,16 @@ void kubo_context_set_state(struct kubo_context *context,
enum kubo_context_state state) { enum kubo_context_state state) {
context->state = kubo_context_states[state]; context->state = kubo_context_states[state];
switch (context->state.id) { // switch (context->state.id) {
case KUBO_CONTEXT_COMMAND: // case KUBO_CONTEXT_COMMAND:
break; // break;
//
case KUBO_CONTEXT_WALL_NEW: // case KUBO_CONTEXT_WALL_NEW:
break; // break;
//
default: // default:
break; // break;
} // }
for (unsigned i = 0; i < kubo_state_data_length; i++) { for (unsigned i = 0; i < kubo_state_data_length; i++) {
if (context->state.id == kubo_state_data[i].id && if (context->state.id == kubo_state_data[i].id &&

View file

@ -24,8 +24,8 @@ struct kubo_context kubo_file_parse(char *file_name) {
struct kubo_wall *wall = malloc(sizeof(struct kubo_wall)); struct kubo_wall *wall = malloc(sizeof(struct kubo_wall));
kubo_wall_init(wall); kubo_wall_init(wall);
for (size_t j = 0; j < scene->walls[i].vertices_count; j++) { for (size_t j = 0; j < scene->walls[i].vertices_count; j++) {
Vector2 vertex = {.x = scene->walls[i].vertices[j][0], Vector2 vertex = { .x = scene->walls[i].vertices[j][0],
.y = scene->walls[i].vertices[j][1]}; .y = scene->walls[i].vertices[j][1] };
kubo_wall_add_vertex(wall, vertex); kubo_wall_add_vertex(wall, vertex);
} }

View file

@ -49,7 +49,8 @@ static const cyaml_schema_value_t vertex_entry = {
static const cyaml_schema_field_t wall_fields[] = { static const cyaml_schema_field_t wall_fields[] = {
CYAML_FIELD_SEQUENCE("vertices", CYAML_FLAG_POINTER, struct kubo_file_wall, CYAML_FIELD_SEQUENCE("vertices", CYAML_FLAG_POINTER, struct kubo_file_wall,
vertices, &vertex_entry, 0, CYAML_UNLIMITED), vertices, &vertex_entry, 0, CYAML_UNLIMITED),
CYAML_FIELD_END}; CYAML_FIELD_END
};
static const cyaml_schema_value_t wall_schema = { static const cyaml_schema_value_t wall_schema = {
CYAML_VALUE_MAPPING(CYAML_FLAG_DEFAULT, struct kubo_file_wall, wall_fields), CYAML_VALUE_MAPPING(CYAML_FLAG_DEFAULT, struct kubo_file_wall, wall_fields),
@ -58,7 +59,8 @@ static const cyaml_schema_value_t wall_schema = {
static const cyaml_schema_field_t scene_fields[] = { static const cyaml_schema_field_t scene_fields[] = {
CYAML_FIELD_SEQUENCE("walls", CYAML_FLAG_POINTER, struct kubo_file_scene, CYAML_FIELD_SEQUENCE("walls", CYAML_FLAG_POINTER, struct kubo_file_scene,
walls, &wall_schema, 0, CYAML_UNLIMITED), walls, &wall_schema, 0, CYAML_UNLIMITED),
CYAML_FIELD_END}; CYAML_FIELD_END
};
static const cyaml_schema_value_t top_schema = { static const cyaml_schema_value_t top_schema = {
CYAML_VALUE_MAPPING(CYAML_FLAG_POINTER, struct kubo_file_scene, CYAML_VALUE_MAPPING(CYAML_FLAG_POINTER, struct kubo_file_scene,

View file

@ -113,25 +113,25 @@ static void handle_camera_input(int key_code, Camera2D *camera) {
case KEY_RIGHT: case KEY_RIGHT:
case KEY_L: case KEY_L:
kubo_camera_shift(camera, kubo_camera_shift(camera,
(Vector2){.x = -KUBO_INPUT_CAMERA_SHIFT, .y = 0}); (Vector2){ .x = -KUBO_INPUT_CAMERA_SHIFT, .y = 0 });
break; break;
case KEY_UP: case KEY_UP:
case KEY_K: case KEY_K:
kubo_camera_shift(camera, kubo_camera_shift(camera,
(Vector2){.x = 0, .y = KUBO_INPUT_CAMERA_SHIFT}); (Vector2){ .x = 0, .y = KUBO_INPUT_CAMERA_SHIFT });
break; break;
case KEY_LEFT: case KEY_LEFT:
case KEY_H: case KEY_H:
kubo_camera_shift(camera, kubo_camera_shift(camera,
(Vector2){.x = KUBO_INPUT_CAMERA_SHIFT, .y = 0}); (Vector2){ .x = KUBO_INPUT_CAMERA_SHIFT, .y = 0 });
break; break;
case KEY_DOWN: case KEY_DOWN:
case KEY_J: case KEY_J:
kubo_camera_shift(camera, kubo_camera_shift(camera,
(Vector2){.x = 0, .y = -KUBO_INPUT_CAMERA_SHIFT}); (Vector2){ .x = 0, .y = -KUBO_INPUT_CAMERA_SHIFT });
break; break;
default: default:
break; break;

View file

@ -40,7 +40,8 @@ Vector2 kubo_wall_get_vertex(struct kubo_wall *wall, size_t index) {
return kubo_vector2_arr_get(&wall->vertices, index); return kubo_vector2_arr_get(&wall->vertices, index);
} }
void kubo_wall_render(struct kubo_wall *wall, bool select, Camera2D *camera, Vector2 mouse) { void kubo_wall_render(struct kubo_wall *wall, bool select, Camera2D *camera,
Vector2 mouse) {
(void)camera; (void)camera;
Color wall_color = Color wall_color =
(select && wall->state == KUBO_WALL_SELECTED) ? BLUE : BLACK; (select && wall->state == KUBO_WALL_SELECTED) ? BLUE : BLACK;
@ -56,7 +57,7 @@ void kubo_wall_render(struct kubo_wall *wall, bool select, Camera2D *camera, Vec
if (wall->state == KUBO_WALL_DRAWING) { if (wall->state == KUBO_WALL_DRAWING) {
// Vector2 mouse = GetScreenToWorld2D(mouse, *camera); // Vector2 mouse = GetScreenToWorld2D(mouse, *camera);
Vector2 mouse_points[] = {points[wall->vertices.count - 1], mouse}; Vector2 mouse_points[] = { points[wall->vertices.count - 1], mouse };
DrawSplineLinear(mouse_points, 2, 10.f, wall_color); DrawSplineLinear(mouse_points, 2, 10.f, wall_color);
} }

View file

@ -47,6 +47,7 @@ void kubo_wall_cleanup(struct kubo_wall *wall);
bool kubo_wall_add_vertex(struct kubo_wall *wall, Vector2 vec); bool kubo_wall_add_vertex(struct kubo_wall *wall, Vector2 vec);
Vector2 kubo_wall_get_vertex(struct kubo_wall *wall, size_t index); Vector2 kubo_wall_get_vertex(struct kubo_wall *wall, size_t index);
void kubo_wall_render(struct kubo_wall *wall, bool select, Camera2D *camera, Vector2 mouse); void kubo_wall_render(struct kubo_wall *wall, bool select, Camera2D *camera,
Vector2 mouse);
#endif #endif

View file

@ -19,7 +19,7 @@
#include "kubo_window.h" #include "kubo_window.h"
#include "raylib.h" #include "raylib.h"
Camera2D camera = {0}; Camera2D camera = { 0 };
bool kubo_mouse_snap = false; bool kubo_mouse_snap = false;
static void window_render(struct kubo_context *context, Vector2 mouse_pos); static void window_render(struct kubo_context *context, Vector2 mouse_pos);
@ -154,7 +154,8 @@ static void new_wall_end(struct kubo_context *context) {
static Vector2 mouse_grid_snap(Vector2 mouse_pos) { static Vector2 mouse_grid_snap(Vector2 mouse_pos) {
Vector2 snap_pos = { Vector2 snap_pos = {
.x = round(mouse_pos.x / KUBO_GRID_SIZE) * KUBO_GRID_SIZE, .x = round(mouse_pos.x / KUBO_GRID_SIZE) * KUBO_GRID_SIZE,
.y = round(mouse_pos.y / KUBO_GRID_SIZE) * KUBO_GRID_SIZE}; .y = round(mouse_pos.y / KUBO_GRID_SIZE) * KUBO_GRID_SIZE
};
return snap_pos; return snap_pos;
} }

2
main.c
View file

@ -26,7 +26,7 @@
#include "kubo_file.h" #include "kubo_file.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
kubo_command_init(); kubo_command_init();
struct kubo_context context; struct kubo_context context;

View file

@ -36,9 +36,11 @@ struct kubo_state_list_entry {
}; };
static const struct kubo_state_list_entry kubo_state_data[] = { static const struct kubo_state_list_entry kubo_state_data[] = {
{KUBO_CONTEXT_NORMAL, kubo_state_normal_data}, { KUBO_CONTEXT_NORMAL, kubo_state_normal_data },
{KUBO_CONTEXT_COMMAND, kubo_state_command_data}, { KUBO_CONTEXT_COMMAND, kubo_state_command_data },
{KUBO_CONTEXT_WALL_SELECT, kubo_state_wall_select_data}}; { KUBO_CONTEXT_WALL_NEW, kubo_state_wall_select_data },
{ KUBO_CONTEXT_WALL_SELECT, kubo_state_wall_select_data }
};
static const unsigned kubo_state_data_length = static const unsigned kubo_state_data_length =
sizeof(kubo_state_data) / sizeof(kubo_state_data[0]); sizeof(kubo_state_data) / sizeof(kubo_state_data[0]);