changing chekc using metadata to use class info

This commit is contained in:
betalars 2023-07-18 23:25:56 +02:00
parent 71a22dccef
commit 4d51a21876
3 changed files with 33 additions and 37 deletions

View File

@ -174,8 +174,8 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
# TODO: We need a better way to recognize whether "to_handle" is a Card or a Post-It. # TODO: We need a better way to recognize whether "to_handle" is a Card or a Post-It.
# (Tried checking for a script, didn't work, because script has no name attached. # (Tried checking for a script, didn't work, because script has no name attached.
# Alternative might be to check for specific values within the script ("is_card" f.e)) # Alternative might be to check for specific values within the script ("is_card" f.e))
match to_handle.get_meta("type"): if to_handle is Card:
"card": # 1 = Card
active_context = ui_context.DROPZONE active_context = ui_context.DROPZONE
if input.is_pressed(): if input.is_pressed():
reorder_areas("dropzone_content") reorder_areas("dropzone_content")
@ -183,7 +183,7 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
else: else:
dropzone.move_child(currently_dragged_area, -1) dropzone.move_child(currently_dragged_area, -1)
currently_dragged_area = null currently_dragged_area = null
"post-it": # 2 = PostIt elif to_handle is PostIt:
if input.is_pressed(): if input.is_pressed():
to_handle.reparent(dropzone) to_handle.reparent(dropzone)
to_handle.on_board = true to_handle.on_board = true
@ -195,7 +195,7 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
if is_in_dropzone(to_handle): if is_in_dropzone(to_handle):
if to_handle.has_overlapping_areas(): if to_handle.has_overlapping_areas():
for area in to_handle.get_overlapping_areas(): for area in to_handle.get_overlapping_areas():
if area.get_meta("type") == "card": if area is Card:
if !area.has_postit_attached(): if !area.has_postit_attached():
attach_postit_to_card(to_handle, area) attach_postit_to_card(to_handle, area)
else: else:
@ -346,7 +346,7 @@ func _input(event):
# Sets everything up to enter the context where postits can be assigned via button controls # Sets everything up to enter the context where postits can be assigned via button controls
func _enter_assignment_context(): func _enter_assignment_context():
# cards are currently not moved, only post its. Exit function if a card should be moved. # cards are currently not moved, only post its. Exit function if a card should be moved.
if currently_selected_node == null or currently_selected_node.get_meta("type") != "post-it" : return if currently_selected_node == null or not currently_selected_node is PostIt : return
# if the postit is already attached, remove it and return it to the post it panels # if the postit is already attached, remove it and return it to the post it panels
if currently_selected_node.is_postit_attached(): if currently_selected_node.is_postit_attached():

View File

@ -65,8 +65,6 @@ var mouse_offset: Vector2
func _ready(): func _ready():
self.set_meta("type", "card") # set type information to find out if this node is a card
_handle_wiggle(0) _handle_wiggle(0)
if not Engine.is_editor_hint() and is_inside_tree(): if not Engine.is_editor_hint() and is_inside_tree():
for postit in self.get_children(): for postit in self.get_children():
@ -155,7 +153,7 @@ func _move_card():
func has_postit_attached() -> bool: func has_postit_attached() -> bool:
var all_children = get_children() var all_children = get_children()
for child in all_children: for child in all_children:
if child.get_meta("type") == "post-it": if child is PostIt:
return true return true
return false return false

View File

@ -57,8 +57,6 @@ var on_board = false
func _ready() -> void: func _ready() -> void:
self.set_meta("type", "post-it") # set type information to find out if this node is a post-it
$Content/Label.text = self.text $Content/Label.text = self.text
$Content/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation) $Content/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation)
@ -118,7 +116,7 @@ func _move_post_it():
position += (get_viewport().get_mouse_position() - position) - mouse_offset position += (get_viewport().get_mouse_position() - position) - mouse_offset
func is_postit_attached() -> bool: func is_postit_attached() -> bool:
if self.get_parent().get_meta("type") == "card": if self.get_parent() is Card:
return true return true
return false return false