Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Control
- var path = ""
- var icon_path = ""
- var preview_path = ""
- var pack_name = "Texture Pack"
- var workshop_item_id = 0
- var item_handle = 0
- ## TODO: ADD TOS CHECK
- func _ready():
- 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))
- Steam.item_updated.connect(func(result, tos): item_updated_signal_function(result, tos))
- Steam.item_created.connect(func(result, file_id, accept_tos): new_item_created(result, file_id, accept_tos))
- #print(workshop_item_id)
- if workshop_item_id != 0:
- print("Attempting to find the existing data of workshop item " + str(workshop_item_id))
- item_handle = Steam.createQueryUGCDetailsRequest([workshop_item_id])
- Steam.sendQueryUGCRequest(item_handle)
- func new_item_created(result, file_id, accept_tos):
- if accept_tos:
- Steam.showWorkshopEULA()
- if result == 1: # OK
- result = "OK"
- workshop_item_id = file_id
- save_texture_pack_data(pack_name, file_id)
- print("[UGC] New Item Created: " + str(result), " ", str(file_id), " ", str(accept_tos))
- func item_query_completed(handle_id, result, results_returned, total_matching, cached):
- # handle_id - ID of the Handle associated with this call result
- # result - EResult (int of an enum)
- # results_returned - (uint32) The number of items returned in this result set
- # total_matching - (uint32) The total number of items that matched the query in the database
- # cached - (bool) Indicates whether this data was retrieved from the local cache
- if result == 1:
- result = "OK"
- print("[UGC] Item Query Completed: " + str(handle_id), " - ", str(result), " - ", str(results_returned), str(total_matching), str(cached))
- var item = Steam.getQueryUGCResult(item_handle, 0)
- if item != null:
- %TitleText.text = str(item["title"])
- %DescriptionText.text = str(item["description"])
- Steam.releaseQueryUGCRequest(item_handle)
- func _on_publish_button_pressed():
- if pack_name == "":
- print("[UGC] The pack name is empty.")
- return
- if path == "[UGC] The path is empty.":
- return
- if workshop_item_id == 0:
- Steam.createItem(2304350, Steam.WORKSHOP_FILE_TYPE_COMMUNITY)
- print("[UGC] Attempting to create a new UGC item...")
- await Steam.item_created
- if workshop_item_id != 0:
- ready_to_update(workshop_item_id)
- #var item = UGC_Item.new()
- #var item_id = floor(randi() + Time.get_unix_time_from_system())
- #item._init(3237207443)
- #print(item_id)
- #print("[UGC] Attempting to create a new UGC item...")
- #Steam.createItem(2304350, Steam.WORKSHOP_FILE_TYPE_COMMUNITY)
- func item_updated_signal_function(result, tos):
- if tos == true:
- Steam.activateGameOverlayToWebPage("steam://url/CommunityFilePage/" + str(workshop_item_id))
- if result == 1:
- result = "OK"
- %PublishLabel.text = "Published!"
- %PublishButton.disabled = true
- elif result == 9:
- result = "File not found!"
- %PublishLabel.text = "Failed!"
- %PublishButton.disabled = true
- else:
- %PublishLabel.text = "Failed!"
- %PublishButton.disabled = true
- print("[UGC] Item updated came back with result: " + str(result) + " and does ToS need to be accepted? " + str(tos))
- await get_tree().create_timer(3, true).timeout
- %PublishLabel.text = "Publish"
- %PublishButton.disabled = false
- func ready_to_update(id):
- print("[UGC] Attempting to add data to the UGC item at ID " + str(id))
- if id != 0:
- print("[UGC] Attempting to edit a UGC item with the ID of %s" % [str(id)])
- var handle = Steam.startItemUpdate(2304350, id)
- Steam.setItemTitle(handle, str(%TitleText.text))
- print("[UGC] Item Title set to " + str(%TitleText.text))
- Steam.setItemDescription(handle, str(%DescriptionText.text))
- print("[UGC] Item Description set to " + str(%DescriptionText.text))
- if %VisibilityOption.selected == 1:
- Steam.setItemVisibility(handle, Steam.REMOTE_STORAGE_PUBLISHED_VISIBILITY_PRIVATE)
- print("[UGC] Item Visbility set to Private")
- elif %VisibilityOption.selected == 2:
- Steam.setItemVisibility(handle, Steam.REMOTE_STORAGE_PUBLISHED_VISIBILITY_UNLISTED)
- print("[UGC] Item Visbility set to Unlisted")
- elif %VisibilityOption.selected == 3:
- Steam.setItemVisibility(handle, Steam.REMOTE_STORAGE_PUBLISHED_VISIBILITY_FRIENDS_ONLY)
- print("[UGC] Item Visbility set to Friends Only")
- else:
- Steam.setItemVisibility(handle, Steam.REMOTE_STORAGE_PUBLISHED_VISIBILITY_PUBLIC)
- print("[UGC] Item Visbility set to Public")
- Steam.setItemTags(handle, ["texture-pack"], false)
- if path != "":
- Steam.setItemContent(handle, path)
- #Steam.addItemPreviewFile(handle, path, Steam.ITEM_PREVIEW_TYPE_IMAGE)
- print("[UGC] Updated Item Content")
- if preview_path != "":
- Steam.setItemPreview(handle, preview_path)
- #Steam.addItemPreviewFile(handle, preview_path, Steam.ITEM_PREVIEW_TYPE_IMAGE)
- print("[UGC] Updated Item Preview")
- #else: # IF THE TEXTURE PACK DOES NOT HAVE AN ICON SPECIFIED, USE THE TEXTURE PACK ITSELF AS THE PREVIEW
- #Steam.setItemPreview(handle, path)
- Steam.submitItemUpdate(handle, str(Time.get_unix_time_from_system())) # Change note is for the user to have a changelog
- save_texture_pack_data(pack_name, workshop_item_id)
- func save_texture_pack_data(texture_pack_name, workshop_id):
- texture_pack_name = texture_pack_name.replace(" ", "_")
- var full_path = Global.save_path + "/texture_packs/" + str(texture_pack_name) + "/pack_info" + ".tres"
- print("[UGC] Saving texture pack information file at the path: " + str(full_path))
- #var dir = DirAccess.open(Global.save_path)
- var settings_data : TexturePackSaveData = load("res://TexturePackSaveData.tres")
- var dir = DirAccess.open(Global.save_path + "/texture_packs/")
- if dir.dir_exists(str(texture_pack_name) + "/"):
- settings_data.workshop_id = workshop_id
- ResourceSaver.save(settings_data, full_path)
- print("[UGC] Successfully saved the texture pack information file to the path: " + str(full_path))
- func _on_menu_button_pressed():
- Global.play_sfx(Global.ui_button_click_sfx)
- var x = load("res://main_menu.tscn").instantiate()
- x.ignoreSettings = true
- get_tree().root.add_child(x)
- self.queue_free()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement