Skip to content

Commit 1b6d64b

Browse files
committed
Don't recreate resources when editing plugin scenes
Previously, opening and saving parameter_block.tscn (for example) in the editor would cause its StyleBoxFlat resource to be replaced by an identical sub_resource with a new unique identifier. This is because its _ready() function runs when the scene is being edited, and previously would unconditionally re-set the stylebox. This either causes needless diff churn, or requires extra work by the developer to discard that hunk. In each case, guard the change with `node_is_part_of_edited_scene`, and remove it from the saved scene.
1 parent d248c34 commit 1b6d64b

File tree

6 files changed

+19
-45
lines changed

6 files changed

+19
-45
lines changed

addons/block_code/ui/block_canvas/block_canvas.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
class_name BlockCanvas
33
extends MarginContainer
44

5+
const Util = preload("res://addons/block_code/ui/util.gd")
6+
57
const EXTEND_MARGIN: float = 800
68
const BLOCK_AUTO_PLACE_MARGIN: Vector2 = Vector2(25, 8)
79
const DEFAULT_WINDOW_MARGIN: Vector2 = Vector2(25, 25)
@@ -45,7 +47,7 @@ signal replace_block_code
4547

4648

4749
func _ready():
48-
if not _open_scene_button.icon:
50+
if not _open_scene_button.icon and not Util.node_is_part_of_edited_scene(self):
4951
_open_scene_button.icon = _open_scene_icon
5052
_populate_block_scenes_by_class()
5153

addons/block_code/ui/block_canvas/block_canvas.tscn

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
1-
[gd_scene load_steps=5 format=3 uid="uid://c6vumewgnfquy"]
1+
[gd_scene load_steps=3 format=3 uid="uid://c6vumewgnfquy"]
22

33
[ext_resource type="Script" path="res://addons/block_code/ui/block_canvas/block_canvas.gd" id="1_tk8h2"]
44
[ext_resource type="Texture2D" uid="uid://cmusxj1ppspnp" path="res://addons/block_code/block_code_node/block_code_node.svg" id="2_710vn"]
55

6-
[sub_resource type="Image" id="Image_1nubg"]
7-
data = {
8-
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
9-
"format": "RGBA8",
10-
"height": 16,
11-
"mipmaps": false,
12-
"width": 16
13-
}
14-
15-
[sub_resource type="ImageTexture" id="ImageTexture_jgo72"]
16-
image = SubResource("Image_1nubg")
17-
186
[node name="BlockCanvas" type="MarginContainer"]
197
anchors_preset = 15
208
anchor_right = 1.0
@@ -142,7 +130,6 @@ layout_mode = 2
142130
size_flags_horizontal = 4
143131
theme_type_variation = &"InspectorActionButton"
144132
text = "Open in Editor"
145-
icon = SubResource("ImageTexture_jgo72")
146133

147134
[node name="ReplaceBlockCodeButton" type="Button" parent="SelectedNodeWithBlockCodeBox/ButtonsBox"]
148135
unique_name_in_owner = true

addons/block_code/ui/blocks/parameter_block/parameter_block.gd

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
class_name ParameterBlock
33
extends Block
44

5+
const Util = preload("res://addons/block_code/ui/util.gd")
6+
57
@export var block_format: String = ""
68
@export var statement: String = ""
79
@export var variant_type: Variant.Type
@@ -19,10 +21,11 @@ func _ready():
1921
super()
2022

2123
block_type = Types.BlockType.VALUE
22-
var new_panel = _panel.get_theme_stylebox("panel").duplicate()
23-
new_panel.bg_color = color
24-
new_panel.border_color = color.darkened(0.2)
25-
_panel.add_theme_stylebox_override("panel", new_panel)
24+
if not Util.node_is_part_of_edited_scene(self):
25+
var new_panel = _panel.get_theme_stylebox("panel").duplicate()
26+
new_panel.bg_color = color
27+
new_panel.border_color = color.darkened(0.2)
28+
_panel.add_theme_stylebox_override("panel", new_panel)
2629

2730
format()
2831

addons/block_code/ui/blocks/parameter_block/parameter_block.tscn

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
[gd_scene load_steps=4 format=3 uid="uid://clipm2dd28jde"]
1+
[gd_scene load_steps=3 format=3 uid="uid://clipm2dd28jde"]
22

33
[ext_resource type="Script" path="res://addons/block_code/ui/blocks/parameter_block/parameter_block.gd" id="1_0hajy"]
44
[ext_resource type="PackedScene" uid="uid://c7puyxpqcq6xo" path="res://addons/block_code/ui/blocks/utilities/drag_drop_area/drag_drop_area.tscn" id="2_gy5co"]
55

6-
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dbera"]
7-
bg_color = Color(1, 1, 1, 1)
8-
border_width_left = 3
9-
border_width_top = 3
10-
border_width_right = 3
11-
border_width_bottom = 3
12-
corner_radius_top_left = 16
13-
corner_radius_top_right = 16
14-
corner_radius_bottom_right = 16
15-
corner_radius_bottom_left = 16
16-
176
[node name="ParameterBlock" type="MarginContainer"]
187
offset_right = 16.0
198
offset_bottom = 8.0
@@ -27,7 +16,6 @@ block_type = 3
2716
[node name="Panel" type="Panel" parent="."]
2817
unique_name_in_owner = true
2918
layout_mode = 2
30-
theme_override_styles/panel = SubResource("StyleBoxFlat_dbera")
3119

3220
[node name="DragDropArea" parent="." instance=ExtResource("2_gy5co")]
3321
layout_mode = 2

addons/block_code/ui/picker/categories/block_category_button.gd

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
class_name BlockCategoryButton
33
extends MarginContainer
44

5+
const Util = preload("res://addons/block_code/ui/util.gd")
6+
57
signal selected
68

79
var category: BlockCategory
@@ -14,10 +16,10 @@ func _ready():
1416
if not category:
1517
category = BlockCategory.new("Example", Color.RED)
1618

17-
var new_stylebox: StyleBoxFlat = _panel.get_theme_stylebox("panel").duplicate()
18-
new_stylebox.bg_color = category.color
19-
20-
_panel.add_theme_stylebox_override("panel", new_stylebox)
19+
if not Util.node_is_part_of_edited_scene(self):
20+
var new_stylebox: StyleBoxFlat = _panel.get_theme_stylebox("panel").duplicate()
21+
new_stylebox.bg_color = category.color
22+
_panel.add_theme_stylebox_override("panel", new_stylebox)
2123

2224
_label.text = category.name
2325

addons/block_code/ui/picker/categories/block_category_button.tscn

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
[gd_scene load_steps=7 format=3 uid="uid://bdtetj0gs45hv"]
1+
[gd_scene load_steps=6 format=3 uid="uid://bdtetj0gs45hv"]
22

33
[ext_resource type="Script" path="res://addons/block_code/ui/picker/categories/block_category_button.gd" id="1_pxxnl"]
44

5-
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_eogpc"]
6-
bg_color = Color(1, 0, 0, 1)
7-
corner_radius_top_left = 100
8-
corner_radius_top_right = 100
9-
corner_radius_bottom_right = 100
10-
corner_radius_bottom_left = 100
11-
125
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ousiv"]
136

147
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_fyk0j"]
@@ -39,7 +32,6 @@ theme_override_constants/margin_bottom = 8
3932
[node name="Panel" type="Panel" parent="HBoxContainer/MarginContainer"]
4033
unique_name_in_owner = true
4134
layout_mode = 2
42-
theme_override_styles/panel = SubResource("StyleBoxFlat_eogpc")
4335

4436
[node name="Label" type="Label" parent="HBoxContainer"]
4537
unique_name_in_owner = true

0 commit comments

Comments
 (0)