Skip to content

Commit a3b6ce2

Browse files
committed
Add block code demo scene
Helps: #196
1 parent 760a579 commit a3b6ce2

File tree

8 files changed

+110
-16
lines changed

8 files changed

+110
-16
lines changed

addons/block_code/ui/block_canvas/block_canvas.gd

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ func set_child(n: Node):
9494
func _on_context_changed():
9595
clear_canvas()
9696

97-
var edited_node = EditorInterface.get_inspector().get_edited_object() as Node
97+
var edited_node: Node
98+
99+
if Engine.is_editor_hint():
100+
edited_node = EditorInterface.get_inspector().get_edited_object() as Node
98101

99102
if _context.block_script != _current_block_script:
100103
_window.position = Vector2(0, 0)

addons/block_code/ui/block_canvas/block_canvas.tscn

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ layout_mode = 2
2222

2323
[node name="Window" type="Control" parent="WindowContainer"]
2424
unique_name_in_owner = true
25+
visible = false
2526
layout_mode = 2
2627
anchors_preset = 0
2728
offset_right = 1152.0
@@ -60,10 +61,12 @@ theme_override_constants/margin_bottom = 4
6061

6162
[node name="ZoomButton" type="Button" parent="WindowContainer/Overlay/MarginContainer"]
6263
unique_name_in_owner = true
64+
visible = false
6365
modulate = Color(1, 1, 1, 0.470588)
6466
layout_mode = 2
6567
focus_mode = 0
6668
theme_override_font_sizes/font_size = 24
69+
text = "1.0x"
6770

6871
[node name="MouseOverride" type="MarginContainer" parent="."]
6972
unique_name_in_owner = true
@@ -72,7 +75,6 @@ mouse_filter = 2
7275

7376
[node name="EmptyBox" type="VBoxContainer" parent="."]
7477
unique_name_in_owner = true
75-
visible = false
7678
layout_mode = 2
7779
size_flags_vertical = 4
7880

@@ -90,7 +92,7 @@ size_flags_vertical = 4
9092
[node name="Label" type="Label" parent="SelectedNodeBox"]
9193
custom_minimum_size = Vector2(200, 0)
9294
layout_mode = 2
93-
text = "Use block coding to create custom behavior and game mechanics for \"{node}\"."
95+
text = "Use block coding to create custom behavior and game mechanics for \"BlockCanvas\"."
9496
horizontal_alignment = 1
9597
autowrap_mode = 2
9698

@@ -103,6 +105,7 @@ unique_name_in_owner = true
103105
layout_mode = 2
104106
size_flags_horizontal = 4
105107
theme_type_variation = &"InspectorActionButton"
108+
disabled = true
106109
text = "Add Block Code"
107110
icon = ExtResource("2_710vn")
108111

@@ -128,13 +131,15 @@ unique_name_in_owner = true
128131
layout_mode = 2
129132
size_flags_horizontal = 4
130133
theme_type_variation = &"InspectorActionButton"
134+
disabled = true
131135
text = "Open in Editor"
132136

133137
[node name="ReplaceBlockCodeButton" type="Button" parent="SelectedNodeWithBlockCodeBox/ButtonsBox"]
134138
unique_name_in_owner = true
135139
layout_mode = 2
136140
size_flags_horizontal = 4
137141
theme_type_variation = &"InspectorActionButton"
142+
disabled = true
138143
text = "Override Block Code"
139144
icon = ExtResource("2_710vn")
140145

addons/block_code/ui/main_panel.gd

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ const VariableDefinition = preload("res://addons/block_code/code_generation/vari
1818
@onready var _drag_manager: DragManager = %DragManager
1919
@onready var _title_bar: TitleBar = %TitleBar
2020
@onready var _delete_node_button: Button = %DeleteNodeButton
21-
@onready var _editor_inspector: EditorInspector = EditorInterface.get_inspector()
2221
@onready var _picker_split: HSplitContainer = %PickerSplit
2322
@onready var _collapse_button: Button = %CollapseButton
2423

25-
@onready var _icon_delete := EditorInterface.get_editor_theme().get_icon("Remove", "EditorIcons")
26-
@onready var _icon_collapse := EditorInterface.get_editor_theme().get_icon("Back", "EditorIcons")
27-
@onready var _icon_expand := EditorInterface.get_editor_theme().get_icon("Forward", "EditorIcons")
24+
@onready var _icon_delete := EditorInterface.get_editor_theme().get_icon("Remove", "EditorIcons") if Engine.is_editor_hint() else null
25+
@onready var _icon_collapse := EditorInterface.get_editor_theme().get_icon("Back", "EditorIcons") if Engine.is_editor_hint() else null
26+
@onready var _icon_expand := EditorInterface.get_editor_theme().get_icon("Forward", "EditorIcons") if Engine.is_editor_hint() else null
2827

2928
const Constants = preload("res://addons/block_code/ui/constants.gd")
3029

@@ -66,7 +65,10 @@ func _on_show_script_button_pressed():
6665

6766

6867
func _on_delete_node_button_pressed():
69-
var scene_root = EditorInterface.get_edited_scene_root()
68+
var scene_root: Node
69+
70+
if Engine.is_editor_hint():
71+
scene_root = EditorInterface.get_edited_scene_root()
7072

7173
if not scene_root:
7274
return
@@ -130,6 +132,9 @@ func save_script():
130132
print("No script loaded to save.")
131133
return
132134

135+
if not Engine.is_editor_hint():
136+
return
137+
133138
var scene_node = EditorInterface.get_edited_scene_root()
134139

135140
if not BlockCodePlugin.is_block_code_editable(_context.block_code_node):

addons/block_code/ui/main_panel.tscn

+5-4
Large diffs are not rendered by default.

addons/block_code/ui/title_bar/title_bar.gd

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ signal node_name_changed(node_name: String)
88
@onready var _context := BlockEditorContext.get_default()
99

1010
@onready var _block_code_icon = load("res://addons/block_code/block_code_node/block_code_node.svg") as Texture2D
11-
@onready var _editor_inspector: EditorInspector = EditorInterface.get_inspector()
12-
@onready var _editor_selection: EditorSelection = EditorInterface.get_selection()
1311
@onready var _node_option_button: OptionButton = %NodeOptionButton
1412

1513

@@ -34,7 +32,7 @@ func _on_context_changed():
3432
func _update_node_option_button_items():
3533
_node_option_button.clear()
3634

37-
var scene_root = EditorInterface.get_edited_scene_root()
35+
var scene_root = EditorInterface.get_edited_scene_root() if Engine.is_editor_hint() else null
3836

3937
if not scene_root:
4038
return
@@ -61,6 +59,7 @@ func _get_block_script_index(block_script: BlockScriptSerialization) -> int:
6159

6260

6361
func _on_node_option_button_item_selected(index):
62+
var _editor_selection := EditorInterface.get_selection()
6463
var block_code_node = _node_option_button.get_item_metadata(index) as BlockCode
6564
var parent_node = block_code_node.get_parent() as Node
6665
_editor_selection.clear()

block_code_demo.gd

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extends Control
2+
3+
@onready var _context := BlockEditorContext.get_default()
4+
5+
@onready var _block_code := %BlockCode
6+
7+
8+
func _ready() -> void:
9+
#var block_script: BlockScriptSerialization =
10+
#block_script.script_inherits = _get_custom_or_native_class(get_parent())
11+
#block_script.generated_script = new_block_script.generated_script.replace("INHERIT_DEFAULT", new_block_script.script_inherits)
12+
13+
_context.set_block_code_node.call_deferred(_block_code)

block_code_demo.tscn

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[gd_scene load_steps=12 format=3 uid="uid://d2sgdkbau3tfv"]
2+
3+
[ext_resource type="PackedScene" uid="uid://bq37yla8ya707" path="res://addons/block_code/ui/main_panel.tscn" id="1_kvne0"]
4+
[ext_resource type="Script" path="res://block_code_demo.gd" id="1_obq7i"]
5+
[ext_resource type="Texture2D" uid="uid://dr8e0tvfxjy1f" path="res://icon.svg" id="2_liip2"]
6+
[ext_resource type="Script" path="res://addons/block_code/block_code_node/block_code.gd" id="2_x7fcc"]
7+
[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialization_tree.gd" id="3_73e6f"]
8+
[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialization.gd" id="4_1yrvj"]
9+
[ext_resource type="Script" path="res://addons/block_code/serialization/block_script_serialization.gd" id="5_bnd5w"]
10+
[ext_resource type="Script" path="res://addons/block_code/code_generation/variable_definition.gd" id="6_h8s2d"]
11+
12+
[sub_resource type="Resource" id="Resource_oalom"]
13+
script = ExtResource("4_1yrvj")
14+
name = &"ready"
15+
children = Array[ExtResource("4_1yrvj")]([])
16+
arguments = {}
17+
18+
[sub_resource type="Resource" id="Resource_8sqy5"]
19+
script = ExtResource("3_73e6f")
20+
root = SubResource("Resource_oalom")
21+
canvas_position = Vector2(54, 47)
22+
23+
[sub_resource type="Resource" id="Resource_ho2y6"]
24+
script = ExtResource("5_bnd5w")
25+
script_inherits = "Sprite2D"
26+
block_serialization_trees = Array[ExtResource("3_73e6f")]([SubResource("Resource_8sqy5")])
27+
variables = Array[ExtResource("6_h8s2d")]([])
28+
generated_script = "extends Sprite2D"
29+
version = 0
30+
31+
[node name="BlockCodeDemo" type="Control"]
32+
layout_mode = 3
33+
anchors_preset = 15
34+
anchor_right = 1.0
35+
anchor_bottom = 1.0
36+
grow_horizontal = 2
37+
grow_vertical = 2
38+
script = ExtResource("1_obq7i")
39+
40+
[node name="VSplitContainer" type="VSplitContainer" parent="."]
41+
layout_mode = 1
42+
anchors_preset = 15
43+
anchor_right = 1.0
44+
anchor_bottom = 1.0
45+
grow_horizontal = 2
46+
grow_vertical = 2
47+
48+
[node name="SubViewportContainer" type="SubViewportContainer" parent="VSplitContainer"]
49+
layout_mode = 2
50+
size_flags_vertical = 3
51+
stretch = true
52+
53+
[node name="SubViewport" type="SubViewport" parent="VSplitContainer/SubViewportContainer"]
54+
handle_input_locally = false
55+
size = Vector2i(1152, 318)
56+
render_target_update_mode = 4
57+
58+
[node name="Sprite2D" type="Sprite2D" parent="VSplitContainer/SubViewportContainer/SubViewport"]
59+
position = Vector2(537, 188)
60+
texture = ExtResource("2_liip2")
61+
62+
[node name="BlockCode" type="Node" parent="VSplitContainer/SubViewportContainer/SubViewport/Sprite2D"]
63+
unique_name_in_owner = true
64+
script = ExtResource("2_x7fcc")
65+
block_script = SubResource("Resource_ho2y6")
66+
67+
[node name="MainPanel" parent="VSplitContainer" instance=ExtResource("1_kvne0")]
68+
layout_mode = 2

project.godot

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config_version=5
1111
[application]
1212

1313
config/name="Block Coding Plugin"
14-
run/main_scene="res://addons/block_code/examples/pong_game/pong_game.tscn"
14+
run/main_scene="res://block_code_demo.tscn"
1515
config/features=PackedStringArray("4.3", "GL Compatibility")
1616
config/icon="res://icon.svg"
1717

0 commit comments

Comments
 (0)