summary refs log tree commit diff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 6b195b4..8fc400f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -39,6 +39,8 @@ struct entity player[1] = {0};
 struct entity *player_new(void);
 int player_property(struct entity *const restrict entity, char const *const restrict property, char const *const restrict value);
 
+void funs_init(void);
+
 int main(int const argc, char *const *const argv) {
 	struct option opts[] = {
 		{"help",       0, NULL, 'h'},
@@ -156,6 +158,7 @@ int main(int const argc, char *const *const argv) {
 	
 	{
 		res_init();
+		funs_init();
 		if (optind == argc) {
 			void *a = util_executableRelativePath("assets.res", *argv, 0);
 			puts(a);
@@ -175,6 +178,55 @@ int main(int const argc, char *const *const argv) {
 		}
 		struct blob map = res_get_map("untitled");
 		tilemap = tilemap_load(map.data, map.size);
+		char *a = (char *) map.data + tilemap->input_bytes;
+		map.size -= tilemap->input_bytes;
+		while (map.size) {
+			size_t len;
+			if ((len = strnlen(a, map.size)) == map.size) {
+				return 1; // hack
+			}
+			char *name = a;
+			puts(name);
+			struct entity *(*fun)(void) = res_get_newfun(name);
+			a += len + 1;
+			map.size -= len + 1;
+			if (fun) {
+				struct entity *entity = fun();
+				while (1) {
+					if ((len = strnlen(a, map.size)) == map.size) {
+						return 1; // hack
+					} else if (len == 0) {
+						a++;
+						map.size--;
+						break;
+					}
+					char *key = a;
+					a += len + 1;
+					map.size -= len + 1;
+					if ((len = strnlen(a, map.size)) == map.size) {
+						return 1; // hack
+					}
+					char *value = a;
+					a += len + 1;
+					map.size -= len + 1;
+					if (res_get_setfun(name)(entity, key, value)) {
+						return 1; // hack
+					}
+				}
+			} else {
+				while (1) { // hack
+					if ((len = strnlen(a, map.size)) == map.size) { // hack
+						return 1; // hack
+					} else if (len == 0) {
+						a++;
+						map.size--;
+						break;
+					}
+					a += len + 1;
+					map.size -= len + 1;
+				}
+			}
+		}
 		//memmem(map.data + tilemap->byte_count, map.size - tilemap->byte_count, (char []) {0, 0}, 2);
 		printf("load_tilemap %p\n", (void *) tilemap);
 		SDL_SetRenderTarget(renderer, NULL);