From 4b496071fccf9772be7401463d815377ceaaec8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Fri, 21 Jan 2022 14:18:13 +0100 Subject: [PATCH] Add version info to the game --- info.json | 7 +++++++ menu/main_menu.gd | 4 ++++ menu/main_menu.tscn | 34 ++++++++++++++++++++++++++-------- settings/global_settings.gd | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 info.json diff --git a/info.json b/info.json new file mode 100644 index 0000000..15537a5 --- /dev/null +++ b/info.json @@ -0,0 +1,7 @@ +{ + "version": { + "major": 0, + "minor": 2, + "patch": 0 + } +} diff --git a/menu/main_menu.gd b/menu/main_menu.gd index 6df43a8..59a3977 100644 --- a/menu/main_menu.gd +++ b/menu/main_menu.gd @@ -4,6 +4,10 @@ extends Panel func _ready() -> void: # gdlint: ignore=max-line-length $MarginContainer/VSplitContainer/VSplitContainer/CenterContainer/VBoxContainer/SingleplayerButton.grab_focus() + $MarginContainer/VSplitContainer/VBoxContainer/VersionLabel.text = ( + "Version: %s" + % GlobalSettings.get_version_string() + ) func _on_SingleplayerButton_pressed() -> void: diff --git a/menu/main_menu.tscn b/menu/main_menu.tscn index f97ca41..3a657f8 100644 --- a/menu/main_menu.tscn +++ b/menu/main_menu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://assets/fonts/kenney-future-narrow.ttf" type="DynamicFontData" id=1] [ext_resource path="res://menu/main_menu.gd" type="Script" id=2] @@ -12,6 +12,9 @@ size = 64 font_data = ExtResource( 1 ) +[sub_resource type="DynamicFont" id=3] +font_data = ExtResource( 1 ) + [sub_resource type="DynamicFont" id=2] size = 32 font_data = ExtResource( 1 ) @@ -41,7 +44,11 @@ margin_right = 984.0 margin_bottom = 560.0 dragger_visibility = 1 -[node name="Title" type="Label" parent="MarginContainer/VSplitContainer"] +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VSplitContainer"] +margin_right = 984.0 +margin_bottom = 98.0 + +[node name="Title" type="Label" parent="MarginContainer/VSplitContainer/VBoxContainer"] margin_right = 984.0 margin_bottom = 72.0 custom_colors/font_color = Color( 0.419608, 0.0117647, 0.0117647, 1 ) @@ -50,8 +57,19 @@ text = "Bugged Racing" align = 1 valign = 1 +[node name="VersionLabel" type="Label" parent="MarginContainer/VSplitContainer/VBoxContainer"] +margin_top = 80.0 +margin_right = 984.0 +margin_bottom = 98.0 +custom_fonts/font = SubResource( 3 ) +text = "Version:" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} + [node name="VSplitContainer" type="VSplitContainer" parent="MarginContainer/VSplitContainer"] -margin_top = 96.0 +margin_top = 122.0 margin_right = 984.0 margin_bottom = 560.0 split_offset = 973 @@ -59,16 +77,16 @@ dragger_visibility = 1 [node name="CenterContainer" type="CenterContainer" parent="MarginContainer/VSplitContainer/VSplitContainer"] margin_right = 984.0 -margin_bottom = 376.0 +margin_bottom = 350.0 __meta__ = { "_edit_use_anchors_": false } [node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VSplitContainer/VSplitContainer/CenterContainer"] margin_left = 348.0 -margin_top = 52.0 +margin_top = 39.0 margin_right = 636.0 -margin_bottom = 324.0 +margin_bottom = 311.0 [node name="SingleplayerButton" type="Button" parent="MarginContainer/VSplitContainer/VSplitContainer/CenterContainer/VBoxContainer"] margin_right = 288.0 @@ -103,9 +121,9 @@ margin_bottom = 272.0 text = "Exit" [node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VSplitContainer/VSplitContainer"] -margin_top = 400.0 +margin_top = 374.0 margin_right = 984.0 -margin_bottom = 464.0 +margin_bottom = 438.0 __meta__ = { "_edit_use_anchors_": false } diff --git a/settings/global_settings.gd b/settings/global_settings.gd index 9ee3136..cc80168 100644 --- a/settings/global_settings.gd +++ b/settings/global_settings.gd @@ -4,3 +4,35 @@ var auto_clutch: bool = false var automatic_transmission: bool = true var selected_camera: int = 0 var multiplayer_name: String = "Player" + +var _config: Dictionary + + +func _ready() -> void: + _config = read_json_file("res://info.json") + + +func read_json_file(file_path: String) -> Dictionary: + var file = File.new() + if not file.file_exists(file_path): + print("File not found: %s" % file_path) + return Dictionary() + file.open(file_path, File.READ) + var content_as_text = file.get_as_text() + var content_as_dictionary = parse_json(content_as_text) + return content_as_dictionary + + +func save_json_file(file_path: String, contents: Dictionary) -> void: + var file = File.new() + file.open(file_path, File.WRITE) + file.store_line(to_json(contents)) + file.close() + + +func get_version_string() -> String: + var version = _config["version"] + var major = version["major"] + var minor = version["minor"] + var patch = version["patch"] + return "%d.%d.%d" % [major, minor, patch]