save/load
authorhgn <hgodden00@gmail.com>
Thu, 11 Nov 2021 23:24:09 +0000 (23:24 +0000)
committerhgn <hgodden00@gmail.com>
Thu, 11 Nov 2021 23:24:09 +0000 (23:24 +0000)
fishladder.c

index 4817bdf9a2a20004f7795879f8f96c918fe4b910..09bcf43e605f77f8ec421d7087c300aaaec073ee 100644 (file)
@@ -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
        {