its finally done
[carveJwlIkooP6JGAAIwe30JlM.git] / workshop.c
1 #ifndef WORKSHOP_C
2 #define WORKSHOP_C
3
4 #define VG_GAME
5 #include "vg/vg.h"
6 #include "vg/vg_tex.h"
7 #include "ent_skateshop.h"
8
9 #include "vg/vg_steam_auth.h"
10 #include "vg/vg_steam_ugc.h"
11 #include "vg/vg_steam_friends.h"
12
13 #define WORKSHOP_VIEW_PER_PAGE 15
14
15 struct workshop_form{
16 struct {
17 char title[80];
18 char description[512];
19
20 PublishedFileId_t file_id; /* 0 if not published yet */
21 ERemoteStoragePublishedFileVisibility visibility;
22
23 int submit_title, /* set if the respective controls are touched */
24 submit_description,
25 submit_file_and_image;
26 }
27 submission;
28
29 enum workshop_form_page{
30 k_workshop_form_hidden,
31 k_workshop_form_open, /* open but not looking at anything */
32 k_workshop_form_edit, /* editing a submission */
33 k_workshop_form_cclosing,
34 k_workshop_form_closing_good, /* post upload screen */
35 k_workshop_form_closing_bad,
36 }
37 page;
38
39 enum workshop_form_operation{
40 k_workshop_form_op_none,
41 k_workshop_form_op_loading_model,
42 k_workshop_form_op_downloading_submission,
43 k_workshop_form_op_publishing_update,
44 }
45 operation;
46
47 /* model viewer
48 * -----------------------------
49 */
50
51 char model_path[128];
52
53 struct player_board board_model;
54
55 /* what does the user want to do with the image preview? */
56 enum workshop_form_file_intent{
57 k_workshop_form_file_intent_none, /* loading probably */
58 k_workshop_form_file_intent_new, /* board_model is valid */
59 k_workshop_form_file_intent_keep_old /* just browsing */
60 }
61 file_intent;
62
63 world_instance *view_world;
64 ent_swspreview *ptr_ent;
65 v2f view_angles,
66 view_angles_begin;
67 v3f view_offset,
68 view_offset_begin;
69
70 float view_dist;
71 int view_changed;
72
73 /*
74 * published UGC request
75 * ------------------------------
76 */
77
78 struct {
79 UGCQueryHandle_t handle;
80 EResult result;
81
82 int all_item_count,
83 returned_item_count;
84 }
85 ugc_query;
86
87 /*
88 * UI information
89 * ------------------------------------------
90 */
91
92 const char *failure_or_success_string;
93
94 int img_w, img_h;
95 u8 *img_buffer;
96
97 int view_published_page_count,
98 view_published_page_id;
99
100 struct published_file{
101 EResult result;
102 int result_index;
103 char title[80];
104 }
105 published_files_list[WORKSHOP_VIEW_PER_PAGE];
106 int published_files_list_length;
107 }
108 static workshop_form;
109
110 /*
111 * Start a new operation and crash if we are already running one.
112 */
113 VG_STATIC void workshop_begin_op( enum workshop_form_operation op )
114 {
115 if( workshop_form.operation != k_workshop_form_op_none ){
116 vg_fatal_error( "Workshop form currently executing op(%d), tried to "
117 "start op(%d)\n", workshop_form.operation, op );
118 }
119
120 workshop_form.operation = op;
121 vg_info( "Starting op( %d )\n", op );
122 }
123
124 /*
125 * Finished operation, otheres can now run
126 */
127 VG_STATIC void workshop_end_op(void)
128 {
129 vg_info( "Finishing op( %d )\n", workshop_form.operation );
130 workshop_form.operation = k_workshop_form_op_none;
131 }
132
133 /*
134 * Close the form and discard UGC query result
135 */
136 VG_STATIC void workshop_quit_form(void)
137 {
138 workshop_begin_op( k_workshop_form_op_none ); /* safeguard */
139 player_board_unload( &workshop_form.board_model );
140 workshop_form.file_intent = k_workshop_form_file_intent_none;
141
142 if( workshop_form.ugc_query.result == k_EResultOK ){
143 workshop_form.ugc_query.result = k_EResultNone;
144
145 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
146 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest(
147 hSteamUGC, workshop_form.ugc_query.handle );
148 }
149
150 workshop_form.page = k_workshop_form_hidden;
151 }
152
153 /*
154 * Delete all information about the submission
155 */
156 VG_STATIC void workshop_reset_submission_data(void)
157 {
158 workshop_form.submission.file_id = 0; /* assuming id of 0 is none/invalid */
159 workshop_form.submission.description[0] = '\0';
160 workshop_form.submission.title[0] = '\0';
161 workshop_form.model_path[0] = '\0';
162 player_board_unload( &workshop_form.board_model );
163 workshop_form.file_intent = k_workshop_form_file_intent_none;
164 }
165
166
167 /*
168 * Mostly copies of what it sais on the Steam API documentation
169 */
170 VG_STATIC const char *workshop_EResult_user_string( EResult result )
171 {
172 switch( result ){
173 case k_EResultInsufficientPrivilege:
174 return "Your account is currently restricted from uploading content "
175 "due to a hub ban, account lock, or community ban. You need to "
176 "contact Steam Support to resolve the issue.";
177 case k_EResultBanned:
178 return "You do not have permission to upload content to this hub "
179 "because you have an active VAC or Game ban.";
180 case k_EResultTimeout:
181 return "The operation took longer than expected, so it was discarded. "
182 "Please try again.";
183 case k_EResultNotLoggedOn:
184 return "You are currently not logged into Steam.";
185 case k_EResultServiceUnavailable:
186 return "The workshop server is having issues or is unavailable, "
187 "please try again.";
188 case k_EResultInvalidParam:
189 return "One of the submission fields contains something not being "
190 "accepted by that field.";
191 case k_EResultAccessDenied:
192 return "There was a problem trying to save the title and description. "
193 "Access was denied.";
194 case k_EResultLimitExceeded:
195 return "You have exceeded your Steam Cloud quota. If you wish to "
196 "upload this file, you must remove some published items.";
197 case k_EResultFileNotFound:
198 return "The uploaded file could not be found.";
199 case k_EResultDuplicateRequest:
200 return "The file was already successfully uploaded.";
201 case k_EResultDuplicateName:
202 return "You already have a Steam Workshop item with that name.";
203 case k_EResultServiceReadOnly:
204 return "Due to a recent password or email change, you are not allowed "
205 "to upload new content. Usually this restriction will expire in"
206 " 5 days, but can last up to 30 days if the account has been "
207 "inactive recently.";
208 default:
209 return "Operation failed for an error which has not been accounted for "
210 "by the programmer. Try again, sorry :)";
211 }
212 }
213
214 /*
215 * op: k_workshop_form_op_publishing_update
216 * ----------------------------------------------------------------------------
217 */
218
219 /*
220 * The endpoint of this operation
221 */
222 VG_STATIC void on_workshop_update_result( void *data, void *user )
223 {
224 vg_info( "Recieved workshop update result\n" );
225 SubmitItemUpdateResult_t *result = data;
226
227 /* this seems to be set here, but my account definitely has accepted it */
228 if( result->m_bUserNeedsToAcceptWorkshopLegalAgreement ){
229 vg_warn( "Workshop agreement currently not accepted\n" );
230 }
231
232 if( result->m_eResult == k_EResultOK ){
233 workshop_form.page = k_workshop_form_closing_good;
234 workshop_form.failure_or_success_string = "Uploaded workshop file!";
235 vg_success( "file uploaded\n" );
236 }
237 else{
238 workshop_form.page = k_workshop_form_closing_bad;
239 workshop_form.failure_or_success_string =
240 workshop_EResult_user_string( result->m_eResult );
241
242 vg_error( "Error with the submitted file (%d)\n", result->m_eResult );
243 }
244
245 workshop_end_op();
246 }
247
248 struct workshop_package_info {
249 PublishedFileId_t publishing_file_id;
250
251 int success;
252 char abs_preview_image[ 1024 ];
253 char abs_content_folder[ 1024 ];
254 char abs_content_file[ 1024 ];
255
256 const char *failure_reason;
257 };
258
259 /*
260 * reciever on completion of packaging the files, it will then start the item
261 * update with Steam API
262 */
263 VG_STATIC void workshop_form_async_package_complete( void *data, u32 size )
264 {
265 struct workshop_package_info *info = data;
266 if( !info->success ){
267 workshop_form.page = k_workshop_form_closing_bad;
268 workshop_form.failure_or_success_string = info->failure_reason;
269 workshop_end_op();
270 return;
271 }
272
273 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
274 UGCUpdateHandle_t handle
275 = SteamAPI_ISteamUGC_StartItemUpdate( hSteamUGC, SKATERIFT_APPID,
276 info->publishing_file_id );
277
278 /* TODO: Handle failure cases for these */
279
280 if( workshop_form.submission.submit_title ){
281 vg_info( "Setting title\n" );
282 SteamAPI_ISteamUGC_SetItemTitle( hSteamUGC, handle,
283 workshop_form.submission.title );
284 }
285
286 if( workshop_form.submission.submit_description ){
287 vg_info( "Setting description\n" );
288 SteamAPI_ISteamUGC_SetItemDescription( hSteamUGC, handle,
289 workshop_form.submission.description);
290 }
291
292 if( workshop_form.submission.submit_file_and_image ){
293 vg_info( "Setting preview image\n" );
294 SteamAPI_ISteamUGC_SetItemPreview( hSteamUGC,
295 handle, info->abs_preview_image );
296
297 vg_info( "Setting item content\n" );
298 SteamAPI_ISteamUGC_SetItemContent( hSteamUGC, handle,
299 info->abs_content_folder );
300 }
301
302 vg_info( "Setting visibility\n" );
303 SteamAPI_ISteamUGC_SetItemVisibility( hSteamUGC, handle,
304 workshop_form.submission.visibility );
305
306 vg_info( "Submitting updates\n" );
307 vg_steam_async_call *call = vg_alloc_async_steam_api_call();
308 call->userdata = NULL;
309 call->p_handler = on_workshop_update_result;
310 call->id = SteamAPI_ISteamUGC_SubmitItemUpdate( hSteamUGC, handle, "" );
311 }
312
313 /*
314 * Async thread for rearranging files into a reasonable workshop folder
315 */
316 struct workshop_package_thread_args{
317 PublishedFileId_t file_id;
318 };
319 VG_STATIC void _workshop_package_thread( void *_args )
320 {
321 struct workshop_package_thread_args *args = _args;
322 PublishedFileId_t file_id = args->file_id;
323
324 vg_info( "Packaging workshop content folder\n" );
325
326 vg_async_item *call = vg_async_alloc( sizeof(struct workshop_package_info) );
327 struct workshop_package_info *info = call->payload;
328 info->publishing_file_id = file_id;
329 info->failure_reason = "Unknown failure reason";
330
331 /* build content folder path */
332 snprintf( info->abs_content_folder, 1024, "%smodels/boards/workshop/%lu",
333 vg.base_path, file_id );
334
335 /* build content file path */
336 snprintf( info->abs_content_file, 1024, "%s/%s", info->abs_content_folder,
337 "board.mdl" );
338
339 /* build workshop preview file path */
340 snprintf( info->abs_preview_image, 1024, "%sworkshop_preview.jpg",
341 vg.base_path );
342
343 /* arange files */
344 if( !vg_mkdir( info->abs_content_folder ) ){
345 info->success = 0;
346 info->failure_reason = "Could not make directory.";
347 vg_async_dispatch( call, workshop_form_async_package_complete );
348 return;
349 }
350
351 vg_linear_clear( vg_mem.scratch );
352 if( !vg_file_copy( workshop_form.model_path, info->abs_content_file,
353 vg_mem.scratch ) ){
354 info->success = 0;
355 info->failure_reason = "Copy file failed.";
356 vg_async_dispatch( call, workshop_form_async_package_complete );
357 return;
358 }
359
360 info->success = 1;
361 vg_async_dispatch( call, workshop_form_async_package_complete );
362 }
363
364 /*
365 * Begins the packaging thread using file_id. Thread definition above.
366 */
367 VG_STATIC void workshop_package_submission( PublishedFileId_t file_id )
368 {
369 vg_linear_clear( vg_mem.scratch );
370 struct workshop_package_thread_args *args =
371 vg_linear_alloc( vg_mem.scratch,
372 sizeof(struct workshop_package_thread_args));
373
374 args->file_id = file_id;
375 vg_loader_start( _workshop_package_thread, args );
376 }
377
378 /*
379 * Steam API call result for when we've created a new item on their network, or
380 * not, if it has failed
381 */
382 VG_STATIC void on_workshop_createitem( void *data, void *user )
383 {
384 CreateItemResult_t *result = data;
385
386 if( result->m_eResult == k_EResultOK ){
387 vg_info( "Created workshop file with id: %lu\n",
388 result->m_nPublishedFileId );
389
390 if( result->m_bUserNeedsToAcceptWorkshopLegalAgreement ){
391 vg_warn( "Workshop agreement currently not accepted\n" );
392 }
393
394 workshop_package_submission( result->m_nPublishedFileId );
395 }
396 else{
397 const char *errstr = workshop_EResult_user_string( result->m_eResult );
398
399 if( errstr ){
400 vg_error( "ISteamUGC_CreateItem() failed(%d): '%s' \n",
401 result->m_eResult, errstr );
402 }
403
404 workshop_form.page = k_workshop_form_closing_bad;
405 workshop_form.failure_or_success_string = errstr;
406 workshop_end_op();
407 }
408 }
409
410 /*
411 * Starts the workshop upload process through Steam API
412 */
413 VG_STATIC void workshop_form_async_submit_begin( void *payload, u32 size )
414 {
415 /* use existing file */
416 if( workshop_form.submission.file_id ){
417 workshop_package_submission( workshop_form.submission.file_id );
418 }
419 else{
420 vg_steam_async_call *call = vg_alloc_async_steam_api_call();
421 call->userdata = NULL;
422 call->p_handler = on_workshop_createitem;
423 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
424 call->id = SteamAPI_ISteamUGC_CreateItem( hSteamUGC, SKATERIFT_APPID,
425 k_EWorkshopFileTypeCommunity );
426 }
427 }
428
429 /*
430 * Downloads the framebuffer into scratch memory
431 */
432 VG_STATIC void workshop_form_async_download_image( void *payload, u32 size )
433 {
434 int w, h;
435 render_fb_get_current_res( gpipeline.fb_workshop_preview, &w, &h );
436 vg_linear_clear( vg_mem.scratch );
437 workshop_form.img_buffer = vg_linear_alloc( vg_mem.scratch, w*h*3 );
438
439 vg_info( "read framebuffer: glReadPixels( %dx%d )\n", w,h );
440
441 glBindFramebuffer( GL_READ_FRAMEBUFFER, gpipeline.fb_workshop_preview->fb );
442 glReadBuffer( GL_COLOR_ATTACHMENT0 );
443 glReadPixels( 0,0, w,h, GL_RGB, GL_UNSIGNED_BYTE, workshop_form.img_buffer );
444
445 workshop_form.img_w = w;
446 workshop_form.img_h = h;
447 }
448
449 /*
450 * Thread which kicks off the upload process
451 */
452 VG_STATIC void _workshop_form_submit_thread( void *data )
453 {
454 vg_async_call( workshop_form_async_download_image, NULL, 0 );
455 vg_async_stall();
456
457 int w = workshop_form.img_w,
458 h = workshop_form.img_h;
459
460 vg_info( "writing: workshop_preview.jpg (%dx%d @90%%)\n", w,h );
461 stbi_flip_vertically_on_write(1);
462 stbi_write_jpg( "workshop_preview.jpg", w,h, 3,
463 workshop_form.img_buffer, 90 );
464
465 vg_async_call( workshop_form_async_submit_begin, NULL, 0 );
466 }
467
468 /*
469 * Entry point for the publishing submission operation
470 */
471 VG_STATIC void workshop_op_submit(void)
472 {
473 /* TODO: Show these errors to the user */
474
475 if( workshop_form.submission.submit_title ){
476 if( !workshop_form.submission.title[0] ){
477 vg_error( "Cannot submit because a title is required\n" );
478 return;
479 }
480 }
481
482 if( workshop_form.submission.submit_description ){
483 if( !workshop_form.submission.description[0] ){
484 vg_error( "Cannot submit because a description is required\n" );
485 return;
486 }
487 }
488
489 if( workshop_form.submission.submit_file_and_image ){
490 if( workshop_form.file_intent == k_workshop_form_file_intent_none ){
491 vg_error( "Cannot submit because the file is empty or unspecified\n" );
492 return;
493 }
494 }
495
496 workshop_begin_op( k_workshop_form_op_publishing_update );
497
498 player_board_unload( &workshop_form.board_model );
499 workshop_form.file_intent = k_workshop_form_file_intent_none;
500
501 vg_loader_start( _workshop_form_submit_thread, NULL );
502 }
503
504 /*
505 * op: k_workshop_form_op_loading_model
506 * -----------------------------------------------------------------------------
507 */
508
509 /*
510 * Reciever for completion of the model file load
511 */
512 VG_STATIC void workshop_form_loadmodel_async_complete( void *payload, u32 size )
513 {
514 v2_zero( workshop_form.view_angles );
515 v3_zero( workshop_form.view_offset );
516 workshop_form.view_dist = 1.0f;
517 workshop_form.view_changed = 1;
518 workshop_form.file_intent = k_workshop_form_file_intent_new;
519
520 vg_success( "workshop async load complete\n" );
521 workshop_end_op();
522 }
523
524 /*
525 * Thread which loads the model from the disk
526 */
527 VG_STATIC void _workshop_form_load_thread( void *data )
528 {
529 player_board_load( &workshop_form.board_model, workshop_form.model_path );
530 vg_async_call( workshop_form_loadmodel_async_complete, NULL, 0 );
531 }
532
533 /*
534 * Entry point for load model operation
535 */
536 VG_STATIC void workshop_op_load_model(void)
537 {
538 workshop_begin_op( k_workshop_form_op_loading_model );
539 vg_loader_start( _workshop_form_load_thread, NULL );
540 }
541
542 /*
543 * op: k_workshop_form_op_downloading_submission
544 * -----------------------------------------------------------------------------
545 */
546
547 /*
548 * The image has been decoded and is ready to slap into the framebuffer
549 */
550 VG_STATIC void workshop_form_async_imageload( void *data, u32 len )
551 {
552 if( data ){
553 struct framebuffer_attachment *a =
554 &gpipeline.fb_workshop_preview->attachments[0];
555
556 glBindTexture( GL_TEXTURE_2D, a->id );
557 glTexSubImage2D( GL_TEXTURE_2D, 0,0,0,
558 WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT,
559 a->format, a->type, data );
560 stbi_image_free( data );
561 vg_success( "Loaded workshop preview image\n" );
562 }
563
564 workshop_end_op();
565 }
566
567 struct workshop_loadpreview_info {
568 char abs_preview_image[ 1024 ];
569 };
570
571 /*
572 * Load the image located at ./workshop_preview.jpg into our framebuffer
573 */
574 VG_STATIC void _workshop_load_preview_thread( void *data )
575 {
576 struct workshop_loadpreview_info *info = data;
577
578 stbi_set_flip_vertically_on_load(1);
579 int x, y, nc;
580 u8 *rgb = stbi_load( info->abs_preview_image, &x, &y, &nc, 3 );
581
582 if( rgb ){
583 if( (x == WORKSHOP_PREVIEW_WIDTH) && (y == WORKSHOP_PREVIEW_HEIGHT) ){
584 vg_async_call( workshop_form_async_imageload, rgb, x*y*3 );
585 }
586 else{
587 vg_error( "Resolution does not match framebuffer, so we can't"
588 " show it\n" );
589 stbi_image_free( rgb );
590 vg_async_call( workshop_form_async_imageload, NULL, 0 );
591 }
592 }
593 else{
594 vg_error( "Failed to load workshop_preview.jpg: '%s'\n",
595 stbi_failure_reason() );
596 vg_async_call( workshop_form_async_imageload, NULL, 0 );
597 }
598 }
599
600 /*
601 * Reciever for the preview download result
602 */
603 VG_STATIC void on_workshop_download_ugcpreview( void *data, void *user )
604 {
605 struct workshop_loadpreview_info *info = user;
606 RemoteStorageDownloadUGCResult_t *result = data;
607
608 if( result->m_eResult == k_EResultOK ){
609 ISteamRemoteStorage *hSteamRemoteStorage = SteamAPI_SteamRemoteStorage();
610 vg_loader_start( _workshop_load_preview_thread, info );
611 }
612 else{
613 vg_error( "Error while donwloading UGC preview( %d )\n",
614 result->m_eResult );
615 workshop_end_op();
616 }
617 }
618
619 /*
620 * Entry point to view operation
621 */
622 VG_STATIC void workshop_op_download_and_view_submission( int result_index )
623 {
624 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
625 ISteamRemoteStorage *hSteamRemoteStorage = SteamAPI_SteamRemoteStorage();
626 SteamUGCDetails_t details;
627 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC,
628 workshop_form.ugc_query.handle,
629 result_index,
630 &details ) )
631 {
632 workshop_begin_op( k_workshop_form_op_downloading_submission );
633 workshop_reset_submission_data();
634
635 vg_strncpy( details.m_rgchDescription,
636 workshop_form.submission.description,
637 vg_list_size( workshop_form.submission.description ),
638 k_strncpy_always_add_null );
639
640 vg_strncpy( details.m_rgchTitle,
641 workshop_form.submission.title,
642 vg_list_size( workshop_form.submission.title ),
643 k_strncpy_always_add_null );
644
645 snprintf( workshop_form.model_path,
646 vg_list_size( workshop_form.model_path ),
647 "Steam Cloud (%lu)", details.m_nPublishedFileId );
648
649 workshop_form.submission.file_id = details.m_nPublishedFileId;
650 workshop_form.file_intent = k_workshop_form_file_intent_keep_old;
651 workshop_form.page = k_workshop_form_edit;
652
653 if( details.m_hPreviewFile == 0 ){
654 vg_error( "m_hPreviewFile is 0\n" );
655 workshop_end_op();
656 }
657 else{
658 /* Now need to begin downloading the image so we can display it */
659 vg_steam_async_call *call = vg_alloc_async_steam_api_call();
660
661 struct workshop_loadpreview_info *info =
662 vg_linear_alloc( vg_mem.scratch,
663 sizeof( struct workshop_loadpreview_info ) );
664
665 snprintf( info->abs_preview_image, 1024,
666 "%smodels/boards/workshop/%lu.jpg",
667 vg.base_path, details.m_hPreviewFile );
668
669 call->p_handler = on_workshop_download_ugcpreview;
670 call->userdata = info;
671 call->id = SteamAPI_ISteamRemoteStorage_UGCDownloadToLocation(
672 hSteamRemoteStorage,
673 details.m_hPreviewFile, info->abs_preview_image, 1 );
674
675 vg_info( "preview file id: %lu\n", details.m_hPreviewFile );
676 }
677 }
678 else{
679 vg_error( "GetQueryUGCResult: Index out of range\n" );
680 workshop_end_op();
681 }
682 }
683
684 /*
685 * Regular stuff
686 * -----------------------------------------------------------------------------
687 */
688
689 /*
690 * View a page of results on the sidebar
691 */
692 VG_STATIC void workshop_view_page( int req )
693 {
694 if( workshop_form.ugc_query.result != k_EResultOK ){
695 vg_error( "Tried to change page without complete data\n" );
696 return;
697 }
698
699 int page = VG_MAX(VG_MIN(req, workshop_form.view_published_page_count-1),0),
700 start = page * WORKSHOP_VIEW_PER_PAGE,
701 end = VG_MIN( (page+1) * WORKSHOP_VIEW_PER_PAGE,
702 workshop_form.ugc_query.returned_item_count ),
703 count = end-start;
704
705 vg_info( "View page %d\n", page );
706
707 workshop_form.view_published_page_id = page;
708 workshop_form.published_files_list_length = count;
709 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
710
711 for( int i=0; i<count; i ++ ){
712 struct published_file *pfile = &workshop_form.published_files_list[i];
713
714 SteamUGCDetails_t details;
715 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC,
716 workshop_form.ugc_query.handle,
717 start+i,
718 &details ) )
719 {
720 if( details.m_eResult != k_EResultOK ){
721 snprintf( pfile->title, 80, "Error (%d)", details.m_eResult );
722 }
723 else{
724 vg_strncpy( details.m_rgchTitle, pfile->title, 80,
725 k_strncpy_always_add_null );
726 }
727
728 pfile->result = details.m_eResult;
729 pfile->result_index = start+i;
730 }
731 else{
732 pfile->result = k_EResultValueOutOfRange;
733 pfile->result_index = -1;
734 snprintf( pfile->title, 80, "Error (invalid index)" );
735 }
736 }
737 }
738
739 /*
740 * Steam API result for when we recieve submitted UGC information about the user
741 */
742 VG_STATIC void on_workshop_UGCQueryComplete( void *data, void *userdata )
743 {
744 SteamUGCQueryCompleted_t *query = data;
745 workshop_form.ugc_query.result = query->m_eResult;
746
747 if( query->m_eResult == k_EResultOK ){
748 if( query->m_unTotalMatchingResults > 50 ){
749 vg_warn( "You have %d items submitted, "
750 "we can only view the last 50\n" );
751 }
752
753 workshop_form.ugc_query.all_item_count = query->m_unTotalMatchingResults;
754 workshop_form.ugc_query.returned_item_count =
755 query->m_unNumResultsReturned;
756
757 workshop_form.ugc_query.handle = query->m_handle;
758 workshop_form.view_published_page_count =
759 (query->m_unNumResultsReturned+WORKSHOP_VIEW_PER_PAGE-1)/
760 WORKSHOP_VIEW_PER_PAGE;
761 workshop_form.view_published_page_id = 0;
762 workshop_form.published_files_list_length = 0;
763
764 workshop_view_page( 0 );
765 }
766 else{
767 vg_error( "Steam UGCQuery failed (%d)\n", query->m_eResult );
768 workshop_form.view_published_page_count = 0;
769 workshop_form.view_published_page_id = 0;
770 workshop_form.published_files_list_length = 0;
771
772 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
773 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest( hSteamUGC, query->m_handle );
774 }
775 }
776
777 /*
778 * Console command to open the workshop publisher
779 */
780 VG_STATIC int workshop_submit_command( int argc, const char *argv[] )
781 {
782 if( !steam_ready ){
783 vg_error( "Steam API is not ready or loaded\n" );
784 return 0;
785 }
786
787 workshop_form.page = k_workshop_form_open;
788 workshop_form.view_published_page_count = 0;
789 workshop_form.view_published_page_id = 0;
790 workshop_form.published_files_list_length = 0;
791 workshop_form.ugc_query.result = k_EResultNone;
792
793 vg_steam_async_call *call = vg_alloc_async_steam_api_call();
794
795 ISteamUser *hSteamUser = SteamAPI_SteamUser();
796 CSteamID steamid;
797 steamid.m_unAll64Bits = SteamAPI_ISteamUser_GetSteamID( hSteamUser );
798
799 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
800 call->p_handler = on_workshop_UGCQueryComplete;
801 call->userdata = NULL;
802 UGCQueryHandle_t handle = SteamAPI_ISteamUGC_CreateQueryUserUGCRequest
803 (
804 hSteamUGC,
805 steamid.m_comp.m_unAccountID,
806 k_EUserUGCList_Published,
807 k_EUGCMatchingUGCType_Items,
808 k_EUserUGCListSortOrder_CreationOrderDesc,
809 SKATERIFT_APPID, SKATERIFT_APPID,
810 1 );
811 call->id = SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC, handle );
812 return 0;
813 }
814
815 VG_STATIC void workshop_init(void)
816 {
817 vg_console_reg_cmd( "workshop_submit", workshop_submit_command, NULL );
818 }
819
820 VG_STATIC void workshop_find_preview_entity(void)
821 {
822 workshop_form.view_world = get_active_world();
823
824 if( mdl_arrcount( &workshop_form.view_world->ent_swspreview ) ){
825 workshop_form.ptr_ent =
826 mdl_arritm( &workshop_form.view_world->ent_swspreview, 0 );
827 workshop_form.page = k_workshop_form_edit;
828 }
829 else{
830 vg_error( "There is no ent_swspreview in the level. "
831 "Cannot publish here\n" );
832 }
833 }
834
835 /*
836 * Redraw the model file into the workshop framebuffer
837 */
838 VG_STATIC void workshop_render_preview(void)
839 {
840 if( !workshop_form.ptr_ent ){
841 return;
842 }
843
844 render_fb_bind( gpipeline.fb_workshop_preview, 0 );
845
846 glClearColor( 0.0f, 0.0f, 0.3f, 1.0f );
847 glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
848 glEnable( GL_DEPTH_TEST );
849 glDisable( GL_BLEND );
850
851 ent_swspreview *swsprev = workshop_form.ptr_ent;
852 world_instance *world = workshop_form.view_world;
853
854 ent_camera *ref = mdl_arritm( &world->ent_camera,
855 mdl_entity_id_id(swsprev->id_camera) );
856 ent_marker *display = mdl_arritm( &world->ent_marker,
857 mdl_entity_id_id(swsprev->id_display) ),
858 *display1= mdl_arritm( &world->ent_marker,
859 mdl_entity_id_id(swsprev->id_display1) );
860
861 v3f baseco;
862 v3_add( display->transform.co, display1->transform.co, baseco );
863 v3_muls( baseco, 0.5f, baseco );
864
865 camera cam;
866 v3f basevector;
867 v3_sub( display->transform.co, ref->transform.co, basevector );
868 float dist = v3_length( basevector );
869
870 v3f baseangles;
871 player_vector_angles( baseangles, basevector, 1.0f, 0.0f );
872
873 v2_add( workshop_form.view_angles, baseangles, cam.angles );
874 cam.angles[2] = 0.0f;
875
876 float sX = sinf( cam.angles[0] ),
877 cX = cosf( cam.angles[0] ),
878 sY = sinf( cam.angles[1] ),
879 cY = cosf( cam.angles[1] );
880
881 v3f offset = { -sX * cY, sY, cX * cY };
882
883 v3_muladds( display->transform.co, offset,
884 dist*workshop_form.view_dist, cam.pos );
885
886 cam.pos[0] += -sX*workshop_form.view_offset[2];
887 cam.pos[2] += cX*workshop_form.view_offset[2];
888 cam.pos[0] += cX*workshop_form.view_offset[0];
889 cam.pos[2] += sX*workshop_form.view_offset[0];
890 cam.pos[1] += workshop_form.view_offset[1];
891
892 cam.nearz = 0.01f;
893 cam.farz = 100.0f;
894 cam.fov = ref->fov;
895
896 camera_update_transform( &cam );
897 camera_update_view( &cam );
898 camera_update_projection( &cam );
899 camera_finalize( &cam );
900
901 m4x3f mmdl, mmdl1;
902 mdl_transform_m4x3( &display->transform, mmdl );
903 mdl_transform_m4x3( &display1->transform, mmdl1 );
904
905 /* force update this for nice shadows. its usually set in the world
906 * pre-render step, but that includes timer stuff
907 */
908 struct player_board *board = &workshop_form.board_model;
909 struct ub_world_lighting *ubo = &world->ub_lighting;
910 v3f vp0, vp1;
911 v3_copy((v3f){0.0f,0.1f, board->truck_positions[0][2]}, vp0 );
912 v3_copy((v3f){0.0f,0.1f, board->truck_positions[1][2]}, vp1 );
913 m4x3_mulv( mmdl1, vp0, ubo->g_board_0 );
914 m4x3_mulv( mmdl1, vp1, ubo->g_board_1 );
915 glBindBuffer( GL_UNIFORM_BUFFER, world->ubo_lighting );
916 glBufferSubData( GL_UNIFORM_BUFFER, 0,
917 sizeof(struct ub_world_lighting), &world->ub_lighting );
918
919 render_world( world, &cam, 1 );
920 render_board( &cam, world, board, mmdl, k_board_shader_entity );
921 render_board( &cam, world, board, mmdl1, k_board_shader_entity );
922
923 glBindFramebuffer( GL_FRAMEBUFFER, 0 );
924 glViewport( 0,0, vg.window_x, vg.window_y );
925 }
926
927 /*
928 * ImGUI section for workshop form
929 * -----------------------------------------------------------------------------
930 */
931
932 VG_STATIC void workshop_changed_model_path( char *buf, u32 len ){
933 workshop_form.submission.submit_file_and_image = 1;
934 }
935
936 VG_STATIC void workshop_changed_title( char *buf, u32 len ){
937 workshop_form.submission.submit_title = 1;
938 }
939
940 VG_STATIC void workshop_changed_description( char *buf, u32 len ){
941 workshop_form.submission.submit_description = 1;
942 }
943
944 VG_STATIC void workshop_form_gui_edit_page( ui_rect content )
945 {
946 ui_rect image_plane;
947 ui_split_px( content, k_ui_axis_h, 300, 0, image_plane, content );
948 ui_fill( image_plane, ui_colour( k_ui_bg+0 ) );
949
950 ui_rect img_box;
951 ui_fit_item( image_plane, (ui_px[2]){ 3, 2 }, img_box );
952
953 if( workshop_form.file_intent == k_workshop_form_file_intent_keep_old ){
954 ui_image( img_box, gpipeline.fb_workshop_preview->attachments[0].id );
955 }
956 else if( workshop_form.file_intent == k_workshop_form_file_intent_new ){
957 ui_image( img_box, gpipeline.fb_workshop_preview->attachments[0].id );
958 int hover = ui_inside_rect( img_box, vg_ui.mouse ),
959 target = ui_inside_rect( img_box, vg_ui.mouse_click );
960
961 if( ui_click_down(UI_MOUSE_MIDDLE) && target ){
962 v3_copy( workshop_form.view_offset,
963 workshop_form.view_offset_begin );
964 }
965 else if( ui_click_down(UI_MOUSE_LEFT) && target ){
966 v2_copy( workshop_form.view_angles,
967 workshop_form.view_angles_begin );
968 }
969
970 if( ui_clicking(UI_MOUSE_MIDDLE) && target ){
971 v2f delta = { vg_ui.mouse[0]-vg_ui.mouse_click[0],
972 vg_ui.mouse[1]-vg_ui.mouse_click[1] };
973
974 float *begin = workshop_form.view_offset_begin,
975 *offset = workshop_form.view_offset;
976 offset[0] = vg_clampf( begin[0]-delta[0]*0.002f, -1.0f, 1.0f );
977 offset[2] = vg_clampf( begin[2]-delta[1]*0.002f, -1.0f, 1.0f );
978 workshop_form.view_changed = 1;
979 }
980 else if( ui_clicking(UI_MOUSE_LEFT) && target ){
981 v2f delta = { vg_ui.mouse[0]-vg_ui.mouse_click[0],
982 vg_ui.mouse[1]-vg_ui.mouse_click[1] };
983
984 v2f angles;
985 v2_muladds( workshop_form.view_angles_begin, delta, 0.002f, angles);
986
987 float limit = VG_PIf*0.2f;
988
989 angles[0] = vg_clampf( angles[0], -limit, limit );
990 angles[1] = vg_clampf( angles[1], -limit, limit );
991
992 v2_copy( angles, workshop_form.view_angles );
993 workshop_form.view_changed = 1;
994 }
995
996 if( !ui_clicking(UI_MOUSE_LEFT) && hover ){
997 float zoom = workshop_form.view_dist;
998 zoom += vg.mouse_wheel[1] * -0.07f;
999 zoom = vg_clampf( zoom, 0.4f, 2.0f );
1000
1001 if( zoom != workshop_form.view_dist ){
1002 workshop_form.view_changed = 1;
1003 workshop_form.view_dist = zoom;
1004 }
1005 }
1006 }
1007 else{
1008 ui_text( img_box, "No image", 1, k_ui_align_middle_center,
1009 ui_colour( k_ui_orange ) );
1010 }
1011
1012 /* file path */
1013 ui_rect null, file_entry, file_button;
1014 ui_split_px( content, k_ui_axis_h, 8, 0, null, content );
1015 ui_split_px( content, k_ui_axis_h, 28, 0, file_entry, content );
1016 ui_split_px( file_entry, k_ui_axis_v, file_entry[2]-128, 0,
1017 file_entry, file_button );
1018
1019 if( workshop_form.file_intent != k_workshop_form_file_intent_none ){
1020 ui_text( file_entry, workshop_form.model_path, 1, k_ui_align_middle_left,
1021 ui_colour( k_ui_fg+4 ) );
1022
1023 if( ui_button_text( file_button, "Remove", 1 ) ){
1024 player_board_unload( &workshop_form.board_model );
1025 workshop_form.file_intent = k_workshop_form_file_intent_none;
1026 workshop_form.model_path[0] = '\0';
1027 }
1028 }
1029 else{
1030 struct ui_textbox_callbacks callbacks = {
1031 .change = workshop_changed_model_path
1032 };
1033
1034 ui_textbox( file_entry, workshop_form.model_path,
1035 vg_list_size(workshop_form.model_path), 0, &callbacks );
1036
1037 if( ui_button_text( file_button, "Load", 1 ) ){
1038 workshop_find_preview_entity();
1039 workshop_op_load_model();
1040 }
1041 }
1042
1043 ui_rect title_entry, label;
1044 ui_split_px( content, k_ui_axis_h, 8, 0, null, content );
1045 ui_split_px( content, k_ui_axis_h, 28, 0, title_entry, content );
1046
1047 const char *str_title = "Title:", *str_desc = "Description:";
1048 ui_split_px( title_entry, k_ui_axis_v,
1049 ui_text_line_width(str_title)+8, 0, label, title_entry );
1050
1051 /* title box */
1052 {
1053 struct ui_textbox_callbacks callbacks = {
1054 .change = workshop_changed_title
1055 };
1056 ui_text( label, str_title, 1, k_ui_align_middle_left, 0 );
1057 ui_textbox( title_entry, workshop_form.submission.title,
1058 vg_list_size(workshop_form.submission.title), 0, &callbacks );
1059 }
1060
1061 /* description box */
1062 {
1063 struct ui_textbox_callbacks callbacks = {
1064 .change = workshop_changed_description
1065 };
1066 ui_rect desc_entry;
1067 ui_split_px( content, k_ui_axis_h, 8, 0, null, content );
1068 ui_split_px( content, k_ui_axis_h, 28, 0, label, content );
1069 ui_split_px( content, k_ui_axis_h, 28*4, 0, desc_entry, content );
1070 ui_text( label, str_desc, 1, k_ui_align_middle_left, 0 );
1071 ui_textbox( desc_entry, workshop_form.submission.description,
1072 vg_list_size(workshop_form.submission.description),
1073 UI_TEXTBOX_MULTILINE|UI_TEXTBOX_WRAP, &callbacks );
1074 }
1075
1076 /* submissionable */
1077 ui_rect submission_row;
1078 ui_split_px( content, k_ui_axis_h, 8, 0, null, content );
1079 ui_split_px( content, k_ui_axis_h, content[3]-32-8, 0, content,
1080 submission_row );
1081
1082 ui_rect submission_center;
1083 rect_copy( submission_row, submission_center );
1084 submission_center[2] = 256;
1085 ui_rect_center( submission_row, submission_center );
1086
1087 ui_rect btn_left, btn_right;
1088 ui_split_ratio( submission_center, k_ui_axis_v, 0.5f, 8,
1089 btn_left, btn_right );
1090
1091 if( ui_button_text( btn_left, "Publish", 1 ) ){
1092 workshop_op_submit();
1093 }
1094 if( ui_button_text( btn_right, "Cancel", 1 ) ){
1095 vg_info( "left\n" );
1096 }
1097
1098 /* disclaimer */
1099 /* TODO!! OPEN THIS LINK */
1100 const char *disclaimer_text =
1101 "By submitting this item, you agree to the workshop terms of service";
1102
1103 ui_rect disclaimer_row, inner, link;
1104 ui_split_px( content, k_ui_axis_h, 8, 0, null, content );
1105 ui_split_px( content, k_ui_axis_h, content[3]-32, 0, content,
1106 disclaimer_row );
1107
1108 ui_px btn_width = 32;
1109
1110 rect_copy( disclaimer_row, inner );
1111 inner[2] = ui_text_line_width( disclaimer_text ) + btn_width+8;
1112
1113 ui_rect_center( disclaimer_row, inner );
1114 ui_split_px( inner, k_ui_axis_v, inner[2]-btn_width, 0, label, btn_right);
1115 ui_rect_pad( btn_right, 2 );
1116
1117 if( ui_button_text( btn_right, "\x91", 2 ) ){
1118 ISteamFriends *hSteamFriends = SteamAPI_SteamFriends();
1119 SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage( hSteamFriends,
1120 "https://steamcommunity.com/sharedfiles/workshoplegalagreement",
1121 k_EActivateGameOverlayToWebPageMode_Default );
1122 }
1123
1124 ui_text( label, disclaimer_text, 1, k_ui_align_middle_left,
1125 ui_colour( k_ui_fg+4 ) );
1126 }
1127
1128 VG_STATIC void workshop_form_gui_sidebar( ui_rect sidebar )
1129 {
1130 /*
1131 * sidebar existing entries panel
1132 */
1133 ui_fill( sidebar, ui_colour( k_ui_bg+2 ) );
1134
1135 ui_rect title;
1136 ui_split_px( sidebar, k_ui_axis_h, 28, 0, title, sidebar );
1137 ui_text( title, "Your submissions", 1, k_ui_align_middle_center, 0 );
1138
1139 ui_rect controls, btn_create_new;
1140 ui_split_px( sidebar, k_ui_axis_h, 32, 0, controls, sidebar );
1141 ui_split_px( sidebar, k_ui_axis_h, sidebar[3]-32, 0,
1142 sidebar, btn_create_new );
1143 ui_fill( controls, ui_colour( k_ui_bg+1 ) );
1144 ui_outline( controls, -1, ui_colour( k_ui_bg+4 ) );
1145
1146 char buf[32];
1147 strcpy( buf, "page " );
1148 int i = 5;
1149
1150 /* TODO: for what it is, this code is getting a bit.. special */
1151 if( workshop_form.view_published_page_id )
1152 i += highscore_intl( buf+i, workshop_form.view_published_page_id, 4 );
1153 else buf[ i ++ ] = '0';
1154 ;
1155 buf[ i ++ ] = '/';
1156 i += highscore_intl( buf+i, workshop_form.view_published_page_count, 4 );
1157 buf[ i ++ ] = '\0';
1158
1159 ui_rect info;
1160 ui_split_ratio( controls, k_ui_axis_v, 0.25f, 0, info, controls );
1161 ui_text( info, buf, 1, k_ui_align_middle_center, 0 );
1162
1163 ui_rect btn_left, btn_right;
1164 ui_split_ratio( controls, k_ui_axis_v, 0.5f, 2, btn_left, btn_right );
1165
1166 if( ui_button_text( btn_left, "newer", 1 ) ){
1167 workshop_view_page( workshop_form.view_published_page_id-1 );
1168 }
1169
1170 if( ui_button_text( btn_right, "older", 1 ) ){
1171 workshop_view_page( workshop_form.view_published_page_count+1 );
1172 }
1173
1174 if( ui_button_text( btn_create_new, "Create New Item", 1 ) ){
1175 workshop_reset_submission_data();
1176 workshop_form.submission.submit_title = 1;
1177 workshop_form.submission.submit_description = 1;
1178 workshop_form.submission.submit_file_and_image = 1;
1179 workshop_form.page = k_workshop_form_edit;
1180 workshop_find_preview_entity();
1181 }
1182
1183 for( int i=0; i<workshop_form.published_files_list_length; i++ ){
1184 ui_rect item;
1185 ui_split_px( sidebar, k_ui_axis_h, 28, 0, item, sidebar );
1186 ui_rect_pad( item, 4 );
1187
1188 struct published_file *pfile = &workshop_form.published_files_list[i];
1189 if( ui_button_text( item, pfile->title, 1 ) ){
1190 if( pfile->result == k_EResultOK ){
1191 vg_info( "Select index: %d\n", pfile->result_index );
1192 workshop_op_download_and_view_submission( pfile->result_index );
1193 }
1194 else{
1195 vg_warn( "Cannot select that item, result not OK\n" );
1196 }
1197 }
1198 }
1199 }
1200
1201 VG_STATIC void workshop_form_gui(void)
1202 {
1203 enum workshop_form_page stable_page = workshop_form.page;
1204 if( stable_page == k_workshop_form_hidden ) return;
1205
1206 ui_rect null;
1207 ui_rect screen = { 0, 0, vg.window_x, vg.window_y };
1208 ui_rect window = { 0, 0, 1000, 700 };
1209 ui_rect_center( screen, window );
1210 vg_ui.wants_mouse = 1;
1211
1212 ui_fill( window, ui_colour( k_ui_bg+1 ) );
1213 ui_outline( window, 1, ui_colour( k_ui_bg+7 ) );
1214
1215 ui_rect title, panel;
1216 ui_split_px( window, k_ui_axis_h, 28, 0, title, panel );
1217 ui_fill( title, ui_colour( k_ui_bg+7 ) );
1218 ui_text( title, "Workshop tool", 1, k_ui_align_middle_center,
1219 ui_colourcont(k_ui_bg+7) );
1220
1221 ui_rect quit_button;
1222 ui_split_px( title, k_ui_axis_v, title[2]-title[3], 2, title, quit_button );
1223
1224 if( workshop_form.operation == k_workshop_form_op_none ){
1225 if( ui_button_text( quit_button, "X", 1 ) ){
1226 workshop_quit_form();
1227 return;
1228 }
1229 }
1230
1231 /*
1232 * temporary operation blinders, we don't yet have a nice way to show the
1233 * user that we're doing something uninterruptable, so the code just
1234 * escapes here and we show them a basic string
1235 */
1236
1237 if( workshop_form.operation != k_workshop_form_op_none ){
1238 const char *op_string = "The programmer has not bothered to describe "
1239 "the current operation that is running.";
1240
1241 switch(workshop_form.operation){
1242 case k_workshop_form_op_loading_model:
1243 op_string = "Operation in progress: Loading model file.";
1244 break;
1245 case k_workshop_form_op_publishing_update:
1246 op_string = "Operation in progress: publishing submission update "
1247 "to steam.";
1248 break;
1249 case k_workshop_form_op_downloading_submission:
1250 op_string = "Operation in progress: downloading existing submission"
1251 " from Steam services.";
1252 break;
1253 default: break;
1254 }
1255
1256 ui_text( panel, op_string, 1, k_ui_align_middle_center, 0 );
1257 return;
1258 }
1259
1260 /* re draw board preview if need to */
1261 if( (stable_page == k_workshop_form_edit) &&
1262 workshop_form.view_changed &&
1263 workshop_form.file_intent == k_workshop_form_file_intent_new )
1264 {
1265 workshop_render_preview();
1266 workshop_form.view_changed = 0;
1267 }
1268
1269 struct workshop_form *form = &workshop_form;
1270
1271 ui_rect sidebar, content;
1272 ui_split_ratio( panel, k_ui_axis_v, 0.3f, 1, sidebar, content );
1273
1274 /* content page */
1275 ui_rect_pad( content, 8 );
1276
1277 if( stable_page == k_workshop_form_edit ){
1278 workshop_form_gui_edit_page( content );
1279 }
1280 else if( stable_page == k_workshop_form_open ){
1281 ui_text( content, "Nothing selected.", 1, k_ui_align_middle_center,
1282 ui_colour( k_ui_fg+4 ) );
1283 }
1284 else if( stable_page >= k_workshop_form_cclosing ){
1285 ui_rect submission_row;
1286 ui_split_px( content, k_ui_axis_h, content[3]-32-8, 0, content,
1287 submission_row );
1288
1289 u32 colour;
1290
1291 if( stable_page == k_workshop_form_closing_bad )
1292 colour = ui_colour( k_ui_red+k_ui_brighter );
1293 else
1294 colour = ui_colour( k_ui_green+k_ui_brighter );
1295
1296 ui_text( content, workshop_form.failure_or_success_string, 1,
1297 k_ui_align_middle_center, colour );
1298
1299 ui_rect submission_center;
1300 rect_copy( submission_row, submission_center );
1301 submission_center[2] = 128;
1302 ui_rect_center( submission_row, submission_center );
1303 ui_rect_pad( submission_center, 8 );
1304
1305 if( ui_button_text( submission_center, "OK", 1 ) ){
1306 workshop_form.page = k_workshop_form_open;
1307 }
1308 }
1309
1310 workshop_form_gui_sidebar( sidebar );
1311 }
1312
1313 #endif /* WORKSHOP_C */