Skip to content

Commit 99e3d11

Browse files
committed
BlockCanvas: Allow running outside the editor
EditorInterface does not exist when blocks run outside the editor. Use custom icons for the zoom in and out buttons instead of doing a lookup for the editor icons. Also let the edited node be null.
1 parent af6cdd8 commit 99e3d11

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

addons/block_code/ui/block_canvas/block_canvas.gd

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const Types = preload("res://addons/block_code/types/types.gd")
1313
const Util = preload("res://addons/block_code/ui/util.gd")
1414
const VariableDefinition = preload("res://addons/block_code/code_generation/variable_definition.gd")
1515

16+
const ZOOM_IN_ICON_TEXTURE = preload("res://addons/block_code/ui/block_canvas/zoom_in_icon_texture.tres")
17+
const ZOOM_OUT_ICON_TEXTURE = preload("res://addons/block_code/ui/block_canvas/zoom_out_icon_texture.tres")
18+
1619
const EXTEND_MARGIN: float = 800
1720
const BLOCK_AUTO_PLACE_MARGIN: Vector2 = Vector2(25, 8)
1821
const DEFAULT_WINDOW_MARGIN: Vector2 = Vector2(25, 25)
@@ -37,8 +40,8 @@ const ZOOM_FACTOR: float = 1.1
3740
@onready var _replace_block_code_button: Button = %ReplaceBlockCodeButton
3841

3942
@onready var _open_scene_icon = _open_scene_button.get_theme_icon("Load", "EditorIcons")
40-
@onready var _icon_zoom_out := EditorInterface.get_editor_theme().get_icon("ZoomLess", "EditorIcons")
41-
@onready var _icon_zoom_in := EditorInterface.get_editor_theme().get_icon("ZoomMore", "EditorIcons")
43+
@onready var _icon_zoom_out := EditorInterface.get_editor_theme().get_icon("ZoomLess", "EditorIcons") if EditorInterface.has_method("get_editor_theme") else ZOOM_OUT_ICON_TEXTURE
44+
@onready var _icon_zoom_in := EditorInterface.get_editor_theme().get_icon("ZoomMore", "EditorIcons") if EditorInterface.has_method("get_editor_theme") else ZOOM_IN_ICON_TEXTURE
4245

4346
@onready var _mouse_override: Control = %MouseOverride
4447
@onready var _zoom_buttons: HBoxContainer = %ZoomButtons
@@ -211,7 +214,9 @@ func set_child(n: Node):
211214
func _on_context_changed():
212215
clear_canvas()
213216

214-
var edited_node = EditorInterface.get_inspector().get_edited_object() as Node
217+
var edited_node
218+
if EditorInterface.has_method("get_inspector"):
219+
edited_node = EditorInterface.get_inspector().get_edited_object() as Node
215220

216221
if _context.block_script != _current_block_script:
217222
_window.position = Vector2(0, 0)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[gd_resource type="ImageTexture" load_steps=2 format=3 uid="uid://braer205nctqj"]
2+
3+
[sub_resource type="Image" id="Image_47mxg"]
4+
data = {
5+
"data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 58, 0, 0, 0, 86, 0, 0, 0, 97, 0, 0, 0, 97, 0, 0, 0, 85, 0, 0, 0, 58, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 60, 47, 47, 47, 114, 160, 160, 160, 177, 205, 205, 205, 225, 218, 218, 218, 246, 218, 218, 218, 246, 205, 205, 205, 225, 158, 158, 158, 176, 44, 44, 44, 114, 0, 0, 0, 59, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 76, 119, 119, 119, 150, 218, 218, 218, 246, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 219, 219, 219, 245, 117, 117, 117, 148, 0, 0, 0, 76, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 119, 119, 119, 148, 224, 224, 224, 254, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 254, 114, 114, 114, 147, 0, 0, 0, 59, 0, 0, 0, 0, 0, 0, 0, 18, 44, 44, 44, 114, 219, 219, 219, 245, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 0, 0, 0, 102, 0, 0, 0, 102, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 218, 218, 218, 245, 40, 40, 40, 113, 0, 0, 0, 17, 0, 0, 0, 58, 158, 158, 158, 176, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 0, 0, 0, 102, 0, 0, 0, 102, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 155, 155, 155, 173, 0, 0, 0, 57, 0, 0, 0, 86, 206, 206, 206, 226, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 0, 0, 0, 102, 0, 0, 0, 102, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 203, 203, 203, 223, 0, 0, 0, 85, 0, 0, 0, 97, 219, 219, 219, 247, 224, 224, 224, 255, 224, 224, 224, 255, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 224, 224, 224, 255, 224, 224, 224, 255, 218, 218, 218, 244, 0, 0, 0, 97, 0, 0, 0, 97, 219, 219, 219, 247, 224, 224, 224, 255, 224, 224, 224, 255, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 224, 224, 224, 255, 224, 224, 224, 255, 218, 218, 218, 244, 0, 0, 0, 97, 0, 0, 0, 85, 206, 206, 206, 226, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 0, 0, 0, 102, 0, 0, 0, 102, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 201, 201, 201, 222, 0, 0, 0, 84, 0, 0, 0, 58, 157, 157, 157, 175, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 0, 0, 0, 102, 0, 0, 0, 102, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 152, 152, 152, 171, 0, 0, 0, 56, 0, 0, 0, 17, 44, 44, 44, 114, 218, 218, 218, 245, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 0, 0, 0, 102, 0, 0, 0, 102, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 217, 217, 217, 243, 36, 36, 36, 111, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 59, 116, 116, 116, 147, 224, 224, 224, 254, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 223, 223, 223, 254, 110, 110, 110, 144, 0, 0, 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 76, 117, 117, 117, 148, 219, 219, 219, 245, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 218, 218, 218, 243, 112, 112, 112, 144, 0, 0, 0, 74, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 59, 43, 43, 43, 113, 156, 156, 156, 175, 203, 203, 203, 224, 218, 218, 218, 245, 218, 218, 218, 245, 203, 203, 203, 223, 155, 155, 155, 173, 40, 40, 40, 113, 0, 0, 0, 58, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 57, 0, 0, 0, 85, 0, 0, 0, 97, 0, 0, 0, 97, 0, 0, 0, 84, 0, 0, 0, 56, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
6+
"format": "RGBA8",
7+
"height": 16,
8+
"mipmaps": false,
9+
"width": 16
10+
}
11+
12+
[resource]
13+
image = SubResource("Image_47mxg")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[gd_resource type="ImageTexture" load_steps=2 format=3 uid="uid://uejh0m7utv1t"]
2+
3+
[sub_resource type="Image" id="Image_cj7at"]
4+
data = {
5+
"data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 58, 0, 0, 0, 86, 0, 0, 0, 97, 0, 0, 0, 97, 0, 0, 0, 85, 0, 0, 0, 58, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 60, 47, 47, 47, 114, 160, 160, 160, 177, 205, 205, 205, 225, 218, 218, 218, 246, 218, 218, 218, 246, 205, 205, 205, 225, 158, 158, 158, 176, 44, 44, 44, 114, 0, 0, 0, 59, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 76, 119, 119, 119, 150, 218, 218, 218, 246, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 219, 219, 219, 245, 117, 117, 117, 148, 0, 0, 0, 76, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 119, 119, 119, 148, 224, 224, 224, 254, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 254, 114, 114, 114, 147, 0, 0, 0, 59, 0, 0, 0, 0, 0, 0, 0, 18, 44, 44, 44, 114, 219, 219, 219, 245, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 218, 218, 218, 245, 40, 40, 40, 113, 0, 0, 0, 17, 0, 0, 0, 58, 158, 158, 158, 176, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 155, 155, 155, 173, 0, 0, 0, 57, 0, 0, 0, 86, 206, 206, 206, 226, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 203, 203, 203, 223, 0, 0, 0, 85, 0, 0, 0, 97, 219, 219, 219, 247, 224, 224, 224, 255, 224, 224, 224, 255, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 224, 224, 224, 255, 224, 224, 224, 255, 218, 218, 218, 244, 0, 0, 0, 97, 0, 0, 0, 97, 219, 219, 219, 247, 224, 224, 224, 255, 224, 224, 224, 255, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 0, 0, 0, 102, 224, 224, 224, 255, 224, 224, 224, 255, 218, 218, 218, 244, 0, 0, 0, 97, 0, 0, 0, 85, 206, 206, 206, 226, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 201, 201, 201, 222, 0, 0, 0, 84, 0, 0, 0, 58, 157, 157, 157, 175, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 152, 152, 152, 171, 0, 0, 0, 56, 0, 0, 0, 17, 44, 44, 44, 114, 218, 218, 218, 245, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 217, 217, 217, 243, 36, 36, 36, 111, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 59, 116, 116, 116, 147, 224, 224, 224, 254, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 223, 223, 223, 254, 110, 110, 110, 144, 0, 0, 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 76, 117, 117, 117, 148, 219, 219, 219, 245, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 218, 218, 218, 243, 112, 112, 112, 144, 0, 0, 0, 74, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 59, 43, 43, 43, 113, 156, 156, 156, 175, 203, 203, 203, 224, 218, 218, 218, 245, 218, 218, 218, 245, 203, 203, 203, 223, 155, 155, 155, 173, 40, 40, 40, 113, 0, 0, 0, 58, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 57, 0, 0, 0, 85, 0, 0, 0, 97, 0, 0, 0, 97, 0, 0, 0, 84, 0, 0, 0, 56, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
6+
"format": "RGBA8",
7+
"height": 16,
8+
"mipmaps": false,
9+
"width": 16
10+
}
11+
12+
[resource]
13+
image = SubResource("Image_cj7at")

0 commit comments

Comments
 (0)