From d2495b0418c6ff82e4fd47753251d88de10a389a Mon Sep 17 00:00:00 2001 From: Dylan McCall Date: Wed, 31 Jul 2024 09:56:15 -0700 Subject: [PATCH] Use class instantiators for block background scripts https://phabricator.endlessm.com/T35538 --- addons/block_code/drag_manager/drag.gd | 4 ++-- .../ui/blocks/control_block/control_block.gd | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/addons/block_code/drag_manager/drag.gd b/addons/block_code/drag_manager/drag.gd index 2043b07e..8a667755 100644 --- a/addons/block_code/drag_manager/drag.gd +++ b/addons/block_code/drag_manager/drag.gd @@ -1,6 +1,7 @@ @tool extends Control +const Background = preload("res://addons/block_code/ui/blocks/utilities/background/background.gd") const BlockCanvas = preload("res://addons/block_code/ui/block_canvas/block_canvas.gd") const Constants = preload("res://addons/block_code/ui/constants.gd") const InstructionTree = preload("res://addons/block_code/instruction_tree/instruction_tree.gd") @@ -189,8 +190,7 @@ func _update_preview(): if target_snap_point: # Make preview block - _preview_block = Control.new() - _preview_block.set_script(preload("res://addons/block_code/ui/blocks/utilities/background/background.gd")) + _preview_block = Background.new() _preview_block.color = Color(1, 1, 1, 0.5) _preview_block.custom_minimum_size = _block.get_global_rect().size diff --git a/addons/block_code/ui/blocks/control_block/control_block.gd b/addons/block_code/ui/blocks/control_block/control_block.gd index 9083b7af..7d72e751 100644 --- a/addons/block_code/ui/blocks/control_block/control_block.gd +++ b/addons/block_code/ui/blocks/control_block/control_block.gd @@ -2,8 +2,10 @@ class_name ControlBlock extends Block +const Background = preload("res://addons/block_code/ui/blocks/utilities/background/background.gd") const Constants = preload("res://addons/block_code/ui/constants.gd") const DragDropArea = preload("res://addons/block_code/ui/blocks/utilities/drag_drop_area/drag_drop_area.gd") +const Gutter = preload("res://addons/block_code/ui/blocks/utilities/background/gutter.gd") @export var block_formats: Array = [] @export var statements: Array = [] @@ -104,9 +106,8 @@ func format(): row.custom_minimum_size.y = 30 row.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN - var bg := Control.new() + var bg := Background.new() bg.name = "Background" - bg.set_script(preload("res://addons/block_code/ui/blocks/utilities/background/background.gd")) bg.color = color if i != 0: bg.shift_top = Constants.CONTROL_MARGIN @@ -144,9 +145,8 @@ func format(): snap_container.custom_minimum_size.y = 30 snap_container.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN - var snap_gutter := Control.new() + var snap_gutter := Gutter.new() snap_gutter.name = "Background" - snap_gutter.set_script(preload("res://addons/block_code/ui/blocks/utilities/background/gutter.gd")) snap_gutter.custom_minimum_size.x = Constants.CONTROL_MARGIN snap_gutter.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN snap_gutter.size_flags_vertical = Control.SIZE_EXPAND_FILL @@ -161,11 +161,10 @@ func format(): %Rows.add_child(snap_container) - var bg := Control.new() + var bg := Background.new() bg.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN bg.custom_minimum_size.x = 100 bg.custom_minimum_size.y = 30 - bg.set_script(preload("res://addons/block_code/ui/blocks/utilities/background/background.gd")) bg.color = color bg.shift_top = Constants.CONTROL_MARGIN %Rows.add_child(bg)