diff options
author | Hop311 <hop3114@gmail.com> | 2023-05-16 23:49:52 +0200 |
---|---|---|
committer | Hop311 <hop3114@gmail.com> | 2023-05-17 13:47:02 +0200 |
commit | 578eb8c332810656842f72e0bb94bb0d4dcb9f5e (patch) | |
tree | 64dd37032c36da8e48d5d519ac840e11cc64dc58 /game/addons/openvic-plugin | |
parent | af6a96ed26bca3eaa28c6dca635918061fab7c80 (diff) |
Changed from OpenVic2 to OpenVic
Diffstat (limited to 'game/addons/openvic-plugin')
-rw-r--r-- | game/addons/openvic-plugin/ReleaseExportEditorPlugin.gd | 105 | ||||
-rw-r--r-- | game/addons/openvic-plugin/openvic-plugin.gd | 12 | ||||
-rw-r--r-- | game/addons/openvic-plugin/plugin.cfg | 7 |
3 files changed, 124 insertions, 0 deletions
diff --git a/game/addons/openvic-plugin/ReleaseExportEditorPlugin.gd b/game/addons/openvic-plugin/ReleaseExportEditorPlugin.gd new file mode 100644 index 0000000..ac6c5bc --- /dev/null +++ b/game/addons/openvic-plugin/ReleaseExportEditorPlugin.gd @@ -0,0 +1,105 @@ +extends EditorExportPlugin + +var _repo_hash : StringName = "0000000000000000000000000000000000000000" +var _repo_short_hash : StringName = "0000000" +var _repo_tag : StringName = "<tag missing>" +var _repo_release_name : StringName = "<release name missing>" + +func _get_name(): + return "OpenVic-ReleaseExportEditorPlugin" + +func _export_file(path: String, type: String, features: PackedStringArray) -> void: + if path != "res://src/Utility/GIT_INFO.gd": return + var GitInfoScript : String = "" + _get_commit_long() + _get_commit_short() + _get_tag() + _get_release_name() + GitInfoScript = "class_name _GIT_INFO_\nextends RefCounted\n\n" + GitInfoScript += "const commit_hash : StringName = &\""+ _repo_hash +"\"\n" + GitInfoScript += "const short_hash : StringName = &\""+ _repo_short_hash +"\"\n" + GitInfoScript += "const tag : StringName = &\""+ _repo_tag +"\"\n" + GitInfoScript += "const release_name : StringName = &\""+ _repo_release_name +"\"\n" + add_file(path, GitInfoScript.to_ascii_buffer(), false) + skip() + +# Based on +# https://github.com/godotengine/godot/blob/6ef2f358c741c993b5cdc9680489e2c4f5da25cc/methods.py#L102-L133 +var _cached_hash : StringName = &"" +func _get_commit_hash() -> StringName: + if not _cached_hash.is_empty(): return _cached_hash + + var git_hash := OS.get_environment("OPENVIC_COMMIT") + if not git_hash.is_empty(): + _cached_hash = git_hash + return git_hash + + var git_folder := "../.git" + + if FileAccess.file_exists(git_folder): + var module_folder := FileAccess.open(git_folder, FileAccess.READ).get_line().strip_edges() + if module_folder.begins_with("gitdir: "): + git_folder = module_folder.substr(8) + + if FileAccess.file_exists(git_folder.path_join("HEAD")): + var head := FileAccess.open(git_folder.path_join("HEAD"), FileAccess.READ).get_line().strip_edges() + if head.begins_with("ref: "): + var ref := head.substr(5) + var parts := git_folder.split("/") + if len(parts) > 2 and parts[len(parts) - 2] == "worktrees": + git_folder = "/".join(parts.slice(0, len(parts) - 2)) + head = git_folder.path_join(ref) + var packedrefs := git_folder.path_join("packed-refs") + if FileAccess.file_exists(head): + git_hash = FileAccess.open(head, FileAccess.READ).get_line().strip_edges() + elif FileAccess.file_exists(packedrefs): + for line in FileAccess.open(packedrefs, FileAccess.READ).get_as_text().split("\n", false): + if line.begins_with("#"): continue + var line_split := line.split(" ") + var line_hash := line_split[0] + var line_ref = line_split[1] + if ref == line_ref: + git_hash = line_hash + break + else: + git_hash = head + + _cached_hash = git_hash + + return git_hash + +func _try_get_tag() -> StringName: + var result : StringName = OS.get_environment("OPENVIC_TAG") + if result.is_empty(): + var git_output := [] + if OS.execute("git", ["describe", "--tags", "--abbrev=0"], git_output) == -1: + push_warning("Could not retrieve repository tag.") + return &"" + result = git_output[0].trim_suffix("\n") + return result + +func _get_commit_long(): + var result := _get_commit_hash() + if not result.is_empty(): + _repo_hash = result + print("Hash: " + _repo_hash) + +func _get_commit_short(): + var result := _get_commit_hash().substr(0,7) + if not result.is_empty(): + _repo_short_hash = result + print("Short Hash: " + _repo_short_hash) + +func _get_tag(): + var result := _try_get_tag() + if not result.is_empty(): + _repo_tag = result + print("Tag: " + _repo_tag) + +func _get_release_name(): + var result : StringName = OS.get_environment("OPENVIC_RELEASE") + if result.is_empty(): + result = _try_get_tag() + if not result.is_empty(): + _repo_release_name = result + print("Release Name: " + _repo_release_name) diff --git a/game/addons/openvic-plugin/openvic-plugin.gd b/game/addons/openvic-plugin/openvic-plugin.gd new file mode 100644 index 0000000..dec0312 --- /dev/null +++ b/game/addons/openvic-plugin/openvic-plugin.gd @@ -0,0 +1,12 @@ +@tool +extends EditorPlugin + +const ReleaseExportEditorPlugin := preload("res://addons/openvic-plugin/ReleaseExportEditorPlugin.gd") +var release_export_editor_plugin := ReleaseExportEditorPlugin.new() + +func _enter_tree() -> void: + add_export_plugin(release_export_editor_plugin) + + +func _exit_tree() -> void: + remove_export_plugin(release_export_editor_plugin) diff --git a/game/addons/openvic-plugin/plugin.cfg b/game/addons/openvic-plugin/plugin.cfg new file mode 100644 index 0000000..ee8ef07 --- /dev/null +++ b/game/addons/openvic-plugin/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="OpenVicPlugin" +description="" +author="" +version="" +script="openvic-plugin.gd" |