Skip to content

Commit a07e93b

Browse files
authored
Merge pull request #373 from Maaack/release-notes-reader
Release notes reader
2 parents 18e8aae + 47b182c commit a07e93b

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
@tool
2+
extends RichTextLabel
3+
4+
const HEADING_STRING_REPLACEMENT = "$1[font_size=%d]$2[/font_size]"
5+
const BOLD_HEADING_STRING_REPLACEMENT = "$1[b][font_size=%d]$2[/font_size][/b]"
6+
7+
@export_group("Font Sizes")
8+
@export var h1_font_size: int
9+
@export var h2_font_size: int
10+
@export var h3_font_size: int
11+
@export var h4_font_size: int
12+
@export var h5_font_size: int
13+
@export var h6_font_size: int
14+
@export var bold_headings : bool
15+
@export_group("Extra Options")
16+
@export var disable_images : bool = false
17+
@export var disable_urls : bool = false
18+
@export var disable_bolds : bool = false
19+
20+
func regex_replace_imgs(markdown_text:String) -> String:
21+
var regex = RegEx.new()
22+
var match_string := "<img .* src=\"(.*)\" \\/>"
23+
var replace_string := ""
24+
if not disable_images:
25+
replace_string = "$1"
26+
regex.compile(match_string)
27+
return regex.sub(markdown_text, replace_string, true)
28+
29+
func regex_replace_urls(markdown_text:String) -> String:
30+
var regex = RegEx.new()
31+
var match_string := "(https:\\/\\/.*)($|\\s)"
32+
var replace_string := "$1"
33+
if not disable_urls:
34+
replace_string = "[url=$1]$1[/url]"
35+
regex.compile(match_string)
36+
return regex.sub(markdown_text, replace_string, true)
37+
38+
func regex_replace_bolds(markdown_text:String) -> String:
39+
var regex = RegEx.new()
40+
var match_string := "\\*\\*(.*)\\*\\*"
41+
var replace_string := "$1"
42+
if not disable_bolds:
43+
replace_string = "[b]$1[/b]"
44+
regex.compile(match_string)
45+
return regex.sub(markdown_text, replace_string, true)
46+
47+
func regex_replace_titles(markdown_text:String) -> String:
48+
var iter = 0
49+
var heading_font_sizes : Array[int] = [
50+
h1_font_size,
51+
h2_font_size,
52+
h3_font_size,
53+
h4_font_size,
54+
h5_font_size,
55+
h6_font_size]
56+
for heading_font_size in heading_font_sizes:
57+
iter += 1
58+
var regex = RegEx.new()
59+
var match_string : String = "([^#]|^)#{%d}\\s([^\n]*)" % iter
60+
var replace_string := HEADING_STRING_REPLACEMENT % [heading_font_size]
61+
if bold_headings:
62+
replace_string = BOLD_HEADING_STRING_REPLACEMENT % [heading_font_size]
63+
regex.compile(match_string)
64+
markdown_text = regex.sub(markdown_text, replace_string, true)
65+
return markdown_text
66+
67+
func from_release_notes(markdown_text : String) -> void:
68+
markdown_text = regex_replace_imgs(markdown_text)
69+
markdown_text = regex_replace_urls(markdown_text)
70+
markdown_text = regex_replace_bolds(markdown_text)
71+
markdown_text = regex_replace_titles(markdown_text)
72+
text = markdown_text
73+
74+
func _on_meta_clicked(meta: String) -> void:
75+
if meta.begins_with("https://"):
76+
var _err = OS.shell_open(meta)
77+
78+
func _ready() -> void:
79+
meta_clicked.connect(_on_meta_clicked)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://dab5i53lgv34a

addons/maaacks_game_template/installer/update_plugin.gd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ signal update_completed
55

66
const DownloadAndExtract = MaaacksGameTemplatePlugin.DownloadAndExtract
77
const APIClient = MaaacksGameTemplatePlugin.APIClient
8+
const ReleaseNotesLabel = preload("./release_notes_label.gd")
89

910
const API_RELEASES_URL := "https://api.github.com/repos/%s/%s/releases"
1011
const UPDATE_CONFIRMATION_MESSAGE := "This will update the contents of the plugin folder (addons/%s/).\nFiles outside of the plugin folder will not be affected.\n\nUpdate %s to v%s?"
@@ -31,7 +32,7 @@ const PLUGIN_TEMP_ZIP_PATH := "res://%s_%s_update.zip"
3132
@onready var _installing_dialog : AcceptDialog = $InstallingDialog
3233
@onready var _error_dialog : AcceptDialog = $ErrorDialog
3334
@onready var _success_dialog : AcceptDialog = $SuccessDialog
34-
@onready var _release_label : RichTextLabel = %ReleaseLabel
35+
@onready var _release_notes_label : ReleaseNotesLabel = %ReleaseNotesLabel
3536
@onready var _update_label : Label = %UpdateLabel
3637
@onready var _warning_message_button : LinkButton = %WarningMessageButton
3738
@onready var _warning_message_label : Label = %WarningMessageLabel
@@ -94,7 +95,7 @@ func _on_api_client_response_received(response_body : Variant) -> void:
9495
_download_and_extract_node.zip_file_path = PLUGIN_TEMP_ZIP_PATH % [plugin_directory, _newest_version]
9596
_update_label.text = UPDATE_CONFIRMATION_MESSAGE % [plugin_directory, _plugin_name, _newest_version]
9697
if latest_release.has("body"):
97-
_release_label.text = latest_release["body"]
98+
_release_notes_label.from_release_notes(latest_release["body"])
9899
_update_confirmation_dialog.show()
99100

100101
func _on_download_and_extract_zip_saved() -> void:

addons/maaacks_game_template/installer/update_plugin.tscn

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
[gd_scene load_steps=4 format=3 uid="uid://gynblau0ojia"]
1+
[gd_scene load_steps=5 format=3 uid="uid://gynblau0ojia"]
22

33
[ext_resource type="Script" uid="uid://cwj8dpqveao6o" path="res://addons/maaacks_game_template/installer/update_plugin.gd" id="1_s6qpc"]
44
[ext_resource type="PackedScene" uid="uid://drhhakm62vjsy" path="res://addons/maaacks_game_template/utilities/api_client.tscn" id="2_s6pdq"]
55
[ext_resource type="PackedScene" uid="uid://dlkmofxhavh10" path="res://addons/maaacks_game_template/utilities/download_and_extract.tscn" id="3_s6pdq"]
6+
[ext_resource type="Script" uid="uid://dab5i53lgv34a" path="res://addons/maaacks_game_template/installer/release_notes_label.gd" id="4_1amwf"]
67

78
[node name="UpdatePlugin" type="Node"]
89
script = ExtResource("1_s6qpc")
@@ -76,7 +77,7 @@ custom_minimum_size = Vector2(0, 420)
7677
layout_mode = 2
7778
size_flags_vertical = 3
7879

79-
[node name="ReleaseLabel" type="RichTextLabel" parent="UpdateConfirmationDialog/MarginContainer/VBoxContainer/ReleaseNotesPanel"]
80+
[node name="ReleaseNotesLabel" type="RichTextLabel" parent="UpdateConfirmationDialog/MarginContainer/VBoxContainer/ReleaseNotesPanel"]
8081
unique_name_in_owner = true
8182
layout_mode = 1
8283
anchors_preset = 15
@@ -85,6 +86,17 @@ anchor_bottom = 1.0
8586
grow_horizontal = 2
8687
grow_vertical = 2
8788
size_flags_vertical = 3
89+
focus_mode = 2
90+
bbcode_enabled = true
91+
selection_enabled = true
92+
script = ExtResource("4_1amwf")
93+
h1_font_size = 64
94+
h2_font_size = 48
95+
h3_font_size = 32
96+
h4_font_size = 24
97+
h5_font_size = 16
98+
h6_font_size = 12
99+
bold_headings = true
88100

89101
[node name="InstallingDialog" type="AcceptDialog" parent="."]
90102
auto_translate_mode = 1

0 commit comments

Comments
 (0)