aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libsok/sok-ctx.c (renamed from src/sok-ctx.c)0
-rw-r--r--src/libsok/sok-level-parser.c (renamed from src/sok-level-parser.c)107
-rw-r--r--src/libsok/sok.h (renamed from src/sok.h)0
-rw-r--r--src/sdl/main.c3
-rw-r--r--src/text/main.c (renamed from src/cli-main.c)6
5 files changed, 76 insertions, 40 deletions
diff --git a/src/sok-ctx.c b/src/libsok/sok-ctx.c
index de22d1e..de22d1e 100644
--- a/src/sok-ctx.c
+++ b/src/libsok/sok-ctx.c
diff --git a/src/sok-level-parser.c b/src/libsok/sok-level-parser.c
index eec08c3..75ac133 100644
--- a/src/sok-level-parser.c
+++ b/src/libsok/sok-level-parser.c
@@ -4,6 +4,19 @@
#define UNUSED(a) ((void) (a))
+#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
+#define CASE_DIGIT \
+ case '0': \
+ case '1': \
+ case '2': \
+ case '3': \
+ case '4': \
+ case '5': \
+ case '6': \
+ case '7': \
+ case '8': \
+ case '9':
+
void
sok_level_parser_init(
sok_level_parser_t * const parser,
@@ -22,7 +35,7 @@ sok_level_parser_parse(
) {
sok_pos_t size = { .x = 0, .y = 0 };
- for (size_t i = 0, w = 0; i < buf_len; i++) {
+ for (size_t i = 0, ofs = 0, w = 0; i < buf_len; i++) {
if (buf[i] == '|') {
if (w > size.x) {
size.x = w;
@@ -31,6 +44,11 @@ sok_level_parser_parse(
// reset column position, increment row count
w = 0;
size.y++;
+ } else if (IS_DIGIT(buf[i])) {
+ ofs = 10 * ofs + (buf[i] - '0');
+ } else if (ofs > 0) {
+ w += ofs;
+ ofs = 0;
} else {
w++;
}
@@ -49,7 +67,7 @@ sok_level_parser_parse(
}
sok_pos_t pos = { 0, 0 };
- for (size_t i = 0; i < buf_len; i++) {
+ for (size_t i = 0, ofs = 0; i < buf_len; i++) {
switch (buf[i]) {
case '|':
// new line
@@ -57,11 +75,14 @@ sok_level_parser_parse(
pos.y++;
break;
+ CASE_DIGIT
+ ofs = 10 * ofs + (buf[i] - '0');
+ break;
case '-':
case '_':
case ' ':
// advance
- pos.x++;
+ pos.x += (ofs > 0) ? ofs : 1;
break;
case '+':
@@ -93,53 +114,65 @@ sok_level_parser_parse(
break;
case '#':
- // emit wall
- if (parser->cbs->on_wall && !parser->cbs->on_wall(parser, pos)) {
- // return failure
- return false;
+ for (size_t j = (ofs > 0) ? ofs : 1; j; j--) {
+ // emit wall
+ if (parser->cbs->on_wall && !parser->cbs->on_wall(parser, pos)) {
+ // return failure
+ return false;
+ }
+
+ // advance
+ pos.x++;
}
-
- // advance
- pos.x++;
+ ofs = 0;
break;
case '*':
- // emit goal
- if (parser->cbs->on_goal && !parser->cbs->on_goal(parser, pos)) {
- // return failure
- return false;
- }
-
- // emit box
- if (parser->cbs->on_box && !parser->cbs->on_box(parser, pos)) {
- // return failure
- return false;
+ for (size_t j = (ofs > 0) ? ofs : 1; j--;) {
+ // emit goal
+ if (parser->cbs->on_goal && !parser->cbs->on_goal(parser, pos)) {
+ // return failure
+ return false;
+ }
+
+ // emit box
+ if (parser->cbs->on_box && !parser->cbs->on_box(parser, pos)) {
+ // return failure
+ return false;
+ }
+
+ // advance
+ pos.x++;
}
-
- // advance
- pos.x++;
+ ofs = 0;
break;
case '.':
- // emit goal
- if (parser->cbs->on_goal && !parser->cbs->on_goal(parser, pos)) {
- // return failure
- return false;
+ for (size_t j = (ofs > 0) ? ofs : 1; j--;) {
+ // emit goal
+ if (parser->cbs->on_goal && !parser->cbs->on_goal(parser, pos)) {
+ // return failure
+ return false;
+ }
+
+ // advance
+ pos.x++;
}
-
- // advance
- pos.x++;
+ ofs = 0;
break;
case '$':
- // emit box
- if (parser->cbs->on_box && !parser->cbs->on_box(parser, pos)) {
- // return failure
- return false;
+ for (size_t j = (ofs > 0) ? ofs : 1; j--;) {
+ // emit box
+ if (parser->cbs->on_box && !parser->cbs->on_box(parser, pos)) {
+ // return failure
+ return false;
+ }
+
+ // advance
+ pos.x++;
}
-
- // advance
- pos.x++;
+ ofs = 0;
break;
default:
diff --git a/src/sok.h b/src/libsok/sok.h
index 7635ead..7635ead 100644
--- a/src/sok.h
+++ b/src/libsok/sok.h
diff --git a/src/sdl/main.c b/src/sdl/main.c
new file mode 100644
index 0000000..0fb4389
--- /dev/null
+++ b/src/sdl/main.c
@@ -0,0 +1,3 @@
+int main(int argc, char *argv[]) {
+ return 0;
+}
diff --git a/src/cli-main.c b/src/text/main.c
index c68908c..bcf53a1 100644
--- a/src/cli-main.c
+++ b/src/text/main.c
@@ -2,14 +2,14 @@
#include <string.h> // atoi()
#include <stdlib.h> // EXIT_{FAILURE,SUCCESS}
#include <stdio.h>
-#include "sok.h"
+#include "../libsok/sok.h"
#define UNUSED(a) ((void) (a))
static const char * const
LEVELS[] = {
- "#####|#@$.#|#####|",
- "#######|###.###|###$###|#.$@$.#|###$###|###.###|#######",
+ "5#|#@$.#|5#",
+ "7#|3#.3#|3#$3#|#.$@$.#|3#$3#|3#.3#|7#",
};
#define NUM_LEVELS (sizeof(LEVELS) / sizeof(char*))