Advertisement
psychworld

Workshop Browser Script

Jun 5th, 2024
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Control
  2.  
  3. var query_handler
  4. var query_result
  5.  
  6. func _ready():
  7.     Steam.ugc_query_completed.connect(func(handle, result, results_returned, total_matching, cached): query_completed(handle, result, results_returned, total_matching, cached))
  8.    
  9.     query_handler = Steam.createQueryAllUGCRequest( Steam.UGC_QUERY_RANKED_BY_PUBLICATION_DATE,
  10.                                                     Steam.UGC_MATCHING_UGC_TYPE_ITEMS,
  11.                                                     2304350,
  12.                                                     2304350,
  13.                                                     1
  14.                                                 )
  15.     print("Query Handle ID: " + str(query_handler))
  16.     Steam.setMatchAnyTag(query_handler, true)
  17.     #Steam.setReturnOnlyIDs(query_handler, true)
  18.     Steam.sendQueryUGCRequest(query_handler)
  19.     #fetch_query_result(Steam.NUM_UGC_RESULTS_PER_PAGE)
  20.  
  21.  
  22. func query_completed(handle, result, results_returned, total_matching, cached):
  23.     print("%s - %s - %s - %s - %s" % [handle, result, results_returned, total_matching, cached])
  24.     if result == Steam.RESULT_OK:
  25.         print("[UGC] Query was completed successfully")
  26.         fetch_query_result(Steam.NUM_UGC_RESULTS_PER_PAGE)
  27.     else:
  28.         print("[UGC] Query failed to get published items. Error: " + str(result))
  29.  
  30.  
  31. func fetch_query_result(number_of_items : int):
  32.     var result : Dictionary
  33.     for i in number_of_items:
  34.         result = Steam.getQueryUGCResult(query_handler, i)
  35.         if not result.is_empty():
  36.             #print("%d - %s" % [i, result])
  37.             var x : WorkshopItem = load("res://ui/workshop_item.tscn").instantiate()
  38.             x.id = result["file_id"]
  39.             x.title = result["title"]
  40.             x.description = result["description"]
  41.             x.author = Steam.getFriendPersonaName(result["steam_id_owner"])
  42.             x.upvotes = result["votes_up"]
  43.             x.downvotes = result["votes_down"]
  44.             x.preview_link = Steam.getQueryUGCPreviewURL(query_handler, i)
  45.             x.data = result
  46.             #x.preview = result["handle_preview-file"]
  47.             %WorkshopItems.add_child(x)
  48.     Steam.releaseQueryUGCRequest(query_handler)
  49.  
  50.  
  51. func _on_menu_button_pressed():
  52.     Global.play_sfx(Global.ui_button_click_sfx)
  53.     var x = load("res://main_menu.tscn").instantiate()
  54.     get_tree().root.call_deferred("add_child", x)
  55.     self.queue_free()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement