7 #include "ent_skateshop.h"
9 #include "vg/vg_steam_auth.h"
10 #include "vg/vg_steam_ugc.h"
11 #include "vg/vg_steam_friends.h"
13 #define WORKSHOP_VIEW_PER_PAGE 15
18 char description
[512];
20 PublishedFileId_t file_id
; /* 0 if not published yet */
22 struct ui_dropdown_value visibility
;
24 int submit_title
, /* set if the respective controls are touched */
26 submit_file_and_image
;
30 enum workshop_form_page
{
31 k_workshop_form_hidden
,
32 k_workshop_form_open
, /* open but not looking at anything */
33 k_workshop_form_edit
, /* editing a submission */
34 k_workshop_form_cclosing
,
35 k_workshop_form_closing_good
, /* post upload screen */
36 k_workshop_form_closing_bad
,
41 * -----------------------------
45 struct player_board board_model
;
47 /* what does the user want to do with the image preview? */
48 enum workshop_form_file_intent
{
49 k_workshop_form_file_intent_none
, /* loading probably */
50 k_workshop_form_file_intent_new
, /* board_model is valid */
51 k_workshop_form_file_intent_keep_old
/* just browsing */
55 world_instance
*view_world
;
56 ent_swspreview
*ptr_ent
;
66 * published UGC request
67 * ------------------------------
71 UGCQueryHandle_t handle
;
81 * ------------------------------------------
84 const char *failure_or_success_string
;
89 int view_published_page_count
,
90 view_published_page_id
;
92 struct published_file
{
97 published_files_list
[WORKSHOP_VIEW_PER_PAGE
];
98 int published_files_list_length
;
100 static workshop_form
;
102 static struct ui_dropdown_opt workshop_form_visibility_opts
[] = {
103 { "Public", k_ERemoteStoragePublishedFileVisibilityPublic
},
104 { "Unlisted", k_ERemoteStoragePublishedFileVisibilityUnlisted
},
105 { "Friends Only", k_ERemoteStoragePublishedFileVisibilityFriendsOnly
},
106 { "Private", k_ERemoteStoragePublishedFileVisibilityPrivate
},
110 * Close the form and discard UGC query result
112 VG_STATIC
void workshop_quit_form(void)
114 skaterift_begin_op( k_async_op_none
); /* safeguard */
115 player_board_unload( &workshop_form
.board_model
);
116 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
118 if( workshop_form
.ugc_query
.result
== k_EResultOK
){
119 workshop_form
.ugc_query
.result
= k_EResultNone
;
121 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
122 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest(
123 hSteamUGC
, workshop_form
.ugc_query
.handle
);
126 workshop_form
.page
= k_workshop_form_hidden
;
131 * Delete all information about the submission
133 VG_STATIC
void workshop_reset_submission_data(void)
135 workshop_form
.submission
.file_id
= 0; /* assuming id of 0 is none/invalid */
136 workshop_form
.submission
.description
[0] = '\0';
137 workshop_form
.submission
.title
[0] = '\0';
139 workshop_form
.submission
.visibility
.value
=
140 k_ERemoteStoragePublishedFileVisibilityPublic
;
141 workshop_form
.submission
.visibility
.index
= 0;
143 workshop_form
.model_path
[0] = '\0';
144 player_board_unload( &workshop_form
.board_model
);
145 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
150 * Mostly copies of what it sais on the Steam API documentation
152 VG_STATIC
const char *workshop_EResult_user_string( EResult result
)
155 case k_EResultInsufficientPrivilege
:
156 return "Your account is currently restricted from uploading content "
157 "due to a hub ban, account lock, or community ban. You need to "
158 "contact Steam Support to resolve the issue.";
159 case k_EResultBanned
:
160 return "You do not have permission to upload content to this hub "
161 "because you have an active VAC or Game ban.";
162 case k_EResultTimeout
:
163 return "The operation took longer than expected, so it was discarded. "
165 case k_EResultNotLoggedOn
:
166 return "You are currently not logged into Steam.";
167 case k_EResultServiceUnavailable
:
168 return "The workshop server is having issues or is unavailable, "
170 case k_EResultInvalidParam
:
171 return "One of the submission fields contains something not being "
172 "accepted by that field.";
173 case k_EResultAccessDenied
:
174 return "There was a problem trying to save the title and description. "
175 "Access was denied.";
176 case k_EResultLimitExceeded
:
177 return "You have exceeded your Steam Cloud quota. If you wish to "
178 "upload this file, you must remove some published items.";
179 case k_EResultFileNotFound
:
180 return "The uploaded file could not be found.";
181 case k_EResultDuplicateRequest
:
182 return "The file was already successfully uploaded.";
183 case k_EResultDuplicateName
:
184 return "You already have a Steam Workshop item with that name.";
185 case k_EResultServiceReadOnly
:
186 return "Due to a recent password or email change, you are not allowed "
187 "to upload new content. Usually this restriction will expire in"
188 " 5 days, but can last up to 30 days if the account has been "
189 "inactive recently.";
191 return "Operation failed for an error which has not been accounted for "
192 "by the programmer. Try again, sorry :)";
197 * op: k_workshop_form_op_publishing_update
198 * ----------------------------------------------------------------------------
202 * The endpoint of this operation
204 VG_STATIC
void on_workshop_update_result( void *data
, void *user
)
206 vg_info( "Recieved workshop update result\n" );
207 SubmitItemUpdateResult_t
*result
= data
;
209 /* this seems to be set here, but my account definitely has accepted it */
210 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
211 vg_warn( "Workshop agreement currently not accepted\n" );
214 if( result
->m_eResult
== k_EResultOK
){
215 workshop_form
.page
= k_workshop_form_closing_good
;
216 workshop_form
.failure_or_success_string
= "Uploaded workshop file!";
217 vg_success( "file uploaded\n" );
220 workshop_form
.page
= k_workshop_form_closing_bad
;
221 workshop_form
.failure_or_success_string
=
222 workshop_EResult_user_string( result
->m_eResult
);
224 vg_error( "Error with the submitted file (%d)\n", result
->m_eResult
);
230 struct workshop_package_info
{
231 PublishedFileId_t publishing_file_id
;
234 char abs_preview_image
[ 1024 ];
235 char abs_content_folder
[ 1024 ];
236 char abs_content_file
[ 1024 ];
238 const char *failure_reason
;
242 * reciever on completion of packaging the files, it will then start the item
243 * update with Steam API
245 VG_STATIC
void workshop_form_async_package_complete( void *data
, u32 size
)
247 struct workshop_package_info
*info
= data
;
248 if( !info
->success
){
249 workshop_form
.page
= k_workshop_form_closing_bad
;
250 workshop_form
.failure_or_success_string
= info
->failure_reason
;
255 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
256 UGCUpdateHandle_t handle
257 = SteamAPI_ISteamUGC_StartItemUpdate( hSteamUGC
, SKATERIFT_APPID
,
258 info
->publishing_file_id
);
260 /* TODO: Handle failure cases for these */
262 if( workshop_form
.submission
.submit_title
){
263 vg_info( "Setting title\n" );
264 SteamAPI_ISteamUGC_SetItemTitle( hSteamUGC
, handle
,
265 workshop_form
.submission
.title
);
268 if( workshop_form
.submission
.submit_description
){
269 vg_info( "Setting description\n" );
270 SteamAPI_ISteamUGC_SetItemDescription( hSteamUGC
, handle
,
271 workshop_form
.submission
.description
);
274 if( workshop_form
.submission
.submit_file_and_image
){
275 vg_info( "Setting preview image\n" );
276 SteamAPI_ISteamUGC_SetItemPreview( hSteamUGC
,
277 handle
, info
->abs_preview_image
);
279 vg_info( "Setting item content\n" );
280 SteamAPI_ISteamUGC_SetItemContent( hSteamUGC
, handle
,
281 info
->abs_content_folder
);
284 vg_info( "Setting visibility\n" );
285 SteamAPI_ISteamUGC_SetItemVisibility( hSteamUGC
, handle
,
286 workshop_form
.submission
.visibility
.value
);
288 vg_info( "Submitting updates\n" );
289 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
290 call
->userdata
= NULL
;
291 call
->p_handler
= on_workshop_update_result
;
292 call
->id
= SteamAPI_ISteamUGC_SubmitItemUpdate( hSteamUGC
, handle
, "" );
296 * Async thread for rearranging files into a reasonable workshop folder
298 struct workshop_package_thread_args
{
299 PublishedFileId_t file_id
;
304 VG_STATIC
void _workshop_package_thread( void *_args
)
306 struct workshop_package_thread_args
*args
= _args
;
307 PublishedFileId_t file_id
= args
->file_id
;
309 vg_info( "Packaging workshop content folder\n" );
311 vg_async_item
*call
= vg_async_alloc( sizeof(struct workshop_package_info
) );
312 struct workshop_package_info
*info
= call
->payload
;
313 info
->publishing_file_id
= file_id
;
314 info
->failure_reason
= "Unknown failure reason";
316 /* build content folder path */
317 snprintf( info
->abs_content_folder
, 1024, "%smodels/boards/workshop/%lu",
318 vg
.base_path
, file_id
);
320 /* build content file path */
321 snprintf( info
->abs_content_file
, 1024, "%s/%s", info
->abs_content_folder
,
324 /* build workshop preview file path */
325 snprintf( info
->abs_preview_image
, 1024, "%sworkshop_preview.jpg",
329 if( !vg_mkdir( info
->abs_content_folder
) ){
331 info
->failure_reason
= "Could not make directory.";
332 vg_async_dispatch( call
, workshop_form_async_package_complete
);
336 vg_linear_clear( vg_mem
.scratch
);
337 if( !vg_file_copy( workshop_form
.model_path
, info
->abs_content_file
,
340 info
->failure_reason
= "Copy file failed.";
341 vg_async_dispatch( call
, workshop_form_async_package_complete
);
345 /* write the metadata file */
346 struct workshop_file_info meta
;
347 meta
.author
= args
->steamid
;
348 vg_strncpy( args
->username
, meta
.author_name
, vg_list_size(meta
.author_name
),
349 k_strncpy_always_add_null
);
350 vg_strncpy( workshop_form
.submission
.title
, meta
.title
,
351 vg_list_size(meta
.title
), k_strncpy_always_add_null
);
355 vg_strnull( &path
, _path
, vg_list_size( _path
) );
356 vg_strcat( &path
, info
->abs_content_file
);
357 vg_strcat( &path
, ".inf" );
359 if( vg_strgood( &path
) ){
360 FILE *fp
= fopen( _path
, "wb" );
363 fwrite( &meta
, sizeof(struct workshop_file_info
), 1, fp
);
368 info
->failure_reason
= "Cant write .inf file";
369 vg_async_dispatch( call
, workshop_form_async_package_complete
);
374 info
->failure_reason
= "Path too long";
375 vg_async_dispatch( call
, workshop_form_async_package_complete
);
380 vg_async_dispatch( call
, workshop_form_async_package_complete
);
384 * Begins the packaging thread using file_id. Thread definition above.
386 VG_STATIC
void workshop_package_submission( PublishedFileId_t file_id
)
388 vg_linear_clear( vg_mem
.scratch
);
389 struct workshop_package_thread_args
*args
=
390 vg_linear_alloc( vg_mem
.scratch
,
391 sizeof(struct workshop_package_thread_args
));
393 ISteamFriends
*hSteamFriends
= SteamAPI_SteamFriends();
394 ISteamUser
*hSteamUser
= SteamAPI_SteamUser();
396 args
->steamid
= SteamAPI_ISteamUser_GetSteamID( hSteamUser
);
398 const char *username
= SteamAPI_ISteamFriends_GetPersonaName(hSteamFriends
);
399 str_utf8_collapse( username
, args
->username
, vg_list_size( args
->username
));
400 vg_info( "Steamid: "PRINTF_U64
", Name: %s(%s)\n",
401 args
->steamid
, username
, args
->username
);
403 args
->file_id
= file_id
;
404 vg_loader_start( _workshop_package_thread
, args
);
408 * Steam API call result for when we've created a new item on their network, or
409 * not, if it has failed
411 VG_STATIC
void on_workshop_createitem( void *data
, void *user
)
413 CreateItemResult_t
*result
= data
;
415 if( result
->m_eResult
== k_EResultOK
){
416 vg_info( "Created workshop file with id: %lu\n",
417 result
->m_nPublishedFileId
);
419 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
420 vg_warn( "Workshop agreement currently not accepted\n" );
423 workshop_package_submission( result
->m_nPublishedFileId
);
426 const char *errstr
= workshop_EResult_user_string( result
->m_eResult
);
429 vg_error( "ISteamUGC_CreateItem() failed(%d): '%s' \n",
430 result
->m_eResult
, errstr
);
433 workshop_form
.page
= k_workshop_form_closing_bad
;
434 workshop_form
.failure_or_success_string
= errstr
;
440 * Starts the workshop upload process through Steam API
442 VG_STATIC
void workshop_form_async_submit_begin( void *payload
, u32 size
)
444 /* use existing file */
445 if( workshop_form
.submission
.file_id
){
446 if( workshop_form
.submission
.submit_file_and_image
){
447 workshop_package_submission( workshop_form
.submission
.file_id
);
450 struct workshop_package_info info
;
451 info
.abs_content_file
[0] = '\0';
452 info
.abs_content_folder
[0] = '\0';
453 info
.abs_preview_image
[0] = '\0';
454 info
.failure_reason
= NULL
;
455 info
.publishing_file_id
= workshop_form
.submission
.file_id
;
457 workshop_form_async_package_complete( &info
,
458 sizeof(struct workshop_package_info
) );
462 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
463 call
->userdata
= NULL
;
464 call
->p_handler
= on_workshop_createitem
;
465 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
466 call
->id
= SteamAPI_ISteamUGC_CreateItem( hSteamUGC
, SKATERIFT_APPID
,
467 k_EWorkshopFileTypeCommunity
);
472 * Downloads the framebuffer into scratch memory
474 VG_STATIC
void workshop_form_async_download_image( void *payload
, u32 size
)
477 render_fb_get_current_res( gpipeline
.fb_workshop_preview
, &w
, &h
);
478 vg_linear_clear( vg_mem
.scratch
);
479 workshop_form
.img_buffer
= vg_linear_alloc( vg_mem
.scratch
, w
*h
*3 );
481 vg_info( "read framebuffer: glReadPixels( %dx%d )\n", w
,h
);
483 glBindFramebuffer( GL_READ_FRAMEBUFFER
, gpipeline
.fb_workshop_preview
->fb
);
484 glReadBuffer( GL_COLOR_ATTACHMENT0
);
485 glReadPixels( 0,0, w
,h
, GL_RGB
, GL_UNSIGNED_BYTE
, workshop_form
.img_buffer
);
487 workshop_form
.img_w
= w
;
488 workshop_form
.img_h
= h
;
492 * Thread which kicks off the upload process
494 VG_STATIC
void _workshop_form_submit_thread( void *data
)
496 vg_async_call( workshop_form_async_download_image
, NULL
, 0 );
499 int w
= workshop_form
.img_w
,
500 h
= workshop_form
.img_h
;
502 vg_info( "writing: workshop_preview.jpg (%dx%d @90%%)\n", w
,h
);
503 stbi_flip_vertically_on_write(1);
504 stbi_write_jpg( "workshop_preview.jpg", w
,h
, 3,
505 workshop_form
.img_buffer
, 90 );
507 vg_async_call( workshop_form_async_submit_begin
, NULL
, 0 );
511 * Entry point for the publishing submission operation
513 VG_STATIC
void workshop_op_submit(void)
515 /* TODO: Show these errors to the user */
517 if( workshop_form
.submission
.submit_title
){
518 if( !workshop_form
.submission
.title
[0] ){
519 vg_error( "Cannot submit because a title is required\n" );
524 if( workshop_form
.submission
.submit_description
){
525 if( !workshop_form
.submission
.description
[0] ){
526 vg_error( "Cannot submit because a description is required\n" );
531 if( workshop_form
.submission
.submit_file_and_image
){
532 if( workshop_form
.file_intent
== k_workshop_form_file_intent_none
){
533 vg_error( "Cannot submit because the file is empty or unspecified\n" );
538 skaterift_begin_op( k_workshop_form_op_publishing_update
);
540 player_board_unload( &workshop_form
.board_model
);
541 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
543 vg_loader_start( _workshop_form_submit_thread
, NULL
);
547 * op: k_workshop_form_op_loading_model
548 * -----------------------------------------------------------------------------
552 * Reciever for completion of the model file load
554 VG_STATIC
void workshop_form_loadmodel_async_complete( void *payload
, u32 size
)
556 v2_zero( workshop_form
.view_angles
);
557 v3_zero( workshop_form
.view_offset
);
558 workshop_form
.view_dist
= 1.0f
;
559 workshop_form
.view_changed
= 1;
560 workshop_form
.file_intent
= k_workshop_form_file_intent_new
;
562 vg_success( "workshop async load complete\n" );
567 * Reciever for failure to load
569 VG_STATIC
void workshop_form_loadmodel_async_error( void *payload
, u32 size
)
575 * Thread which loads the model from the disk
577 VG_STATIC
void _workshop_form_load_thread( void *data
)
579 FILE *test
= fopen( workshop_form
.model_path
, "rb" );
582 player_board_load( &workshop_form
.board_model
, workshop_form
.model_path
);
583 vg_async_call( workshop_form_loadmodel_async_complete
, NULL
, 0 );
586 vg_error( "workshop async load failed: file not found\n" );
587 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
592 * Entry point for load model operation
594 VG_STATIC
void workshop_op_load_model(void)
596 skaterift_begin_op( k_workshop_form_op_loading_model
);
597 vg_loader_start( _workshop_form_load_thread
, NULL
);
601 * op: k_workshop_form_op_downloading_submission
602 * -----------------------------------------------------------------------------
606 * The image has been decoded and is ready to slap into the framebuffer
608 VG_STATIC
void workshop_form_async_imageload( void *data
, u32 len
)
611 struct framebuffer_attachment
*a
=
612 &gpipeline
.fb_workshop_preview
->attachments
[0];
614 glBindTexture( GL_TEXTURE_2D
, a
->id
);
615 glTexSubImage2D( GL_TEXTURE_2D
, 0,0,0,
616 WORKSHOP_PREVIEW_WIDTH
, WORKSHOP_PREVIEW_HEIGHT
,
617 a
->format
, a
->type
, data
);
618 stbi_image_free( data
);
619 vg_success( "Loaded workshop preview image\n" );
625 struct workshop_loadpreview_info
{
626 char abs_preview_image
[ 1024 ];
630 * Load the image located at ./workshop_preview.jpg into our framebuffer
632 VG_STATIC
void _workshop_load_preview_thread( void *data
)
634 struct workshop_loadpreview_info
*info
= data
;
636 stbi_set_flip_vertically_on_load(1);
638 u8
*rgb
= stbi_load( info
->abs_preview_image
, &x
, &y
, &nc
, 3 );
641 if( (x
== WORKSHOP_PREVIEW_WIDTH
) && (y
== WORKSHOP_PREVIEW_HEIGHT
) ){
642 vg_async_call( workshop_form_async_imageload
, rgb
, x
*y
*3 );
645 vg_error( "Resolution does not match framebuffer, so we can't"
647 stbi_image_free( rgb
);
648 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
652 vg_error( "Failed to load workshop_preview.jpg: '%s'\n",
653 stbi_failure_reason() );
654 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
659 * Reciever for the preview download result
661 VG_STATIC
void on_workshop_download_ugcpreview( void *data
, void *user
)
663 struct workshop_loadpreview_info
*info
= user
;
664 RemoteStorageDownloadUGCResult_t
*result
= data
;
666 if( result
->m_eResult
== k_EResultOK
){
667 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
668 vg_loader_start( _workshop_load_preview_thread
, info
);
671 vg_error( "Error while donwloading UGC preview( %d )\n",
678 * Entry point to view operation
680 VG_STATIC
void workshop_op_download_and_view_submission( int result_index
)
682 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
683 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
684 SteamUGCDetails_t details
;
685 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
686 workshop_form
.ugc_query
.handle
,
690 skaterift_begin_op( k_workshop_form_op_downloading_submission
);
691 workshop_reset_submission_data();
692 workshop_form
.submission
.submit_description
= 0;
693 workshop_form
.submission
.submit_file_and_image
= 0;
694 workshop_form
.submission
.submit_title
= 0;
696 vg_strncpy( details
.m_rgchDescription
,
697 workshop_form
.submission
.description
,
698 vg_list_size( workshop_form
.submission
.description
),
699 k_strncpy_always_add_null
);
701 vg_strncpy( details
.m_rgchTitle
,
702 workshop_form
.submission
.title
,
703 vg_list_size( workshop_form
.submission
.title
),
704 k_strncpy_always_add_null
);
706 snprintf( workshop_form
.model_path
,
707 vg_list_size( workshop_form
.model_path
),
708 "Steam Cloud (%lu)", details
.m_nPublishedFileId
);
710 workshop_form
.submission
.file_id
= details
.m_nPublishedFileId
;
711 workshop_form
.file_intent
= k_workshop_form_file_intent_keep_old
;
712 workshop_form
.page
= k_workshop_form_edit
;
713 workshop_form
.submission
.visibility
.value
= details
.m_eVisibility
;
715 for( i32 i
=0; i
<vg_list_size(workshop_form_visibility_opts
); i
++ ){
716 if( workshop_form_visibility_opts
[i
].value
== details
.m_eVisibility
){
717 workshop_form
.submission
.visibility
.index
= i
;
722 if( details
.m_hPreviewFile
== 0 ){
723 vg_error( "m_hPreviewFile is 0\n" );
727 /* Now need to begin downloading the image so we can display it */
728 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
730 struct workshop_loadpreview_info
*info
=
731 vg_linear_alloc( vg_mem
.scratch
,
732 sizeof( struct workshop_loadpreview_info
) );
734 snprintf( info
->abs_preview_image
, 1024,
735 "%smodels/boards/workshop/" PRINTF_U64
".jpg",
736 vg
.base_path
, details
.m_hPreviewFile
);
738 call
->p_handler
= on_workshop_download_ugcpreview
;
739 call
->userdata
= info
;
740 call
->id
= SteamAPI_ISteamRemoteStorage_UGCDownloadToLocation(
742 details
.m_hPreviewFile
, info
->abs_preview_image
, 1 );
744 vg_info( "preview file id: " PRINTF_U64
"\n",
745 details
.m_hPreviewFile
);
749 vg_error( "GetQueryUGCResult: Index out of range\n" );
756 * -----------------------------------------------------------------------------
760 * View a page of results on the sidebar
762 VG_STATIC
void workshop_view_page( int req
)
764 if( workshop_form
.ugc_query
.result
!= k_EResultOK
){
765 vg_error( "Tried to change page without complete data\n" );
769 int page
= VG_MAX(VG_MIN(req
, workshop_form
.view_published_page_count
-1),0),
770 start
= page
* WORKSHOP_VIEW_PER_PAGE
,
771 end
= VG_MIN( (page
+1) * WORKSHOP_VIEW_PER_PAGE
,
772 workshop_form
.ugc_query
.returned_item_count
),
775 vg_info( "View page %d\n", page
);
777 workshop_form
.view_published_page_id
= page
;
778 workshop_form
.published_files_list_length
= count
;
779 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
781 for( int i
=0; i
<count
; i
++ ){
782 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
784 SteamUGCDetails_t details
;
785 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
786 workshop_form
.ugc_query
.handle
,
790 if( details
.m_eResult
!= k_EResultOK
){
791 snprintf( pfile
->title
, 80, "Error (%d)", details
.m_eResult
);
794 vg_strncpy( details
.m_rgchTitle
, pfile
->title
, 80,
795 k_strncpy_always_add_null
);
798 pfile
->result
= details
.m_eResult
;
799 pfile
->result_index
= start
+i
;
802 pfile
->result
= k_EResultValueOutOfRange
;
803 pfile
->result_index
= -1;
804 snprintf( pfile
->title
, 80, "Error (invalid index)" );
810 * Steam API result for when we recieve submitted UGC information about the user
812 VG_STATIC
void on_workshop_UGCQueryComplete( void *data
, void *userdata
)
814 SteamUGCQueryCompleted_t
*query
= data
;
815 workshop_form
.ugc_query
.result
= query
->m_eResult
;
817 if( query
->m_eResult
== k_EResultOK
){
818 if( query
->m_unTotalMatchingResults
> 50 ){
819 vg_warn( "You have %d items submitted, "
820 "we can only view the last 50\n" );
823 workshop_form
.ugc_query
.all_item_count
= query
->m_unTotalMatchingResults
;
824 workshop_form
.ugc_query
.returned_item_count
=
825 query
->m_unNumResultsReturned
;
827 workshop_form
.ugc_query
.handle
= query
->m_handle
;
828 workshop_form
.view_published_page_count
=
829 (query
->m_unNumResultsReturned
+WORKSHOP_VIEW_PER_PAGE
-1)/
830 WORKSHOP_VIEW_PER_PAGE
;
831 workshop_form
.view_published_page_id
= 0;
832 workshop_form
.published_files_list_length
= 0;
834 workshop_view_page( 0 );
837 vg_error( "Steam UGCQuery failed (%d)\n", query
->m_eResult
);
838 workshop_form
.view_published_page_count
= 0;
839 workshop_form
.view_published_page_id
= 0;
840 workshop_form
.published_files_list_length
= 0;
842 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
843 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest( hSteamUGC
, query
->m_handle
);
848 * Console command to open the workshop publisher
850 VG_STATIC
int workshop_submit_command( int argc
, const char *argv
[] )
853 vg_error( "Steam API is not ready or loaded\n" );
857 workshop_form
.page
= k_workshop_form_open
;
858 workshop_form
.view_published_page_count
= 0;
859 workshop_form
.view_published_page_id
= 0;
860 workshop_form
.published_files_list_length
= 0;
861 workshop_form
.ugc_query
.result
= k_EResultNone
;
863 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
865 ISteamUser
*hSteamUser
= SteamAPI_SteamUser();
867 steamid
.m_unAll64Bits
= SteamAPI_ISteamUser_GetSteamID( hSteamUser
);
869 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
870 call
->p_handler
= on_workshop_UGCQueryComplete
;
871 call
->userdata
= NULL
;
872 UGCQueryHandle_t handle
= SteamAPI_ISteamUGC_CreateQueryUserUGCRequest
875 steamid
.m_comp
.m_unAccountID
,
876 k_EUserUGCList_Published
,
877 k_EUGCMatchingUGCType_Items
,
878 k_EUserUGCListSortOrder_CreationOrderDesc
,
879 SKATERIFT_APPID
, SKATERIFT_APPID
,
881 call
->id
= SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC
, handle
);
885 VG_STATIC
void workshop_init(void)
887 vg_console_reg_cmd( "workshop_submit", workshop_submit_command
, NULL
);
890 VG_STATIC
void workshop_find_preview_entity(void)
892 workshop_form
.view_world
= get_active_world();
894 if( mdl_arrcount( &workshop_form
.view_world
->ent_swspreview
) ){
895 workshop_form
.ptr_ent
=
896 mdl_arritm( &workshop_form
.view_world
->ent_swspreview
, 0 );
897 workshop_form
.page
= k_workshop_form_edit
;
900 vg_error( "There is no ent_swspreview in the level. "
901 "Cannot publish here\n" );
906 * Redraw the model file into the workshop framebuffer
908 VG_STATIC
void workshop_render_preview(void)
910 if( !workshop_form
.ptr_ent
){
914 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
916 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
917 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
918 glEnable( GL_DEPTH_TEST
);
919 glDisable( GL_BLEND
);
921 ent_swspreview
*swsprev
= workshop_form
.ptr_ent
;
922 world_instance
*world
= workshop_form
.view_world
;
924 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
925 mdl_entity_id_id(swsprev
->id_camera
) );
926 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
927 mdl_entity_id_id(swsprev
->id_display
) ),
928 *display1
= mdl_arritm( &world
->ent_marker
,
929 mdl_entity_id_id(swsprev
->id_display1
) );
932 v3_add( display
->transform
.co
, display1
->transform
.co
, baseco
);
933 v3_muls( baseco
, 0.5f
, baseco
);
937 v3_sub( display
->transform
.co
, ref
->transform
.co
, basevector
);
938 float dist
= v3_length( basevector
);
941 player_vector_angles( baseangles
, basevector
, 1.0f
, 0.0f
);
943 v2_add( workshop_form
.view_angles
, baseangles
, cam
.angles
);
944 cam
.angles
[2] = 0.0f
;
946 float sX
= sinf( cam
.angles
[0] ),
947 cX
= cosf( cam
.angles
[0] ),
948 sY
= sinf( cam
.angles
[1] ),
949 cY
= cosf( cam
.angles
[1] );
951 v3f offset
= { -sX
* cY
, sY
, cX
* cY
};
953 v3_muladds( display
->transform
.co
, offset
,
954 dist
*workshop_form
.view_dist
, cam
.pos
);
956 cam
.pos
[0] += -sX
*workshop_form
.view_offset
[2];
957 cam
.pos
[2] += cX
*workshop_form
.view_offset
[2];
958 cam
.pos
[0] += cX
*workshop_form
.view_offset
[0];
959 cam
.pos
[2] += sX
*workshop_form
.view_offset
[0];
960 cam
.pos
[1] += workshop_form
.view_offset
[1];
966 camera_update_transform( &cam
);
967 camera_update_view( &cam
);
968 camera_update_projection( &cam
);
969 camera_finalize( &cam
);
972 mdl_transform_m4x3( &display
->transform
, mmdl
);
973 mdl_transform_m4x3( &display1
->transform
, mmdl1
);
975 /* force update this for nice shadows. its usually set in the world
976 * pre-render step, but that includes timer stuff
978 struct player_board
*board
= &workshop_form
.board_model
;
979 struct ub_world_lighting
*ubo
= &world
->ub_lighting
;
981 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[0][2]}, vp0
);
982 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[1][2]}, vp1
);
983 m4x3_mulv( mmdl1
, vp0
, ubo
->g_board_0
);
984 m4x3_mulv( mmdl1
, vp1
, ubo
->g_board_1
);
985 glBindBuffer( GL_UNIFORM_BUFFER
, world
->ubo_lighting
);
986 glBufferSubData( GL_UNIFORM_BUFFER
, 0,
987 sizeof(struct ub_world_lighting
), &world
->ub_lighting
);
989 render_world( world
, &cam
, 1 );
990 render_board( &cam
, world
, board
, mmdl
, k_board_shader_entity
);
991 render_board( &cam
, world
, board
, mmdl1
, k_board_shader_entity
);
993 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
994 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
998 * ImGUI section for workshop form
999 * -----------------------------------------------------------------------------
1002 VG_STATIC
void workshop_changed_model_path( char *buf
, u32 len
){
1003 workshop_form
.submission
.submit_file_and_image
= 1;
1006 VG_STATIC
void workshop_changed_title( char *buf
, u32 len
){
1007 workshop_form
.submission
.submit_title
= 1;
1010 VG_STATIC
void workshop_changed_description( char *buf
, u32 len
){
1011 workshop_form
.submission
.submit_description
= 1;
1014 VG_STATIC
void workshop_form_gui_edit_page( ui_rect content
)
1016 ui_rect image_plane
;
1017 ui_split( content
, k_ui_axis_h
, 300, 0, image_plane
, content
);
1018 ui_fill( image_plane
, ui_colour( k_ui_bg
+0 ) );
1021 ui_fit_item( image_plane
, (ui_px
[2]){ 3, 2 }, img_box
);
1023 if( workshop_form
.file_intent
== k_workshop_form_file_intent_keep_old
){
1024 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1026 else if( workshop_form
.file_intent
== k_workshop_form_file_intent_new
){
1027 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1028 int hover
= ui_inside_rect( img_box
, vg_ui
.mouse
),
1029 target
= ui_inside_rect( img_box
, vg_ui
.mouse_click
);
1031 if( ui_click_down(UI_MOUSE_MIDDLE
) && target
){
1032 v3_copy( workshop_form
.view_offset
,
1033 workshop_form
.view_offset_begin
);
1035 else if( ui_click_down(UI_MOUSE_LEFT
) && target
){
1036 v2_copy( workshop_form
.view_angles
,
1037 workshop_form
.view_angles_begin
);
1040 if( ui_clicking(UI_MOUSE_MIDDLE
) && target
){
1041 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1042 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1044 float *begin
= workshop_form
.view_offset_begin
,
1045 *offset
= workshop_form
.view_offset
;
1046 offset
[0] = vg_clampf( begin
[0]-delta
[0]*0.002f
, -1.0f
, 1.0f
);
1047 offset
[2] = vg_clampf( begin
[2]-delta
[1]*0.002f
, -1.0f
, 1.0f
);
1048 workshop_form
.view_changed
= 1;
1050 else if( ui_clicking(UI_MOUSE_LEFT
) && target
){
1051 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1052 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1055 v2_muladds( workshop_form
.view_angles_begin
, delta
, 0.002f
, angles
);
1057 float limit
= VG_PIf
*0.2f
;
1059 angles
[0] = vg_clampf( angles
[0], -limit
, limit
);
1060 angles
[1] = vg_clampf( angles
[1], -limit
, limit
);
1062 v2_copy( angles
, workshop_form
.view_angles
);
1063 workshop_form
.view_changed
= 1;
1066 if( !ui_clicking(UI_MOUSE_LEFT
) && hover
){
1067 float zoom
= workshop_form
.view_dist
;
1068 zoom
+= vg
.mouse_wheel
[1] * -0.07f
;
1069 zoom
= vg_clampf( zoom
, 0.4f
, 2.0f
);
1071 if( zoom
!= workshop_form
.view_dist
){
1072 workshop_form
.view_changed
= 1;
1073 workshop_form
.view_dist
= zoom
;
1078 ui_text( img_box
, "No image", 1, k_ui_align_middle_center
,
1079 ui_colour( k_ui_orange
) );
1083 ui_rect null
, file_entry
, file_button
, file_label
;
1084 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1085 ui_split( content
, k_ui_axis_h
, 28, 0, file_entry
, content
);
1086 ui_split( file_entry
, k_ui_axis_v
, -128, 0, file_entry
, file_button
);
1087 ui_split_label( file_entry
, "File:", 1, 8, file_label
, file_entry
);
1088 ui_text( file_label
, "File:", 1, k_ui_align_middle_left
, 0 );
1090 if( workshop_form
.file_intent
!= k_workshop_form_file_intent_none
){
1091 ui_text( file_entry
, workshop_form
.model_path
, 1, k_ui_align_middle_left
,
1092 ui_colour( k_ui_fg
+4 ) );
1094 if( ui_button_text( file_button
, "Remove", 1 ) ){
1095 player_board_unload( &workshop_form
.board_model
);
1096 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1097 workshop_form
.model_path
[0] = '\0';
1101 struct ui_textbox_callbacks callbacks
= {
1102 .change
= workshop_changed_model_path
1105 ui_textbox( file_entry
, workshop_form
.model_path
,
1106 vg_list_size(workshop_form
.model_path
), 0, &callbacks
);
1108 if( ui_button_text( file_button
, "Load", 1 ) ){
1109 workshop_find_preview_entity();
1110 workshop_op_load_model();
1114 ui_rect title_entry
, label
;
1115 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1116 ui_split( content
, k_ui_axis_h
, 28, 0, title_entry
, content
);
1118 const char *str_title
= "Title:", *str_desc
= "Description:";
1119 ui_split( title_entry
, k_ui_axis_v
,
1120 ui_text_line_width(str_title
)+8, 0, label
, title_entry
);
1122 ui_rect vis_dropdown
;
1123 ui_split_ratio( title_entry
, k_ui_axis_v
, 0.6f
, 16,
1124 title_entry
, vis_dropdown
);
1128 struct ui_textbox_callbacks callbacks
= {
1129 .change
= workshop_changed_title
1131 ui_text( label
, str_title
, 1, k_ui_align_middle_left
, 0 );
1132 ui_textbox( title_entry
, workshop_form
.submission
.title
,
1133 vg_list_size(workshop_form
.submission
.title
), 0, &callbacks
);
1136 /* visibility option */
1138 ui_enum( vis_dropdown
, "Visibility:", workshop_form_visibility_opts
,
1139 4, &workshop_form
.submission
.visibility
);
1142 /* description box */
1144 struct ui_textbox_callbacks callbacks
= {
1145 .change
= workshop_changed_description
1148 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1149 ui_split( content
, k_ui_axis_h
, 28, 0, label
, content
);
1150 ui_split( content
, k_ui_axis_h
, 28*4, 0, desc_entry
, content
);
1151 ui_text( label
, str_desc
, 1, k_ui_align_middle_left
, 0 );
1152 ui_textbox( desc_entry
, workshop_form
.submission
.description
,
1153 vg_list_size(workshop_form
.submission
.description
),
1154 UI_TEXTBOX_MULTILINE
|UI_TEXTBOX_WRAP
, &callbacks
);
1157 /* submissionable */
1158 ui_rect submission_row
;
1159 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1160 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1163 ui_rect submission_center
;
1164 rect_copy( submission_row
, submission_center
);
1165 submission_center
[2] = 256;
1166 ui_rect_center( submission_row
, submission_center
);
1168 ui_rect btn_left
, btn_right
;
1169 ui_split_ratio( submission_center
, k_ui_axis_v
, 0.5f
, 8,
1170 btn_left
, btn_right
);
1172 if( ui_button_text( btn_left
, "Publish", 1 ) ){
1173 workshop_op_submit();
1175 if( ui_button_text( btn_right
, "Cancel", 1 ) ){
1176 workshop_form
.page
= k_workshop_form_open
;
1177 player_board_unload( &workshop_form
.board_model
);
1178 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1182 const char *disclaimer_text
=
1183 "By submitting this item, you agree to the workshop terms of service";
1185 ui_rect disclaimer_row
, inner
, link
;
1186 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1187 ui_split( content
, k_ui_axis_h
, content
[3]-32, 0, content
,
1190 ui_px btn_width
= 32;
1192 rect_copy( disclaimer_row
, inner
);
1193 inner
[2] = ui_text_line_width( disclaimer_text
) + btn_width
+8;
1195 ui_rect_center( disclaimer_row
, inner
);
1196 ui_split( inner
, k_ui_axis_v
, inner
[2]-btn_width
, 0, label
, btn_right
);
1197 ui_rect_pad( btn_right
, (ui_px
[2]){2,2} );
1199 if( ui_button_text( btn_right
, "\x91", 2 ) ){
1200 ISteamFriends
*hSteamFriends
= SteamAPI_SteamFriends();
1201 SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage( hSteamFriends
,
1202 "https://steamcommunity.com/sharedfiles/workshoplegalagreement",
1203 k_EActivateGameOverlayToWebPageMode_Default
);
1206 ui_text( label
, disclaimer_text
, 1, k_ui_align_middle_left
,
1207 ui_colour( k_ui_fg
+4 ) );
1210 VG_STATIC
void workshop_form_gui_sidebar( ui_rect sidebar
)
1213 * sidebar existing entries panel
1215 ui_fill( sidebar
, ui_colour( k_ui_bg
+2 ) );
1218 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1219 ui_text( title
, "Your submissions", 1, k_ui_align_middle_center
, 0 );
1221 ui_rect controls
, btn_create_new
;
1222 ui_split( sidebar
, k_ui_axis_h
, 32, 0, controls
, sidebar
);
1223 ui_split( sidebar
, k_ui_axis_h
, -32, 0, sidebar
, btn_create_new
);
1224 ui_fill( controls
, ui_colour( k_ui_bg
+1 ) );
1227 strcpy( buf
, "page " );
1229 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_id
+1, 4 );
1231 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_count
, 4 );
1234 ui_rect_pad( controls
, (ui_px
[2]){0,4} );
1236 ui_split_ratio( controls
, k_ui_axis_v
, 0.25f
, 0, info
, controls
);
1237 ui_text( info
, buf
, 1, k_ui_align_middle_center
, 0 );
1239 ui_rect btn_left
, btn_right
;
1240 ui_split_ratio( controls
, k_ui_axis_v
, 0.5f
, 2, btn_left
, btn_right
);
1242 if( ui_button_text( btn_left
, "newer", 1 ) ){
1243 workshop_view_page( workshop_form
.view_published_page_id
-1 );
1246 if( ui_button_text( btn_right
, "older", 1 ) ){
1247 workshop_view_page( workshop_form
.view_published_page_count
+1 );
1250 if( ui_button_text( btn_create_new
, "Create New Item", 1 ) ){
1251 workshop_reset_submission_data();
1252 workshop_form
.submission
.submit_title
= 1;
1253 workshop_form
.submission
.submit_description
= 1;
1254 workshop_form
.submission
.submit_file_and_image
= 1;
1255 workshop_form
.page
= k_workshop_form_edit
;
1256 workshop_find_preview_entity();
1259 for( int i
=0; i
<workshop_form
.published_files_list_length
; i
++ ){
1261 ui_split( sidebar
, k_ui_axis_h
, 28, 0, item
, sidebar
);
1262 ui_rect_pad( item
, (ui_px
[2]){4,4} );
1264 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
1265 if( ui_button_text( item
, pfile
->title
, 1 ) ){
1266 if( pfile
->result
== k_EResultOK
){
1267 vg_info( "Select index: %d\n", pfile
->result_index
);
1268 workshop_op_download_and_view_submission( pfile
->result_index
);
1271 vg_warn( "Cannot select that item, result not OK\n" );
1277 VG_STATIC
void workshop_form_gui(void)
1279 enum workshop_form_page stable_page
= workshop_form
.page
;
1280 if( stable_page
== k_workshop_form_hidden
) return;
1283 ui_rect screen
= { 0, 0, vg
.window_x
, vg
.window_y
};
1284 ui_rect window
= { 0, 0, 1000, 700 };
1285 ui_rect_center( screen
, window
);
1286 vg_ui
.wants_mouse
= 1;
1288 ui_fill( window
, ui_colour( k_ui_bg
+1 ) );
1289 ui_outline( window
, 1, ui_colour( k_ui_bg
+7 ) );
1291 ui_rect title
, panel
;
1292 ui_split( window
, k_ui_axis_h
, 28, 0, title
, panel
);
1293 ui_fill( title
, ui_colour( k_ui_bg
+7 ) );
1294 ui_text( title
, "Workshop tool", 1, k_ui_align_middle_center
,
1295 ui_colourcont(k_ui_bg
+7) );
1297 ui_rect quit_button
;
1298 ui_split( title
, k_ui_axis_v
, title
[2]-title
[3], 2, title
, quit_button
);
1300 if( skaterift
.async_op
== k_async_op_none
){
1301 if( ui_button_text( quit_button
, "X", 1 ) ){
1302 workshop_quit_form();
1308 * temporary operation blinders, we don't yet have a nice way to show the
1309 * user that we're doing something uninterruptable, so the code just
1310 * escapes here and we show them a basic string
1313 if( skaterift
.async_op
!= k_async_op_none
){
1314 const char *op_string
= "The programmer has not bothered to describe "
1315 "the current operation that is running.";
1317 switch( skaterift
.async_op
){
1318 case k_workshop_form_op_loading_model
:
1319 op_string
= "Operation in progress: Loading model file.";
1321 case k_workshop_form_op_publishing_update
:
1322 op_string
= "Operation in progress: publishing submission update "
1325 case k_workshop_form_op_downloading_submission
:
1326 op_string
= "Operation in progress: downloading existing submission"
1327 " from Steam services.";
1332 ui_text( panel
, op_string
, 1, k_ui_align_middle_center
, 0 );
1336 /* re draw board preview if need to */
1337 if( (stable_page
== k_workshop_form_edit
) &&
1338 workshop_form
.view_changed
&&
1339 workshop_form
.file_intent
== k_workshop_form_file_intent_new
)
1341 workshop_render_preview();
1342 workshop_form
.view_changed
= 0;
1345 struct workshop_form
*form
= &workshop_form
;
1347 ui_rect sidebar
, content
;
1348 ui_split_ratio( panel
, k_ui_axis_v
, 0.3f
, 1, sidebar
, content
);
1351 ui_rect_pad( content
, (ui_px
[2]){8,8} );
1353 if( stable_page
== k_workshop_form_edit
){
1354 workshop_form_gui_edit_page( content
);
1356 else if( stable_page
== k_workshop_form_open
){
1357 ui_text( content
, "Nothing selected.", 1, k_ui_align_middle_center
,
1358 ui_colour( k_ui_fg
+4 ) );
1360 else if( stable_page
>= k_workshop_form_cclosing
){
1361 ui_rect submission_row
;
1362 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1367 if( stable_page
== k_workshop_form_closing_bad
)
1368 colour
= ui_colour( k_ui_red
+k_ui_brighter
);
1370 colour
= ui_colour( k_ui_green
+k_ui_brighter
);
1372 ui_text( content
, workshop_form
.failure_or_success_string
, 1,
1373 k_ui_align_middle_center
, colour
);
1375 ui_rect submission_center
;
1376 rect_copy( submission_row
, submission_center
);
1377 submission_center
[2] = 128;
1378 ui_rect_center( submission_row
, submission_center
);
1379 ui_rect_pad( submission_center
, (ui_px
[2]){8,8} );
1381 if( ui_button_text( submission_center
, "OK", 1 ) ){
1382 workshop_form
.page
= k_workshop_form_open
;
1386 workshop_form_gui_sidebar( sidebar
);
1390 * Some async api stuff
1391 * -----------------------------------------------------------------------------
1394 VG_STATIC
void async_workshop_get_filepath( void *data
, u32 len
)
1396 struct async_workshop_filepath_info
*info
= data
;
1401 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1402 if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC
, info
->id
, &_size
,
1403 info
->buf
, info
->len
, &_ts
))
1405 info
->buf
[0] = '\0';
1409 VG_STATIC
void async_workshop_get_installed_files( void *data
, u32 len
)
1411 struct async_workshop_installed_files_info
*info
= data
;
1413 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1414 u32 count
= SteamAPI_ISteamUGC_GetSubscribedItems( hSteamUGC
, info
->buffer
,
1417 vg_info( "Found %u subscribed items\n", count
);
1420 for( u32 i
=0; i
<count
; i
++ ){
1421 u32 state
= SteamAPI_ISteamUGC_GetItemState( hSteamUGC
, info
->buffer
[i
] );
1422 if( state
& k_EItemStateInstalled
){
1423 info
->buffer
[j
++] = info
->buffer
[i
];
1430 VG_STATIC
void vg_strsan_ascii( char *buf
, u32 len
)
1432 for( u32 i
=0; i
<len
-1; i
++ ){
1433 if( buf
[i
] == 0 ) return;
1435 if( buf
[i
] < 32 || buf
[i
] > 126 ){
1442 #define VG_STRSAN_ASCII( X ) vg_strsan_ascii( X, vg_list_size(X) )
1444 VG_STATIC
void workshop_load_metadata( const char *path
,
1445 struct workshop_file_info
*info
)
1447 FILE *fp
= fopen( path
, "rb" );
1450 if( fread( info
, sizeof( struct workshop_file_info
), 1, fp
) ){
1451 VG_STRSAN_ASCII( info
->author_name
);
1452 VG_STRSAN_ASCII( info
->title
);
1458 #endif /* WORKSHOP_C */