WIP: finish cleaning up function architecture

This commit is contained in:
betalars 2023-09-24 12:23:26 +02:00
parent f91bab668d
commit a2c5217fbf
5 changed files with 44 additions and 48 deletions

View File

@ -30,7 +30,7 @@ var dropzone_size: Vector2
@onready var postit_container = $HBoxContainer/ScrollContainer/VBoxContainer
@onready var board_of_devs = $"board of devs"
var base_postit_panel: Panel
@onready var current_context = DROPZONE:
@onready var current_context:int = DROPZONE:
set(context):
match context:
DROPZONE:
@ -142,47 +142,31 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
current_context = DROPZONE
if !input.is_pressed():
insert_area(dropzone, to_handle)
current_context = dropzone
current_context = DROPZONE
elif to_handle is PostIt:
if input.is_action_pressed("mouse_left"):
to_handle.reparent(dropzone)
to_handle.on_board = true
to_handle.set_owner(self) # needs to be here otherwise the owner disappears
elif input.is_action_pressed("mouse_right"):
_return_postit_to_panels(to_handle)
to_handle.is_dragged = false
is_area_dragged = false
currently_dragged_area = null
if input.is_action_pressed("mouse_right"):
_return_postits_to_panels()
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
if to_handle.has_overlapping_areas():
for area in to_handle.get_overlapping_areas():
if area is Card:
if area.has_postit_attached():
area.exchange_postIt_with(to_handle).reparent(dropzone)
else:
to_handle.rotation = to_handle.base_rotation
to_handle.scale = to_handle.base_scale
else:
current_context = POST_IT_LIST
_return_postit_to_panels(to_handle)
currently_dragged_area = null
_return_postits_to_panels()
# Logic for attaching a postit to a card. Also reset postit positions if the card cannot be attached
func attach_postit_to_card(postit: Area2D, card: Area2D, preview = false):
if card.has_postit_attached():
if current_context == ASSIGN_POST_IT:
_return_postit_to_panels(postit) # don't attach if card has already a post-it attached
return
postit.set_owner(self)
#if update_dict:
# area_dict["post_its_in_list"].erase(postit)
# area_dict["dropzone_content"].push_back(postit)
func _return_postits_to_panels():
for panel in postit_container.get_children():
panel.reclaim_postit()
func is_board_complete() -> bool:
if mementos_collected == 4:
@ -206,10 +190,11 @@ func handle_hover(to_handle: Area2D):
currently_active_node = to_handle
if is_in_dropzone(to_handle):
current_dropzone_id = area_dict["dropzone_content"].find(to_handle)
if to_handle is Card or (to_handle is PostIt and to_handle.on_board):
current_dropzone_id = dropzone.get_children().find(to_handle)
current_context = DROPZONE
else:
current_postIt_id = area_dict["post_its_in_list"].find(to_handle)
current_postIt_id = postit_container.get_children().find(to_handle.attatched_to)
current_context = POST_IT_LIST
# Adds a child at the correct child indext in an area

View File

@ -109,6 +109,7 @@ func _handle_wiggle(delta):
rotation = noise.get_noise_1d(wiggle_pos)*wiggle_strength
## Deprecated
func replace_with(card: Card):
self.text = card.text
self.compatible_postits = card.compatible_postits
@ -125,6 +126,7 @@ func _on_focus_exited():
func _on_mouse_entered():
is_mouse_entered = true
if not Input.is_action_pressed("mouse_left"):
# Do nothing if mouse hovers over postIt
if has_postit_attached():
if postit_anchor.get_child(-1).highlighted:
return
@ -168,6 +170,7 @@ func attach_postit(postit: PostIt) -> bool:
postit.position = Vector2(0,0)
postit.on_board = false
current_post_it = postit
postit.attatched_to = self
return true
func remove_postit() -> PostIt:
@ -176,6 +179,7 @@ func remove_postit() -> PostIt:
current_post_it = null
former_child.reparent(get_parent())
former_child.on_board = true
former_child.attatched_to = null
return former_child
func exchange_postIt_with(new_post: PostIt) -> PostIt:
@ -183,6 +187,7 @@ func exchange_postIt_with(new_post: PostIt) -> PostIt:
attach_postit(new_post)
return tmp
## TODO why does this exist?
func check_hover():
if is_mouse_entered:
_on_mouse_entered()

View File

@ -21,20 +21,26 @@ func attatch_postit(attatchment: PostIt, tween:bool = true):
attatchment.reparent(self)
attatched_postIt = attatchment
attatchment.owner = self.owner
attatchment.attatched_to = self
func lend_postit() -> PostIt:
attatched_postIt.on_board = true
return attatched_postIt
func return_postit():
attatched_postIt.on_board = false
attatched_postIt.tween_transform_to(ancor.global_position)
await attatched_postIt.transform_tween_finished
attatched_postIt.reparent(self)
attatched_postIt.owner = self.owner
func reclaim_postit():
if is_empty():
attatched_postIt.on_board = false
attatched_postIt.tween_transform_to(ancor.global_position)
await attatched_postIt.transform_tween_finished
attatched_postIt.reparent(self)
attatched_postIt.owner = self.owner
func dissolve():
if attatched_postIt.attatched_to == self: attatched_postIt.attatched_to = null
var height_tween: Tween = create_tween()
height_tween.tween_property(self, "custom_minimum_size", Vector2.ZERO, 0.3)
await height_tween.finished
self.free()
func replace_postit_with(new_postit: PostIt):
if is_empty():
attatched_postIt = new_postit
func is_empty():
return ancor.get_child_count() == 0

View File

@ -30,7 +30,6 @@ size_flags_horizontal = 6
size_flags_vertical = 6
mouse_filter = 1
script = ExtResource("3_8v4c4")
dropzone_padding = null
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 2

View File

@ -55,7 +55,8 @@ var mouse_offset: Vector2
@onready var diameter = $CollisionShape2D.shape.height
@export_range(1.0, 10.0) var bounce_speed: float = 8
var on_board = false
var on_board: bool = false
var attatched_to: Node = null
func _ready() -> void: