diff options
author | Spartan322 <Megacake1234@gmail.com> | 2023-03-26 15:22:03 +0200 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2023-03-29 02:53:28 +0200 |
commit | 793a8939c4f721844c276a3d49293c23c902c8d3 (patch) | |
tree | 9d333d26e18e0ad29979170edc031f60866e40cd /game | |
parent | cb5858b80c6dc9918b8366a433ca78a5d4adebed (diff) |
Add automated git release info retrieval on export
Makes debug easier to see and handle
Add commit hash label to MainMenu
Add click-copyable tag, commit hash, and checksum to main menu
Rename VersionChecksumBox to ReleaseInfoBox
Move ReleaseInfoBox to separate scene and script
Add GIT_INFO.gd for generic project running
Add openvic2-plugin addon for handling export plugin
Replaces GIT_INFO.gd on export
Setup build workflow to retrieve commit hash, tag, and release
Diffstat (limited to 'game')
-rw-r--r-- | game/addons/openvic2-plugin/ReleaseExportEditorPlugin.gd | 105 | ||||
-rw-r--r-- | game/addons/openvic2-plugin/openvic2-plugin.gd | 12 | ||||
-rw-r--r-- | game/addons/openvic2-plugin/plugin.cfg | 7 | ||||
-rw-r--r-- | game/project.godot | 2 | ||||
-rw-r--r-- | game/src/GameMenu.tscn | 2 | ||||
-rw-r--r-- | game/src/MainMenu/MainMenu.gd | 7 | ||||
-rw-r--r-- | game/src/MainMenu/MainMenu.tscn | 24 | ||||
-rw-r--r-- | game/src/MainMenu/ReleaseInfoBox.gd | 31 | ||||
-rw-r--r-- | game/src/MainMenu/ReleaseInfoBox.tscn | 38 | ||||
-rw-r--r-- | game/src/Utility/GIT_INFO.gd | 9 | ||||
-rw-r--r-- | game/theme/main_menu.tres | 65 |
11 files changed, 271 insertions, 31 deletions
diff --git a/game/addons/openvic2-plugin/ReleaseExportEditorPlugin.gd b/game/addons/openvic2-plugin/ReleaseExportEditorPlugin.gd new file mode 100644 index 0000000..4e03788 --- /dev/null +++ b/game/addons/openvic2-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 "OpenVic2-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("OPENVIC2_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("OPENVIC2_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("OPENVIC2_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/openvic2-plugin/openvic2-plugin.gd b/game/addons/openvic2-plugin/openvic2-plugin.gd new file mode 100644 index 0000000..8cfa4e8 --- /dev/null +++ b/game/addons/openvic2-plugin/openvic2-plugin.gd @@ -0,0 +1,12 @@ +@tool +extends EditorPlugin + +const ReleaseExportEditorPlugin := preload("res://addons/openvic2-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/openvic2-plugin/plugin.cfg b/game/addons/openvic2-plugin/plugin.cfg new file mode 100644 index 0000000..b3e5611 --- /dev/null +++ b/game/addons/openvic2-plugin/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="OpenVic2Plugin" +description="" +author="" +version="" +script="openvic2-plugin.gd" diff --git a/game/project.godot b/game/project.godot index ae9822c..b2a3098 100644 --- a/game/project.godot +++ b/game/project.godot @@ -38,7 +38,7 @@ window/stretch/aspect="ignore" [editor_plugins] -enabled=PackedStringArray("res://addons/keychain/plugin.cfg") +enabled=PackedStringArray("res://addons/keychain/plugin.cfg", "res://addons/openvic2-plugin/plugin.cfg") [gui] diff --git a/game/src/GameMenu.tscn b/game/src/GameMenu.tscn index 752b1be..aabb29c 100644 --- a/game/src/GameMenu.tscn +++ b/game/src/GameMenu.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=7 format=3 uid="uid://o4u142w4qkln"] [ext_resource type="Script" path="res://src/GameMenu.gd" id="1_cafwe"] -[ext_resource type="PackedScene" uid="uid://c5nyjkpsx14h1" path="res://src/MainMenu/MainMenu.tscn" id="2_2jbkh"] +[ext_resource type="PackedScene" uid="uid://bp5n3mlu45ygw" path="res://src/MainMenu/MainMenu.tscn" id="2_2jbkh"] [ext_resource type="PackedScene" uid="uid://cnbfxjy1m6wja" path="res://src/OptionMenu/OptionsMenu.tscn" id="3_111lv"] [ext_resource type="PackedScene" uid="uid://c8knthxkwj1uj" path="res://src/CreditsMenu/CreditsMenu.tscn" id="4_n0hoo"] [ext_resource type="PackedScene" uid="uid://crhkgngfnxf4y" path="res://src/LobbyMenu/LobbyMenu.tscn" id="4_nofk1"] diff --git a/game/src/MainMenu/MainMenu.gd b/game/src/MainMenu/MainMenu.gd index 662cd90..4420786 100644 --- a/game/src/MainMenu/MainMenu.gd +++ b/game/src/MainMenu/MainMenu.gd @@ -7,18 +7,11 @@ signal credits_button_pressed @export var _new_game_button : BaseButton -@export -var _checksum_label : Label - # REQUIREMENTS: # * SS-3 -# * UIFUN-97 func _ready(): print("From GDScript") TestSingleton.hello_singleton() - # UI-111 - _checksum_label.tooltip_text = "Checksum " + Checksum.get_checksum_text() - _checksum_label.text = "(" + Checksum.get_checksum_text().substr(0, 4) + ")" _on_new_game_button_visibility_changed() # REQUIREMENTS: diff --git a/game/src/MainMenu/MainMenu.tscn b/game/src/MainMenu/MainMenu.tscn index 6159ea6..10bf526 100644 --- a/game/src/MainMenu/MainMenu.tscn +++ b/game/src/MainMenu/MainMenu.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=4 format=3 uid="uid://c5nyjkpsx14h1"] +[gd_scene load_steps=5 format=3 uid="uid://bp5n3mlu45ygw"] [ext_resource type="Theme" uid="uid://qoi3oec48jp0" path="res://theme/main_menu.tres" id="1_1yri4"] [ext_resource type="Script" path="res://src/MainMenu/MainMenu.gd" id="2_nm1fq"] [ext_resource type="PackedScene" uid="uid://b7oncobnacxmt" path="res://src/LocaleButton.tscn" id="3_amonp"] +[ext_resource type="PackedScene" uid="uid://cen7wkmn6og66" path="res://src/MainMenu/ReleaseInfoBox.tscn" id="3_km0er"] -[node name="MainMenu" type="Control" node_paths=PackedStringArray("_new_game_button", "_checksum_label")] +[node name="MainMenu" type="Control" node_paths=PackedStringArray("_new_game_button")] editor_description = "UI-13" layout_mode = 3 anchors_preset = 15 @@ -15,7 +16,6 @@ grow_vertical = 2 theme = ExtResource("1_1yri4") script = ExtResource("2_nm1fq") _new_game_button = NodePath("Panel/VBox/Margin/ButtonList/NewGameButton") -_checksum_label = NodePath("Panel/VBox/BottomMargin/VersionChecksumBox/ChecksumLabel") [node name="Panel" type="PanelContainer" parent="."] layout_mode = 1 @@ -132,25 +132,9 @@ size_flags_stretch_ratio = 0.35 layout_mode = 2 theme_type_variation = &"BottomMargin" -[node name="VersionChecksumBox" type="HBoxContainer" parent="Panel/VBox/BottomMargin"] -editor_description = "UI-31" +[node name="ReleaseInfoBox" parent="Panel/VBox/BottomMargin" instance=ExtResource("3_km0er")] layout_mode = 2 -[node name="VersionLabel" type="Label" parent="Panel/VBox/BottomMargin/VersionChecksumBox"] -layout_mode = 2 -tooltip_text = "OpenVic2 v0.01 \"Primum Mobile\"" -mouse_filter = 1 -theme_type_variation = &"VersionLabel" -text = "v0.01" - -[node name="ChecksumLabel" type="Label" parent="Panel/VBox/BottomMargin/VersionChecksumBox"] -editor_description = "UI-111" -layout_mode = 2 -tooltip_text = "Checksum 00000000" -mouse_filter = 1 -theme_type_variation = &"ChecksumLabel" -text = "(0000)" - [node name="LocaleButton" parent="Panel/VBox/BottomMargin" instance=ExtResource("3_amonp")] layout_mode = 2 size_flags_horizontal = 8 diff --git a/game/src/MainMenu/ReleaseInfoBox.gd b/game/src/MainMenu/ReleaseInfoBox.gd new file mode 100644 index 0000000..48686f3 --- /dev/null +++ b/game/src/MainMenu/ReleaseInfoBox.gd @@ -0,0 +1,31 @@ +extends HBoxContainer + +@export +var _version_label : Button + +@export +var _commit_label : Button + +@export +var _checksum_label : Button + +# REQUIREMENTS: +# * UIFUN-97 +func _ready(): + _version_label.text = _GIT_INFO_.release_name + _version_label.tooltip_text = _GIT_INFO_.tag + _commit_label.text = _GIT_INFO_.short_hash + _commit_label.tooltip_text = _GIT_INFO_.commit_hash + # UI-111 + _checksum_label.tooltip_text = "Checksum " + Checksum.get_checksum_text() + _checksum_label.text = "(" + Checksum.get_checksum_text().substr(0, 4) + ")" + + +func _on_version_label_pressed(): + DisplayServer.clipboard_set(_GIT_INFO_.tag) + +func _on_commit_label_pressed(): + DisplayServer.clipboard_set(_GIT_INFO_.commit_hash) + +func _on_checksum_label_pressed(): + DisplayServer.clipboard_set(Checksum.get_checksum_text()) diff --git a/game/src/MainMenu/ReleaseInfoBox.tscn b/game/src/MainMenu/ReleaseInfoBox.tscn new file mode 100644 index 0000000..d15ae31 --- /dev/null +++ b/game/src/MainMenu/ReleaseInfoBox.tscn @@ -0,0 +1,38 @@ +[gd_scene load_steps=2 format=3 uid="uid://cen7wkmn6og66"] + +[ext_resource type="Script" path="res://src/MainMenu/ReleaseInfoBox.gd" id="1_y2djw"] + +[node name="ReleaseInfoBox" type="HBoxContainer" node_paths=PackedStringArray("_version_label", "_commit_label", "_checksum_label")] +editor_description = "UI-31" +script = ExtResource("1_y2djw") +_version_label = NodePath("VersionLabel") +_commit_label = NodePath("CommitLabel") +_checksum_label = NodePath("ChecksumLabel") + +[node name="VersionLabel" type="Button" parent="."] +layout_mode = 2 +tooltip_text = "OpenVic2 v0.01 \"Primum Mobile\"" +theme_type_variation = &"VersionLabel" +text = "v0.01" +flat = true +alignment = 0 + +[node name="CommitLabel" type="Button" parent="."] +layout_mode = 2 +theme_type_variation = &"CommitLabel" +text = "ffffffff" +flat = true +alignment = 0 + +[node name="ChecksumLabel" type="Button" parent="."] +editor_description = "UI-111" +layout_mode = 2 +tooltip_text = "Checksum 00000000" +theme_type_variation = &"ChecksumLabel" +text = "(0000)" +flat = true +alignment = 0 + +[connection signal="pressed" from="VersionLabel" to="." method="_on_version_label_pressed"] +[connection signal="pressed" from="CommitLabel" to="." method="_on_commit_label_pressed"] +[connection signal="pressed" from="ChecksumLabel" to="." method="_on_checksum_label_pressed"] diff --git a/game/src/Utility/GIT_INFO.gd b/game/src/Utility/GIT_INFO.gd new file mode 100644 index 0000000..dc02349 --- /dev/null +++ b/game/src/Utility/GIT_INFO.gd @@ -0,0 +1,9 @@ +### IMPORTANT: IF LOCATION IS CHANGED, PLEASE UPDATE IN addon/openvic2-plugin/ReleaseExportEditorPlugin +class_name _GIT_INFO_ +extends RefCounted + + +const commit_hash : StringName = &"0000000000000000000000000000000000000000" +const short_hash : StringName = &"0000000" +const tag : StringName = &"<tag missing>" +const release_name : StringName = &"<release name missing>" diff --git a/game/theme/main_menu.tres b/game/theme/main_menu.tres index 9093252..24c5552 100644 --- a/game/theme/main_menu.tres +++ b/game/theme/main_menu.tres @@ -1,4 +1,4 @@ -[gd_resource type="Theme" load_steps=17 format=3 uid="uid://qoi3oec48jp0"] +[gd_resource type="Theme" load_steps=32 format=3 uid="uid://qoi3oec48jp0"] [ext_resource type="Script" path="res://src/Utility/StyleBoxCombinedTexture.gd" id="1_axke7"] [ext_resource type="Script" path="res://src/Utility/TextureSetting.gd" id="2_7bwl2"] @@ -61,6 +61,26 @@ content_margin_bottom = -1.0 script = ExtResource("1_axke7") texture_settings = Array[ExtResource("2_7bwl2")]([SubResource("Resource_hxpog"), SubResource("Resource_c0k5l")]) +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_8sqd6"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_xf6qr"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_1w6b1"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_7j42t"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_3fk2j"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_3jrfj"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_1qwxu"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_myxhv"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_kmfi1"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_1qcrh"] + [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_dd2b8"] content_margin_left = 20.0 content_margin_top = 10.0 @@ -110,6 +130,16 @@ script = ExtResource("7_qo00e") style_box = SubResource("StyleBoxTexture_l2rw3") sound = ExtResource("8_etuft") +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_xdtca"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_o5r8v"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_aan0b"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_4j6j5"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_spejd"] + [resource] BackgroundPanel/base_type = &"PanelContainer" BackgroundPanel/styles/panel = SubResource("StyleBox_odacv") @@ -117,8 +147,28 @@ BottomMargin/base_type = &"MarginContainer" BottomMargin/constants/margin_bottom = 10 BottomMargin/constants/margin_left = 50 BottomMargin/constants/margin_right = 50 -ChecksumLabel/base_type = &"Label" +ChecksumLabel/base_type = &"Button" ChecksumLabel/colors/font_color = Color(0.247059, 0.392157, 1, 1) +ChecksumLabel/colors/font_hover_pressed_color = Color(0.247059, 0.392157, 1, 1) +ChecksumLabel/colors/font_pressed_color = Color(0.247059, 0.392157, 1, 1) +ChecksumLabel/constants/h_separation = 0 +ChecksumLabel/constants/outline_size = 0 +ChecksumLabel/styles/disabled = SubResource("StyleBoxEmpty_8sqd6") +ChecksumLabel/styles/focus = SubResource("StyleBoxEmpty_xf6qr") +ChecksumLabel/styles/hover = SubResource("StyleBoxEmpty_1w6b1") +ChecksumLabel/styles/normal = SubResource("StyleBoxEmpty_7j42t") +ChecksumLabel/styles/pressed = SubResource("StyleBoxEmpty_3fk2j") +CommitLabel/base_type = &"Button" +CommitLabel/colors/font_hover_color = Color(0.360784, 0.360784, 0.360784, 1) +CommitLabel/colors/font_hover_pressed_color = Color(0.215686, 0.215686, 0.215686, 1) +CommitLabel/colors/font_pressed_color = Color(0.215686, 0.215686, 0.215686, 1) +CommitLabel/constants/h_separation = 0 +CommitLabel/constants/outline_size = 0 +CommitLabel/styles/disabled = SubResource("StyleBoxEmpty_3jrfj") +CommitLabel/styles/focus = SubResource("StyleBoxEmpty_1qwxu") +CommitLabel/styles/hover = SubResource("StyleBoxEmpty_myxhv") +CommitLabel/styles/normal = SubResource("StyleBoxEmpty_kmfi1") +CommitLabel/styles/pressed = SubResource("StyleBoxEmpty_1qcrh") TitleButton/base_type = &"Button" TitleButton/colors/font_color = Color(0.87451, 0.87451, 0.87451, 1) TitleButton/colors/font_disabled_color = Color(0.875, 0.875, 0.875, 0.5) @@ -141,3 +191,14 @@ TitleButton/styles/normal = ExtResource("6_dx0aj") TitleButton/styles/pressed = SubResource("StyleBox_uuspe") TitleLabel/base_type = &"Label" TitleLabel/font_sizes/font_size = 90 +VersionLabel/base_type = &"Button" +VersionLabel/colors/font_hover_color = Color(0.360784, 0.360784, 0.360784, 1) +VersionLabel/colors/font_hover_pressed_color = Color(0.215686, 0.215686, 0.215686, 1) +VersionLabel/colors/font_pressed_color = Color(0.215686, 0.215686, 0.215686, 1) +VersionLabel/constants/h_separation = 0 +VersionLabel/constants/outline_size = 0 +VersionLabel/styles/disabled = SubResource("StyleBoxEmpty_xdtca") +VersionLabel/styles/focus = SubResource("StyleBoxEmpty_o5r8v") +VersionLabel/styles/hover = SubResource("StyleBoxEmpty_aan0b") +VersionLabel/styles/normal = SubResource("StyleBoxEmpty_4j6j5") +VersionLabel/styles/pressed = SubResource("StyleBoxEmpty_spejd") |