Skip to content

Commit

Permalink
Make auto-updater optional
Browse files Browse the repository at this point in the history
  • Loading branch information
shomykohai committed Jun 9, 2024
1 parent 5e33ef3 commit d0a85a6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
21 changes: 11 additions & 10 deletions addons/quest_system/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ func _enter_tree() -> void:
translation_plugin = QuestPropertyTranslationPlugin.new()
add_translation_parser_plugin(translation_plugin)
# Check for new version
var http_request := HTTPRequest.new()
http_request.request_completed.connect(_http_request_completed)
EditorInterface.get_base_control().add_child(http_request)
http_request.request(REMOTE_RELEASE_URL)
await http_request.request_completed
http_request.queue_free()
if QuestSystemSettings.get_config_setting("check_for_updates_on_startup", true):
var http_request := HTTPRequest.new()
http_request.request_completed.connect(_http_request_completed)
EditorInterface.get_base_control().add_child(http_request)
http_request.request(REMOTE_RELEASE_URL)
await http_request.request_completed
http_request.queue_free()

func _exit_tree() -> void:
remove_autoload_singleton("QuestSystem")
Expand All @@ -40,13 +41,13 @@ func _get_plugin_path() -> String:
func _http_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray):
if result != HTTPRequest.RESULT_SUCCESS:
return

var data: Dictionary = JSON.parse_string(body.get_string_from_utf8())
if _version_to_int(data["tag_name"]) <= _version_to_int(get_plugin_version()):
return

var title_bar: Node = null

# Here we get the title bar node in a unconventional way
for node in EditorInterface.get_base_control().get_children(true):
if node is VBoxContainer:
Expand All @@ -60,7 +61,7 @@ func _http_request_completed(result: int, response_code: int, headers: PackedStr
update_button.pressed.connect(_on_update_button_pressed.bind(get_plugin_version(), data["tag_name"]))
title_bar.add_child(update_button)
title_bar.move_child(update_button, title_bar.get_child_count(true) - 3)

func _on_update_button_pressed(old_ver: String, new_ver: String) -> void:
var update_panel: AcceptDialog = load(_get_plugin_path()+"/views/update_dialog.tscn").instantiate()
update_panel.set_meta("old_ver", old_ver)
Expand Down
10 changes: 8 additions & 2 deletions addons/quest_system/settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const MAIN_CATEGORY: StringName = "quest_system"
const CONFIG_CATEGORY: StringName = MAIN_CATEGORY + "/config"

static func initialize(plugin_path: StringName) -> void:
# Addon settings
_init_setting(
CONFIG_CATEGORY + "/check_for_updates_on_startup",
true, TYPE_BOOL)

# Pools
_init_setting(
CONFIG_CATEGORY + "/available_quest_pool_path",
Expand All @@ -23,19 +28,20 @@ static func initialize(plugin_path: StringName) -> void:
CONFIG_CATEGORY + "/additional_pools",
[],
TYPE_ARRAY, PROPERTY_HINT_TYPE_STRING, ("%s:" % TYPE_STRING))

# Default Pools settings
_init_setting(
CONFIG_CATEGORY + "/require_objective_completed",
true, TYPE_BOOL)



static func _init_setting(name: String, default_value: Variant, type:=typeof(default_value), hint:=PROPERTY_HINT_NONE, hint_string:=""):
if not ProjectSettings.has_setting(name):
ProjectSettings.set_setting(name, default_value)

ProjectSettings.set_initial_value(name, default_value)

var hint_info: Dictionary = {
"name": name,
"type": type,
Expand Down
18 changes: 9 additions & 9 deletions addons/quest_system/translation_plugin.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
extends EditorTranslationParserPlugin

func _parse_file(path: String, msgids: Array[String], msgids_context_plural: Array[Array]) -> void:
var res := ResourceLoader.load(path)
if not res: return
if not res is Quest: return
for property in res.get_script().get_script_property_list():
if property.type != 4: continue # If the property is not a string, we skip it
# Here we check if the property is an exported variable
if property.usage & PROPERTY_USAGE_STORAGE or property.usage & PROPERTY_USAGE_SCRIPT_VARIABLE:
msgids.append("quest_%s/%s"% [res.id, property["name"]]) # quest_1/quest_name
var res := ResourceLoader.load(path)
if not res: return
if not res is Quest: return
for property in res.get_script().get_script_property_list():
if property.type != 4: continue # If the property is not a string, we skip it
# Here we check if the property is an exported variable
if property.usage & PROPERTY_USAGE_STORAGE or property.usage & PROPERTY_USAGE_SCRIPT_VARIABLE:
msgids.append("quest_%s/%s"% [res.id, property["name"]]) # quest_1/quest_name

func _get_recognized_extensions() -> PackedStringArray:
return ['tres']
return ['tres']

0 comments on commit d0a85a6

Please sign in to comment.