From 4d51a218767bd73fef90c902c2a6639a89058065 Mon Sep 17 00:00:00 2001 From: betalars Date: Tue, 18 Jul 2023 23:25:56 +0200 Subject: [PATCH] changing chekc using metadata to use class info --- src/logic-scenes/board/card-board.gd | 62 ++++++++++++++-------------- src/logic-scenes/board/card.gd | 4 +- src/logic-scenes/board/post-it.gd | 4 +- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index a01b436..d10424c 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -174,37 +174,37 @@ 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. # (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)) - match to_handle.get_meta("type"): - "card": # 1 = Card - active_context = ui_context.DROPZONE - if input.is_pressed(): - reorder_areas("dropzone_content") - reorder_areas("cards") + if to_handle is Card: + + active_context = ui_context.DROPZONE + if input.is_pressed(): + reorder_areas("dropzone_content") + reorder_areas("cards") + else: + dropzone.move_child(currently_dragged_area, -1) + currently_dragged_area = null + elif to_handle is PostIt: + if input.is_pressed(): + to_handle.reparent(dropzone) + to_handle.on_board = true + to_handle.set_owner(self) # needs to be here otherwise the owner disappears + area_dict["post_its_in_list"].erase(to_handle) + area_dict["dropzone_content"].push_back(to_handle) + # TODO (if needed): Add function to rearrange the array based on positions in the dropzone + else: + if is_in_dropzone(to_handle): + if to_handle.has_overlapping_areas(): + for area in to_handle.get_overlapping_areas(): + if area is Card: + if !area.has_postit_attached(): + attach_postit_to_card(to_handle, area) + else: + to_handle.rotation = to_handle.base_rotation + to_handle.scale = to_handle.base_scale else: - dropzone.move_child(currently_dragged_area, -1) - currently_dragged_area = null - "post-it": # 2 = PostIt - if input.is_pressed(): - to_handle.reparent(dropzone) - to_handle.on_board = true - to_handle.set_owner(self) # needs to be here otherwise the owner disappears - area_dict["post_its_in_list"].erase(to_handle) - area_dict["dropzone_content"].push_back(to_handle) - # TODO (if needed): Add function to rearrange the array based on positions in the dropzone - else: - if is_in_dropzone(to_handle): - if to_handle.has_overlapping_areas(): - for area in to_handle.get_overlapping_areas(): - if area.get_meta("type") == "card": - if !area.has_postit_attached(): - attach_postit_to_card(to_handle, area) - else: - to_handle.rotation = to_handle.base_rotation - to_handle.scale = to_handle.base_scale - else: - active_context = ui_context.POST_IT_LIST - _return_postit_to_panels(to_handle) - currently_dragged_area = null + active_context = ui_context.POST_IT_LIST + _return_postit_to_panels(to_handle) + currently_dragged_area = null # Logic for attaching a postit to a card. Also reset postit positions if the card cannot be attached @@ -346,7 +346,7 @@ func _input(event): # Sets everything up to enter the context where postits can be assigned via button controls func _enter_assignment_context(): # 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 currently_selected_node.is_postit_attached(): diff --git a/src/logic-scenes/board/card.gd b/src/logic-scenes/board/card.gd index ce7120f..f3c8a06 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -65,8 +65,6 @@ var mouse_offset: Vector2 func _ready(): - self.set_meta("type", "card") # set type information to find out if this node is a card - _handle_wiggle(0) if not Engine.is_editor_hint() and is_inside_tree(): for postit in self.get_children(): @@ -155,7 +153,7 @@ func _move_card(): func has_postit_attached() -> bool: var all_children = get_children() for child in all_children: - if child.get_meta("type") == "post-it": + if child is PostIt: return true return false diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index 47bf360..4df1b0f 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -57,8 +57,6 @@ var on_board = false 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/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 func is_postit_attached() -> bool: - if self.get_parent().get_meta("type") == "card": + if self.get_parent() is Card: return true return false