From 155f3c26eb39c89057d52d72b45898819edfe640 Mon Sep 17 00:00:00 2001 From: hgn Date: Thu, 11 Nov 2021 23:24:09 +0000 Subject: [PATCH] save/load --- fishladder.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/fishladder.c b/fishladder.c index 4817bdf..09bcf43 100644 --- a/fishladder.c +++ b/fishladder.c @@ -336,22 +336,20 @@ static int map_load( const char *str ) // Tile initialization // row[ cx ] .. etc + struct cell *cell = &row[ cx ]; if( *c == '+' || *c == '-' ) { struct cell_terminal term = { .id = cx + world.h*world.w }; arrpush( world.io, term ); - row[ cx ++ ].state = *c == '+'? FLAG_INPUT: FLAG_OUTPUT; + cell->state = *c == '+'? FLAG_INPUT: FLAG_OUTPUT; reg_end ++; } - else if( *c == '#' ) - { - row[ cx ++ ].state = FLAG_WALL; - } - else - { - row[ cx ++ ].state = 0x00; - } + else if( *c == '#' ) cell->state = FLAG_WALL; + else if( *c == '*' ) cell->state = FLAG_CANAL; + else cell->state = 0x00; + + cx ++; } c ++; @@ -432,7 +430,7 @@ static void console_save_map( int argc, char *argv[] ) { if( argc >= 1 ) { - FILE *test_writer = fopen( argv[0], "w" ); + FILE *test_writer = fopen( argv[0], "wb" ); if( test_writer ) { map_serialize( test_writer ); @@ -442,12 +440,30 @@ static void console_save_map( int argc, char *argv[] ) } } +static void console_load_map( int argc, char *argv[] ) +{ + if( argc >= 1 ) + { + char *text_source = vg_textasset_read( argv[0] ); + + if( text_source ) + map_load( text_source ); + + free( text_source ); + } +} + void vg_start(void) { vg_function_push( (struct vg_cmd){ - .name = "save_map", + .name = "map_write", .function = console_save_map }); + + vg_function_push( (struct vg_cmd){ + .name = "map_load", + .function = console_load_map + }); // Quad mesh { -- 2.25.1