aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libsok/sok-ctx.c32
-rw-r--r--src/libsok/sok.h35
2 files changed, 63 insertions, 4 deletions
diff --git a/src/libsok/sok-ctx.c b/src/libsok/sok-ctx.c
index ec36d2a..84fe8ed 100644
--- a/src/libsok/sok-ctx.c
+++ b/src/libsok/sok-ctx.c
@@ -547,6 +547,10 @@ bool sok_ctx_walk(
}
}
+ if (cbs->on_walls_start && !cbs->on_walls_start(ctx, data)) {
+ return false;
+ }
+
if (cbs->on_wall) {
// walk walls
for (size_t i = 0; i < (ctx->level.size.x * ctx->level.size.y); i++) {
@@ -564,6 +568,14 @@ bool sok_ctx_walk(
}
}
+ if (cbs->on_walls_end && !cbs->on_walls_end(ctx, data)) {
+ return false;
+ }
+
+ if (cbs->on_goals_start && !cbs->on_goals_start(ctx, data)) {
+ return false;
+ }
+
if (cbs->on_goal) {
// walk goals
for (size_t i = 0; i < ctx->level.num_goals; i++) {
@@ -577,6 +589,14 @@ bool sok_ctx_walk(
}
}
+ if (cbs->on_goals_end && !cbs->on_goals_end(ctx, data)) {
+ return false;
+ }
+
+ if (cbs->on_boxes_start && !cbs->on_boxes_start(ctx, data)) {
+ return false;
+ }
+
if (cbs->on_box) {
// walk boxes
for (size_t i = 0; i < ctx->level.num_boxes; i++) {
@@ -589,6 +609,14 @@ bool sok_ctx_walk(
}
}
+ if (cbs->on_boxes_end && !cbs->on_boxes_end(ctx, data)) {
+ return false;
+ }
+
+ if (cbs->on_moves_start && !cbs->on_moves_start(ctx, data)) {
+ return false;
+ }
+
if (cbs->on_move) {
// walk moves
for (size_t i = 0; i < ctx->num_moves; i++) {
@@ -599,6 +627,10 @@ bool sok_ctx_walk(
}
}
+ if (cbs->on_moves_end && !cbs->on_moves_end(ctx, data)) {
+ return false;
+ }
+
// return success
return true;
}
diff --git a/src/libsok/sok.h b/src/libsok/sok.h
index 4fbae72..1503b5f 100644
--- a/src/libsok/sok.h
+++ b/src/libsok/sok.h
@@ -24,6 +24,15 @@ typedef enum {
SOK_DIR_LAST,
} sok_dir_t;
+#define SOK_DIR_TO_CHAR(dir) ( \
+ ((dir) == SOK_DIR_RIGHT) ? 'r' : \
+ (((dir) == SOK_DIR_UP) ? 'u' : \
+ ((((dir) == SOK_DIR_LEFT) ? 'l' : \
+ (((((dir) == SOK_DIR_DOWN) ? 'd' : \
+ 'X' \
+)))))))
+
+
#define SOK_DIR_TO_STR(dir) ( \
((dir) == SOK_DIR_RIGHT) ? "r" : \
(((dir) == SOK_DIR_UP) ? "u" : \
@@ -149,6 +158,11 @@ _Bool sok_ctx_undo(sok_ctx_t * const);
/* context walker */
/******************/
+typedef _Bool (*sok_ctx_walk_step_cb_t)(
+ const sok_ctx_t * const,
+ void * const
+);
+
typedef _Bool (*sok_ctx_walk_pos_cb_t)(
const sok_ctx_t * const,
const sok_pos_t,
@@ -177,11 +191,24 @@ typedef _Bool (*sok_ctx_walk_move_cb_t)(
);
typedef struct {
- sok_ctx_walk_pos_cb_t on_size,
- on_wall;
- sok_ctx_walk_tile_cb_t on_home,
- on_box;
+ sok_ctx_walk_pos_cb_t on_size;
+
+ sok_ctx_walk_step_cb_t on_walls_start,
+ on_walls_end;
+ sok_ctx_walk_pos_cb_t on_wall;
+
+ sok_ctx_walk_tile_cb_t on_home;
+
+ sok_ctx_walk_step_cb_t on_boxes_start,
+ on_boxes_end;
+ sok_ctx_walk_tile_cb_t on_box;
+
+ sok_ctx_walk_step_cb_t on_goals_start,
+ on_goals_end;
sok_ctx_walk_goal_cb_t on_goal;
+
+ sok_ctx_walk_step_cb_t on_moves_start,
+ on_moves_end;
sok_ctx_walk_move_cb_t on_move;
} sok_ctx_walk_cbs_t;