Advertisement
psychworld

Workshop Uploader Script

Jun 5th, 2024
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Control
  2.  
  3. var path = ""
  4. var icon_path = ""
  5. var preview_path = ""
  6. var pack_name = "Texture Pack"
  7. var workshop_item_id = 0
  8. var item_handle = 0
  9.  
  10. ## TODO: ADD TOS CHECK
  11.  
  12.  
  13. func _ready():
  14.     Steam.ugc_query_completed.connect(func(handle_id, result, results_returned, total_matching, cached): item_query_completed(handle_id, result, results_returned, total_matching, cached))
  15.     Steam.item_updated.connect(func(result, tos): item_updated_signal_function(result, tos))
  16.     Steam.item_created.connect(func(result, file_id, accept_tos): new_item_created(result, file_id, accept_tos))
  17.     #print(workshop_item_id)
  18.     if workshop_item_id != 0:
  19.         print("Attempting to find the existing data of workshop item " + str(workshop_item_id))
  20.         item_handle = Steam.createQueryUGCDetailsRequest([workshop_item_id])
  21.         Steam.sendQueryUGCRequest(item_handle)
  22.  
  23.  
  24. func new_item_created(result, file_id, accept_tos):
  25.     if accept_tos:
  26.         Steam.showWorkshopEULA()
  27.     if result == 1: # OK
  28.         result = "OK"
  29.         workshop_item_id = file_id
  30.         save_texture_pack_data(pack_name, file_id)
  31.     print("[UGC] New Item Created: " + str(result), " ", str(file_id), " ", str(accept_tos))
  32.    
  33.  
  34. func item_query_completed(handle_id, result, results_returned, total_matching, cached):
  35.     # handle_id - ID of the Handle associated with this call result
  36.     # result - EResult (int of an enum)
  37.     # results_returned - (uint32) The number of items returned in this result set
  38.     # total_matching - (uint32) The total number of items that matched the query in the database
  39.     # cached - (bool) Indicates whether this data was retrieved from the local cache
  40.     if result == 1:
  41.         result = "OK"
  42.     print("[UGC] Item Query Completed: " + str(handle_id), " - ", str(result), " - ", str(results_returned), str(total_matching), str(cached))
  43.     var item = Steam.getQueryUGCResult(item_handle, 0)
  44.     if item != null:
  45.         %TitleText.text = str(item["title"])
  46.         %DescriptionText.text = str(item["description"])
  47.     Steam.releaseQueryUGCRequest(item_handle)
  48.  
  49.  
  50. func _on_publish_button_pressed():
  51.     if pack_name == "":
  52.         print("[UGC] The pack name is empty.")
  53.         return
  54.     if path == "[UGC] The path is empty.":
  55.         return
  56.     if workshop_item_id == 0:
  57.         Steam.createItem(2304350, Steam.WORKSHOP_FILE_TYPE_COMMUNITY)
  58.         print("[UGC] Attempting to create a new UGC item...")
  59.         await Steam.item_created
  60.     if workshop_item_id != 0:
  61.         ready_to_update(workshop_item_id)
  62.     #var item = UGC_Item.new()
  63.     #var item_id = floor(randi() + Time.get_unix_time_from_system())
  64.     #item._init(3237207443)
  65.     #print(item_id)
  66.     #print("[UGC] Attempting to create a new UGC item...")
  67.     #Steam.createItem(2304350, Steam.WORKSHOP_FILE_TYPE_COMMUNITY)
  68.  
  69.  
  70. func item_updated_signal_function(result, tos):
  71.     if tos == true:
  72.         Steam.activateGameOverlayToWebPage("steam://url/CommunityFilePage/" + str(workshop_item_id))
  73.     if result == 1:
  74.         result = "OK"
  75.         %PublishLabel.text = "Published!"
  76.         %PublishButton.disabled = true
  77.     elif result == 9:
  78.         result = "File not found!"
  79.         %PublishLabel.text = "Failed!"
  80.         %PublishButton.disabled = true
  81.     else:
  82.         %PublishLabel.text = "Failed!"
  83.         %PublishButton.disabled = true
  84.     print("[UGC] Item updated came back with result: " + str(result) + " and does ToS need to be accepted? " + str(tos))
  85.     await get_tree().create_timer(3, true).timeout
  86.     %PublishLabel.text = "Publish"
  87.     %PublishButton.disabled = false
  88.  
  89.  
  90. func ready_to_update(id):
  91.     print("[UGC] Attempting to add data to the UGC item at ID " + str(id))
  92.     if id != 0:
  93.         print("[UGC] Attempting to edit a UGC item with the ID of %s" % [str(id)])
  94.     var handle = Steam.startItemUpdate(2304350, id)
  95.     Steam.setItemTitle(handle, str(%TitleText.text))
  96.     print("[UGC] Item Title set to " + str(%TitleText.text))
  97.     Steam.setItemDescription(handle, str(%DescriptionText.text))
  98.     print("[UGC] Item Description set to " + str(%DescriptionText.text))
  99.     if %VisibilityOption.selected == 1:
  100.         Steam.setItemVisibility(handle, Steam.REMOTE_STORAGE_PUBLISHED_VISIBILITY_PRIVATE)
  101.         print("[UGC] Item Visbility set to Private")
  102.     elif %VisibilityOption.selected == 2:
  103.         Steam.setItemVisibility(handle, Steam.REMOTE_STORAGE_PUBLISHED_VISIBILITY_UNLISTED)
  104.         print("[UGC] Item Visbility set to Unlisted")
  105.     elif %VisibilityOption.selected == 3:
  106.         Steam.setItemVisibility(handle, Steam.REMOTE_STORAGE_PUBLISHED_VISIBILITY_FRIENDS_ONLY)
  107.         print("[UGC] Item Visbility set to Friends Only")
  108.     else:
  109.         Steam.setItemVisibility(handle, Steam.REMOTE_STORAGE_PUBLISHED_VISIBILITY_PUBLIC)
  110.         print("[UGC] Item Visbility set to Public")
  111.     Steam.setItemTags(handle, ["texture-pack"], false)
  112.     if path != "":
  113.         Steam.setItemContent(handle, path)
  114.         #Steam.addItemPreviewFile(handle, path, Steam.ITEM_PREVIEW_TYPE_IMAGE)
  115.         print("[UGC] Updated Item Content")
  116.     if preview_path != "":
  117.         Steam.setItemPreview(handle, preview_path)
  118.         #Steam.addItemPreviewFile(handle, preview_path, Steam.ITEM_PREVIEW_TYPE_IMAGE)
  119.         print("[UGC] Updated Item Preview")
  120.     #else: # IF THE TEXTURE PACK DOES NOT HAVE AN ICON SPECIFIED, USE THE TEXTURE PACK ITSELF AS THE PREVIEW
  121.         #Steam.setItemPreview(handle, path)
  122.     Steam.submitItemUpdate(handle, str(Time.get_unix_time_from_system())) # Change note is for the user to have a changelog
  123.     save_texture_pack_data(pack_name, workshop_item_id)
  124.  
  125.  
  126. func save_texture_pack_data(texture_pack_name, workshop_id):
  127.     texture_pack_name = texture_pack_name.replace(" ", "_")
  128.     var full_path = Global.save_path + "/texture_packs/" + str(texture_pack_name) + "/pack_info" + ".tres"
  129.     print("[UGC] Saving texture pack information file at the path: " + str(full_path))
  130.     #var dir = DirAccess.open(Global.save_path)
  131.     var settings_data : TexturePackSaveData = load("res://TexturePackSaveData.tres")
  132.     var dir = DirAccess.open(Global.save_path + "/texture_packs/")
  133.     if dir.dir_exists(str(texture_pack_name) + "/"):
  134.         settings_data.workshop_id = workshop_id
  135.         ResourceSaver.save(settings_data, full_path)
  136.         print("[UGC] Successfully saved the texture pack information file to the path: " + str(full_path))
  137.  
  138.  
  139. func _on_menu_button_pressed():
  140.     Global.play_sfx(Global.ui_button_click_sfx)
  141.     var x = load("res://main_menu.tscn").instantiate()
  142.     x.ignoreSettings = true
  143.     get_tree().root.add_child(x)
  144.     self.queue_free()
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement