image fail box
[carveJwlIkooP6JGAAIwe30JlM.git] / workshop.c
index cf0e25a8628e43c384ad5dded311ff9dc0fb4610..8c24e03b308de083eabef432d6ae4f22cb3c1c35 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef WORKSHOP_C
 #define WORKSHOP_C
 
+#include "workshop.h"
+
 #define VG_GAME
 #include "vg/vg.h"
 #include "vg/vg_tex.h"
 #include "steam.h"
 #include "highscores.h"
 
-#define WORKSHOP_VIEW_PER_PAGE 15
-
-struct workshop_form{
-   struct {
-      char title[80];
-      char description[512];
-      char author[32];
-      struct ui_dropdown_value submission_type_selection;
-      enum workshop_file_type type;
-
-      PublishedFileId_t file_id; /* 0 if not published yet */
-
-      struct ui_dropdown_value visibility;
-      int submit_title,       /* set if the respective controls are touched */
-          submit_description,
-          submit_file_and_image;
-   } 
-   submission;
-
-   enum workshop_form_page{
-      k_workshop_form_hidden, 
-      k_workshop_form_open,      /* open but not looking at anything */
-      k_workshop_form_edit,      /* editing a submission */
-      k_workshop_form_cclosing,
-      k_workshop_form_closing_good, /* post upload screen */
-      k_workshop_form_closing_bad,  
-   }
-   page;
-
-   /* model viewer 
-    * -----------------------------
-    */
-
-   char addon_folder[128];
-   struct player_board board_model;
-
-   /* what does the user want to do with the image preview? */
-   enum workshop_form_file_intent{
-      k_workshop_form_file_intent_none,         /* loading probably */
-      k_workshop_form_file_intent_new,          /* board_model is valid */
-      k_workshop_form_file_intent_keep_old      /* just browsing */
-   }
-   file_intent;
-
-   world_instance *view_world;
-   ent_swspreview *ptr_ent;
-   v2f view_angles,
-       view_angles_begin;
-   v3f view_offset,
-       view_offset_begin;
-
-   float view_dist;
-   int view_changed;
-
-   /*
-    * published UGC request
-    * ------------------------------
-    */
-
-   struct {
-      UGCQueryHandle_t handle;
-      EResult result;
-
-      int all_item_count,
-          returned_item_count;
-   }
-   ugc_query;
-
-   /* 
-    * UI information
-    * ------------------------------------------
-    */
-
-   const char *failure_or_success_string;
-
-   int img_w, img_h;
-   u8 *img_buffer;
-
-   int view_published_page_count,
-       view_published_page_id;
-
-   struct published_file{
-      EResult result;
-      int result_index;
-      char title[80];
-   }
-   published_files_list[WORKSHOP_VIEW_PER_PAGE];
-   int published_files_list_length;
-}
-static workshop_form;
-
 static struct ui_dropdown_opt workshop_form_visibility_opts[] = {
  { "Public",       k_ERemoteStoragePublishedFileVisibilityPublic },
  { "Unlisted",     k_ERemoteStoragePublishedFileVisibilityUnlisted },
@@ -428,32 +339,32 @@ VG_STATIC void _workshop_form_submit_thread( void *data )
    descriptor_str[descriptor.cur*2] = '\0';
    vg_info( "binstr: %s\n", descriptor_str );
 
-   DIR *dir = opendir( folder.buffer );
-   if( !dir ){
+   vg_dir dir;
+   if( !vg_dir_open( &dir, folder.buffer ) ){
       vg_error( "could not open addon folder '%s'\n", folder.buffer );
       vg_async_call( workshop_async_any_complete, NULL, 0 );
       return;
    }
 
-   struct dirent *entry;
-   while( (entry = readdir(dir)) ){
-      if( entry->d_type == DT_REG ){
-         if( entry->d_name[0] == '.' ) continue;
+   while( vg_dir_next_entry(&dir) ){
+      if( vg_dir_entry_type(&dir) == k_vg_entry_type_file ){
+         const char *d_name = vg_dir_entry_name(&dir);
+         if( d_name[0] == '.' ) continue;
 
          vg_str file = folder;
          vg_strcat( &file, "/" );
-         vg_strcat( &file, entry->d_name );
+         vg_strcat( &file, d_name );
          if( !vg_strgood( &file ) ) continue;
 
          char *ext = vg_strch( &file, '.' );
          if( !ext ) continue;
          if( strcmp(ext,".mdl") ) continue;
 
-         vg_msg_wkvstr( &descriptor, "content", entry->d_name );
+         vg_msg_wkvstr( &descriptor, "content", d_name );
          break;
       }
    }
-   closedir(dir);
+   vg_dir_close(&dir);
 
    vg_str descriptor_file = folder;
    vg_strcat( &descriptor_file, "/addon.inf" );
@@ -578,8 +489,8 @@ VG_STATIC void _workshop_form_load_thread( void *data )
       return;
    }
 
-   DIR *dir = opendir( folder.buffer );
-   if( !dir ){
+   vg_dir dir;
+   if( !vg_dir_open( &dir, folder.buffer ) ){
       vg_error( "workshop async load failed: could not open folder\n" );
       vg_async_call( workshop_form_loadmodel_async_error, NULL, 0 );
       return;
@@ -588,14 +499,14 @@ VG_STATIC void _workshop_form_load_thread( void *data )
    vg_info( "Searching %s for model files\n", folder.buffer );
 
    int found_mdl = 0;
-   struct dirent *entry;
-   while( (entry = readdir(dir)) ){
-      if( entry->d_type == DT_REG ){
-         if( entry->d_name[0] == '.' ) continue;
+   while( vg_dir_next_entry(&dir) ){
+      if( vg_dir_entry_type(&dir) == k_vg_entry_type_file ){
+         const char *d_name = vg_dir_entry_name(&dir);
+         if( d_name[0] == '.' ) continue;
 
          vg_str file = folder;
          vg_strcat( &file, "/" );
-         vg_strcat( &file, entry->d_name );
+         vg_strcat( &file, d_name );
          if( !vg_strgood( &file ) ) continue;
 
          char *ext = vg_strch( &file, '.' );
@@ -605,7 +516,7 @@ VG_STATIC void _workshop_form_load_thread( void *data )
          break;
       }
    }
-   closedir(dir);
+   vg_dir_close(&dir);
 
    if( !found_mdl ){
       vg_error( "workshop async load failed: no model files found\n" );
@@ -623,7 +534,19 @@ VG_STATIC void _workshop_form_load_thread( void *data )
 VG_STATIC void workshop_op_load_model(void)
 {
    if( workshop_form.submission.type == k_workshop_file_type_world ){
-      vg_error( "Currently unsupported\n" );
+      vg_warn( "WORLD LOAD INFO Currently unsupported\n" );
+      return;
+   }
+
+   workshop_form.view_world = world_current_instance();
+
+   if( mdl_arrcount( &workshop_form.view_world->ent_swspreview ) ){
+      workshop_form.ptr_ent = 
+            mdl_arritm( &workshop_form.view_world->ent_swspreview, 0 );
+   }
+   else{
+      vg_error( "There is no ent_swspreview in the level. "
+                "Cannot publish here\n" );
       return;
    }
 
@@ -652,43 +575,54 @@ VG_STATIC void workshop_form_async_imageload( void *data, u32 len )
       stbi_image_free( data );
       vg_success( "Loaded workshop preview image\n" );
    }
+   else{
+      snprintf( workshop_form.error_msg, sizeof(workshop_form.error_msg),
+               "Preview image could not be loaded. Reason: %s\n",
+                stbi_failure_reason() );
+      ui_start_modal( workshop_form.error_msg, UI_MODAL_BAD );
+   }
    
    skaterift_end_op();
 }
 
-struct workshop_loadpreview_info {
-   char abs_preview_image[ 1024 ];
-};
-
 /*
  * Load the image located at ./workshop_preview.jpg into our framebuffer
  */
 VG_STATIC void _workshop_load_preview_thread( void *data )
 {
-   struct workshop_loadpreview_info *info = data;
-
-   stbi_set_flip_vertically_on_load(1);
-   int x, y, nc;
-   u8 *rgb = stbi_load( info->abs_preview_image, &x, &y, &nc, 3 );
-
-   if( rgb ){
-      if( (x == WORKSHOP_PREVIEW_WIDTH) && (y == WORKSHOP_PREVIEW_HEIGHT) ){
-         vg_async_call( workshop_form_async_imageload, rgb, x*y*3 );
+   char path_buf[ 4096 ];
+   vg_str path;
+   vg_strnull( &path, path_buf, 4096 );
+   vg_strcat( &path, "boards/" );
+   vg_strcat( &path, workshop_form.addon_folder );
+   vg_strcat( &path, "/preview.jpg" );
+
+   if( vg_strgood( &path ) ){
+      stbi_set_flip_vertically_on_load(1);
+      int x, y, nc;
+      u8 *rgb = stbi_load( path.buffer, &x, &y, &nc, 3 );
+
+      if( rgb ){
+         if( (x == WORKSHOP_PREVIEW_WIDTH) && (y == WORKSHOP_PREVIEW_HEIGHT) ){
+            vg_async_call( workshop_form_async_imageload, rgb, x*y*3 );
+         }
+         else{
+            vg_error( "Resolution does not match framebuffer, so we can't"
+                      " show it\n" );
+            stbi_image_free( rgb );
+            vg_async_call( workshop_form_async_imageload, NULL, 0 );
+         }
       }
       else{
-         vg_error( "Resolution does not match framebuffer, so we can't"
-                   " show it\n" );
-         stbi_image_free( rgb );
          vg_async_call( workshop_form_async_imageload, NULL, 0 );
       }
    }
    else{
-      vg_error( "Failed to load workshop_preview.jpg: '%s'\n", 
-                  stbi_failure_reason() );
       vg_async_call( workshop_form_async_imageload, NULL, 0 );
    }
 }
 
+#if 0
 /*
  * Reciever for the preview download result
  */
@@ -707,6 +641,7 @@ VG_STATIC void on_workshop_download_ugcpreview( void *data, void *user )
       skaterift_end_op();
    }
 }
+#endif
 
 /*
  * Entry point to view operation
@@ -746,7 +681,7 @@ VG_STATIC void workshop_op_download_and_view_submission( int result_index )
 
       snprintf( workshop_form.addon_folder, 
                  vg_list_size( workshop_form.addon_folder ),
-                 "Steam Cloud (%lu)", details.m_nPublishedFileId );
+                 "Steam Cloud ("PRINTF_U64")", details.m_nPublishedFileId );
 
       workshop_form.submission.file_id = details.m_nPublishedFileId;
       workshop_form.file_intent = k_workshop_form_file_intent_keep_old;
@@ -761,31 +696,25 @@ VG_STATIC void workshop_op_download_and_view_submission( int result_index )
          u32 len = strlen(metadata_str);
          vg_info( "Metadata: %s\n", metadata_str );
          vg_str_bin( metadata_str, metadata_buf, len );
-         vg_msg msg;
-         vg_msg_init( &msg, metadata_buf, len/2 );
+         vg_msg root;
+         vg_msg_init( &root, metadata_buf, len/2 );
          
-         vg_msg_cmd cmd;
-         while( vg_msg_next( &msg, &cmd ) ){
-            if( (msg.depth == 1) && (cmd.code == k_vg_msg_code_frame) ){
-               if( VG_STRDJB2_EQ( "workshop", cmd.key, cmd.key_djb2 ) ){
-                  u32 depth = msg.depth;
-                  while( (msg.depth == depth) && vg_msg_next( &msg, &cmd ) ){
-                     if( cmd.code & k_vg_msg_code_unsigned ){
-                        if( VG_STRDJB2_EQ( "type", cmd.key, cmd.key_djb2 ) ){
-                           workshop_form.submission.type = cmd.value._u32;
-   workshop_form.submission.submission_type_selection.value = cmd.value._u32;
-                        }
-                     }
-                     else if( cmd.code == k_vg_msg_code_kvstring ){
-                        if( VG_STRDJB2_EQ( "folder", cmd.key, cmd.key_djb2 ) ){
-                           vg_strncpy( cmd.value._buf,
-                                       workshop_form.addon_folder,
-                                       sizeof(workshop_form.addon_folder),
-                                       k_strncpy_always_add_null );
-                        }
-                     }
-                  }
-               }
+         vg_msg workshop = root;
+         if( vg_msg_seekframe( &workshop, "workshop", k_vg_msg_first )){
+            vg_msg_cmd kv_type = vg_msg_seekkv( &workshop, "type", 
+                                                k_vg_msg_first );
+            if( kv_type.code & k_vg_msg_code_integer ){
+               u32 u = kv_type.value._u32;
+               workshop_form.submission.type = u;
+               workshop_form.submission.submission_type_selection.value = u;
+            }
+
+            const char *kv_folder = vg_msg_seekkvstr( &workshop, "folder",
+                                                      k_vg_msg_first );
+            if( kv_folder ){
+               vg_strncpy( kv_folder, workshop_form.addon_folder,
+                           sizeof(workshop_form.addon_folder),
+                           k_strncpy_always_add_null );
             }
          }
       }
@@ -808,14 +737,13 @@ VG_STATIC void workshop_op_download_and_view_submission( int result_index )
          }
       }
 
-      vg_error( "m_hPreviewFile is 0\n" );
       render_fb_bind( gpipeline.fb_workshop_preview, 0 );
       glClearColor( 0.2f, 0.0f, 0.0f, 1.0f );
       glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
       glBindFramebuffer( GL_FRAMEBUFFER, 0 );
       glViewport( 0,0, vg.window_x, vg.window_y );
 
-      skaterift_end_op();
+      vg_loader_start( _workshop_load_preview_thread, NULL );
 
 #if 0
       if( details.m_hPreviewFile == 0 ){
@@ -950,7 +878,7 @@ VG_STATIC void on_workshop_UGCQueryComplete( void *data, void *userdata )
 VG_STATIC int workshop_submit_command( int argc, const char *argv[] )
 {
    if( !steam_ready ){
-      vg_error( "Steam API is not ready or loaded\n" );
+      ui_start_modal( "Steam API is not initialized\n", UI_MODAL_BAD );
       return 0;
    }
 
@@ -988,26 +916,24 @@ VG_STATIC void workshop_init(void)
    vg_console_reg_cmd( "workshop_submit", workshop_submit_command, NULL );
 }
 
-VG_STATIC void workshop_find_preview_entity(void)
-{
-   workshop_form.view_world = world_current_instance();
+VG_STATIC void workshop_render_world_preview(void){
+   render_fb_bind( gpipeline.fb_workshop_preview, 0 );
 
-   if( mdl_arrcount( &workshop_form.view_world->ent_swspreview ) ){
-      workshop_form.ptr_ent = 
-            mdl_arritm( &workshop_form.view_world->ent_swspreview, 0 );
-      workshop_form.page = k_workshop_form_edit;
-   }
-   else{
-      vg_error( "There is no ent_swspreview in the level. "
-                "Cannot publish here\n" );
-   }
+   glClearColor( 0.0f, 0.0f, 0.3f, 1.0f );
+   glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
+   glEnable( GL_DEPTH_TEST );
+   glDisable( GL_BLEND );
+
+   render_world( localplayer.viewable_world, &main_camera, 1 );
+
+   glBindFramebuffer( GL_FRAMEBUFFER, 0 );
+   glViewport( 0,0, vg.window_x, vg.window_y );
 }
 
 /*
  * Redraw the model file into the workshop framebuffer
  */
-VG_STATIC void workshop_render_preview(void)
-{
+VG_STATIC void workshop_render_board_preview(void){
    if( !workshop_form.ptr_ent ){
       return;
    }
@@ -1112,62 +1038,65 @@ VG_STATIC void workshop_changed_description( char *buf, u32 len ){
    workshop_form.submission.submit_description = 1;
 }
 
-VG_STATIC void workshop_form_gui_edit_page( ui_rect content )
-{
-   if( workshop_form.submission.type == k_workshop_file_type_none ){
-      ui_rect box;
-      rect_copy( content, box );
-      box[3] = 128;
-      box[2] = (box[2]*2)/3;
-      ui_rect_center( content, box );
-
-      ui_rect row;
-      ui_split( box, k_ui_axis_h, 28, 0, row, box );
-      ui_text( row, "Select the type of item\n", 1, k_ui_align_middle_center,0);
-      ui_split( box, k_ui_axis_h, 28, 0, row, box );
-      ui_enum( row, "Type:", workshop_form_type_opts,
-               3, &workshop_form.submission.submission_type_selection );
-      ui_split( box, k_ui_axis_h, 8, 0, row, box );
-      ui_split( box, k_ui_axis_h, 28, 0, row, box );
-
-      ui_rect button_l, button_r;
-      rect_copy( row, button_l );
-      button_l[2] = 128*2;
-      ui_rect_center( row, button_l );
-      ui_split_ratio( button_l, k_ui_axis_v, 0.5f, 2, button_l, button_r );
-
-      if( workshop_form.submission.submission_type_selection.value !=
-            k_workshop_file_type_none ){
-         if( ui_button_text( button_l, "OK", 1 ) ){
-            workshop_form.submission.type = 
+VG_STATIC void workshop_form_gui_page_undecided( ui_rect content ){
+   ui_rect box;
+   rect_copy( content, box );
+   box[3] = 128;
+   box[2] = (box[2]*2)/3;
+   ui_rect_center( content, box );
+
+   ui_rect row;
+   ui_split( box, k_ui_axis_h, 28, 0, row, box );
+   ui_text( row, "Select the type of item\n", 1, k_ui_align_middle_center,0);
+   ui_split( box, k_ui_axis_h, 28, 0, row, box );
+   ui_enum( row, "Type:", workshop_form_type_opts,
+            3, &workshop_form.submission.submission_type_selection );
+   ui_split( box, k_ui_axis_h, 8, 0, row, box );
+   ui_split( box, k_ui_axis_h, 28, 0, row, box );
+
+   ui_rect button_l, button_r;
+   rect_copy( row, button_l );
+   button_l[2] = 128*2;
+   ui_rect_center( row, button_l );
+   ui_split_ratio( button_l, k_ui_axis_v, 0.5f, 2, button_l, button_r );
+
+   if( workshop_form.submission.submission_type_selection.value !=
+         k_workshop_file_type_none ){
+      if( ui_button_text( button_l, "OK", 1 ) ){
+         enum workshop_file_type type = 
                workshop_form.submission.submission_type_selection.value;
+         workshop_form.submission.type = type;
+
+         if( type == k_workshop_file_type_world ){
+            workshop_form.view_changed = 1;
+            workshop_form.file_intent = k_workshop_form_file_intent_new;
          }
       }
-      else{
-         ui_fill( button_l, ui_colour(k_ui_bg) );
-         ui_text( button_l, "OK", 1, k_ui_align_middle_center, 
-                  ui_colour(k_ui_bg+4) );
-      }
-      
-      if( ui_button_text( button_r, "Cancel", 1 ) ){
-         workshop_form.page = k_workshop_form_open;
-         workshop_form.file_intent = k_workshop_form_file_intent_none;
-      }
-      return;
    }
+   else{
+      ui_fill( button_l, ui_colour(k_ui_bg) );
+      ui_text( button_l, "OK", 1, k_ui_align_middle_center, 
+               ui_colour(k_ui_bg+4) );
+   }
+   
+   if( ui_button_text( button_r, "Cancel", 1 ) ){
+      workshop_form.page = k_workshop_form_open;
+      workshop_form.file_intent = k_workshop_form_file_intent_none;
+   }
+}
 
-   ui_rect image_plane;
-   ui_split( content, k_ui_axis_h, 300, 0, image_plane, content );
-   ui_fill( image_plane, ui_colour( k_ui_bg+0 ) );
-
-   ui_rect img_box;
-   ui_fit_item( image_plane, (ui_px[2]){ 3, 2 }, img_box );
-
+VG_STATIC void workshop_form_gui_draw_preview( ui_rect img_box ){
+   enum workshop_file_type type = workshop_form.submission.type;
    if( workshop_form.file_intent == k_workshop_form_file_intent_keep_old ){
       ui_image( img_box, gpipeline.fb_workshop_preview->attachments[0].id );
    }
    else if( workshop_form.file_intent == k_workshop_form_file_intent_new ){
       ui_image( img_box, gpipeline.fb_workshop_preview->attachments[0].id );
+
+      if( type == k_workshop_file_type_world ){
+         return;
+      }
+
       int hover  = ui_inside_rect( img_box, vg_ui.mouse ),
           target = ui_inside_rect( img_box, vg_ui.mouse_click );
       
@@ -1221,12 +1150,28 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content )
       ui_text( img_box, "No image", 1, k_ui_align_middle_center,
                ui_colour( k_ui_orange ) );
    }
+}
+
+VG_STATIC void workshop_form_gui_edit_page( ui_rect content ){
+   enum workshop_file_type type = workshop_form.submission.type;
+
+   if( type == k_workshop_file_type_none ){
+      workshop_form_gui_page_undecided( content );
+      return;
+   }
+
+   ui_rect image_plane;
+   ui_split( content, k_ui_axis_h, 300, 0, image_plane, content );
+   ui_fill( image_plane, ui_colour( k_ui_bg+0 ) );
+
+   ui_rect img_box;
+   ui_fit_item( image_plane, (ui_px[2]){ 3, 2 }, img_box );
+   workshop_form_gui_draw_preview( img_box );
 
    /* file path */
    ui_rect null, file_entry, file_button, file_label;
    ui_split( content, k_ui_axis_h, 8, 0, null, content );
    ui_split( content, k_ui_axis_h, 28, 0, file_entry, content );
-   ui_split( file_entry, k_ui_axis_v, -128, 0, file_entry, file_button );
 
    if( workshop_form.submission.type == k_workshop_file_type_board ){
       ui_label( file_entry, "Addon folder: skaterift/boards/", 
@@ -1237,27 +1182,36 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content )
                 1, 8, file_entry );
    }
 
-   if( workshop_form.file_intent != k_workshop_form_file_intent_none ){
-      ui_text( file_entry, workshop_form.addon_folder, 1, 
-               k_ui_align_middle_left, ui_colour( k_ui_fg+4 ) );
-
-      if( ui_button_text( file_button, "Remove", 1 ) ){
-         player_board_unload( &workshop_form.board_model );
-         workshop_form.file_intent = k_workshop_form_file_intent_none;
-         workshop_form.addon_folder[0] = '\0';
-      }
-   }
-   else{
+   if( type == k_workshop_file_type_world ){
       struct ui_textbox_callbacks callbacks = {
          .change = workshop_changed_model_path
       };
-
       ui_textbox( file_entry, workshop_form.addon_folder,
                   vg_list_size(workshop_form.addon_folder), 0, &callbacks );
+   }
+   else{
+      ui_split( file_entry, k_ui_axis_v, -128, 0, file_entry, file_button );
+      if( workshop_form.file_intent != k_workshop_form_file_intent_none ){
+         ui_text( file_entry, workshop_form.addon_folder, 1, 
+                  k_ui_align_middle_left, ui_colour( k_ui_fg+4 ) );
+
+         if( ui_button_text( file_button, "Remove", 1 ) ){
+            player_board_unload( &workshop_form.board_model );
+            workshop_form.file_intent = k_workshop_form_file_intent_none;
+            workshop_form.addon_folder[0] = '\0';
+         }
+      }
+      else{
+         struct ui_textbox_callbacks callbacks = {
+            .change = workshop_changed_model_path
+         };
 
-      if( ui_button_text( file_button, "Load", 1 ) ){
-         workshop_find_preview_entity();
-         workshop_op_load_model();
+         ui_textbox( file_entry, workshop_form.addon_folder,
+                     vg_list_size(workshop_form.addon_folder), 0, &callbacks );
+
+         if( ui_button_text( file_button, "Load", 1 ) ){
+            workshop_op_load_model();
+         }
       }
    }
 
@@ -1431,7 +1385,6 @@ VG_STATIC void workshop_form_gui_sidebar( ui_rect sidebar )
       workshop_form.submission.submit_description = 1;
       workshop_form.submission.submit_file_and_image = 1;
       workshop_form.page = k_workshop_form_edit;
-      workshop_find_preview_entity();
    }
 
    for( int i=0; i<workshop_form.published_files_list_length; i++ ){
@@ -1516,7 +1469,14 @@ VG_STATIC void workshop_form_gui(void)
        workshop_form.view_changed && 
        workshop_form.file_intent == k_workshop_form_file_intent_new )
    {
-      workshop_render_preview();
+      enum workshop_file_type type = workshop_form.submission.type;
+      if( type == k_workshop_file_type_board ){
+         workshop_render_board_preview();
+      }
+      else if( type == k_workshop_file_type_world ){
+         vg_success( "Renders world preview\n" );
+         workshop_render_world_preview();
+      }
       workshop_form.view_changed = 0;
    }
 
@@ -1606,34 +1566,4 @@ VG_STATIC void async_workshop_get_installed_files( void *data, u32 len )
    *info->len = j;
 }
 
-#if 0
-VG_STATIC void vg_strsan_ascii( char *buf, u32 len )
-{
-   for( u32 i=0; i<len-1; i ++ ){
-      if( buf[i] == 0 ) return;
-
-      if( buf[i] < 32 || buf[i] > 126 ){
-         buf[i] = '?';
-      }
-   }
-   buf[len-1] = '\0';
-}
-
-#define VG_STRSAN_ASCII( X ) vg_strsan_ascii( X, vg_list_size(X) )
-
-VG_STATIC void workshop_load_metadata( const char *path,
-                                       struct workshop_file_info *info )
-{
-   FILE *fp = fopen( path, "rb" );
-   
-   if( fp ){
-      if( fread( info, sizeof( struct workshop_file_info ), 1, fp ) ){
-         VG_STRSAN_ASCII( info->author_name );
-         VG_STRSAN_ASCII( info->title );
-      }
-      fclose( fp );
-   }
-}
-#endif
-
 #endif /* WORKSHOP_C */