Skip to content

Commit

Permalink
Use class instantiators for block background scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanmccall committed Jul 31, 2024
1 parent c92f254 commit d2495b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions addons/block_code/drag_manager/drag.gd
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions addons/block_code/ui/blocks/control_block/control_block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)

0 comments on commit d2495b0

Please sign in to comment.