WIP: finish cleaning up function architecture
This commit is contained in:
parent
f91bab668d
commit
a2c5217fbf
|
|
@ -30,7 +30,7 @@ var dropzone_size: Vector2
|
||||||
@onready var postit_container = $HBoxContainer/ScrollContainer/VBoxContainer
|
@onready var postit_container = $HBoxContainer/ScrollContainer/VBoxContainer
|
||||||
@onready var board_of_devs = $"board of devs"
|
@onready var board_of_devs = $"board of devs"
|
||||||
var base_postit_panel: Panel
|
var base_postit_panel: Panel
|
||||||
@onready var current_context = DROPZONE:
|
@onready var current_context:int = DROPZONE:
|
||||||
set(context):
|
set(context):
|
||||||
match context:
|
match context:
|
||||||
DROPZONE:
|
DROPZONE:
|
||||||
|
|
@ -142,47 +142,31 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
|
||||||
current_context = DROPZONE
|
current_context = DROPZONE
|
||||||
if !input.is_pressed():
|
if !input.is_pressed():
|
||||||
insert_area(dropzone, to_handle)
|
insert_area(dropzone, to_handle)
|
||||||
current_context = dropzone
|
current_context = DROPZONE
|
||||||
elif to_handle is PostIt:
|
elif to_handle is PostIt:
|
||||||
if input.is_action_pressed("mouse_left"):
|
if input.is_action_pressed("mouse_left"):
|
||||||
to_handle.reparent(dropzone)
|
to_handle.reparent(dropzone)
|
||||||
to_handle.on_board = true
|
to_handle.on_board = true
|
||||||
to_handle.set_owner(self) # needs to be here otherwise the owner disappears
|
to_handle.set_owner(self) # needs to be here otherwise the owner disappears
|
||||||
elif input.is_action_pressed("mouse_right"):
|
if input.is_action_pressed("mouse_right"):
|
||||||
_return_postit_to_panels(to_handle)
|
_return_postits_to_panels()
|
||||||
to_handle.is_dragged = false
|
|
||||||
is_area_dragged = false
|
|
||||||
currently_dragged_area = null
|
|
||||||
else:
|
else:
|
||||||
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 is Card:
|
if area is Card:
|
||||||
if !area.has_postit_attached():
|
if area.has_postit_attached():
|
||||||
attach_postit_to_card(to_handle, area)
|
area.exchange_postIt_with(to_handle).reparent(dropzone)
|
||||||
else:
|
else:
|
||||||
to_handle.rotation = to_handle.base_rotation
|
to_handle.rotation = to_handle.base_rotation
|
||||||
to_handle.scale = to_handle.base_scale
|
to_handle.scale = to_handle.base_scale
|
||||||
else:
|
else:
|
||||||
current_context = POST_IT_LIST
|
current_context = POST_IT_LIST
|
||||||
_return_postit_to_panels(to_handle)
|
_return_postits_to_panels()
|
||||||
currently_dragged_area = null
|
|
||||||
|
|
||||||
|
func _return_postits_to_panels():
|
||||||
# Logic for attaching a postit to a card. Also reset postit positions if the card cannot be attached
|
for panel in postit_container.get_children():
|
||||||
func attach_postit_to_card(postit: Area2D, card: Area2D, preview = false):
|
panel.reclaim_postit()
|
||||||
|
|
||||||
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 is_board_complete() -> bool:
|
func is_board_complete() -> bool:
|
||||||
if mementos_collected == 4:
|
if mementos_collected == 4:
|
||||||
|
|
@ -206,10 +190,11 @@ func handle_hover(to_handle: Area2D):
|
||||||
currently_active_node = to_handle
|
currently_active_node = to_handle
|
||||||
|
|
||||||
if is_in_dropzone(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
|
current_context = DROPZONE
|
||||||
else:
|
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
|
current_context = POST_IT_LIST
|
||||||
|
|
||||||
# Adds a child at the correct child indext in an area
|
# Adds a child at the correct child indext in an area
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,7 @@ func _handle_wiggle(delta):
|
||||||
|
|
||||||
rotation = noise.get_noise_1d(wiggle_pos)*wiggle_strength
|
rotation = noise.get_noise_1d(wiggle_pos)*wiggle_strength
|
||||||
|
|
||||||
|
## Deprecated
|
||||||
func replace_with(card: Card):
|
func replace_with(card: Card):
|
||||||
self.text = card.text
|
self.text = card.text
|
||||||
self.compatible_postits = card.compatible_postits
|
self.compatible_postits = card.compatible_postits
|
||||||
|
|
@ -125,6 +126,7 @@ func _on_focus_exited():
|
||||||
func _on_mouse_entered():
|
func _on_mouse_entered():
|
||||||
is_mouse_entered = true
|
is_mouse_entered = true
|
||||||
if not Input.is_action_pressed("mouse_left"):
|
if not Input.is_action_pressed("mouse_left"):
|
||||||
|
# Do nothing if mouse hovers over postIt
|
||||||
if has_postit_attached():
|
if has_postit_attached():
|
||||||
if postit_anchor.get_child(-1).highlighted:
|
if postit_anchor.get_child(-1).highlighted:
|
||||||
return
|
return
|
||||||
|
|
@ -168,6 +170,7 @@ func attach_postit(postit: PostIt) -> bool:
|
||||||
postit.position = Vector2(0,0)
|
postit.position = Vector2(0,0)
|
||||||
postit.on_board = false
|
postit.on_board = false
|
||||||
current_post_it = postit
|
current_post_it = postit
|
||||||
|
postit.attatched_to = self
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func remove_postit() -> PostIt:
|
func remove_postit() -> PostIt:
|
||||||
|
|
@ -176,6 +179,7 @@ func remove_postit() -> PostIt:
|
||||||
current_post_it = null
|
current_post_it = null
|
||||||
former_child.reparent(get_parent())
|
former_child.reparent(get_parent())
|
||||||
former_child.on_board = true
|
former_child.on_board = true
|
||||||
|
former_child.attatched_to = null
|
||||||
return former_child
|
return former_child
|
||||||
|
|
||||||
func exchange_postIt_with(new_post: PostIt) -> PostIt:
|
func exchange_postIt_with(new_post: PostIt) -> PostIt:
|
||||||
|
|
@ -183,6 +187,7 @@ func exchange_postIt_with(new_post: PostIt) -> PostIt:
|
||||||
attach_postit(new_post)
|
attach_postit(new_post)
|
||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
|
## TODO why does this exist?
|
||||||
func check_hover():
|
func check_hover():
|
||||||
if is_mouse_entered:
|
if is_mouse_entered:
|
||||||
_on_mouse_entered()
|
_on_mouse_entered()
|
||||||
|
|
|
||||||
|
|
@ -21,20 +21,26 @@ func attatch_postit(attatchment: PostIt, tween:bool = true):
|
||||||
attatchment.reparent(self)
|
attatchment.reparent(self)
|
||||||
attatched_postIt = attatchment
|
attatched_postIt = attatchment
|
||||||
attatchment.owner = self.owner
|
attatchment.owner = self.owner
|
||||||
|
attatchment.attatched_to = self
|
||||||
|
|
||||||
func lend_postit() -> PostIt:
|
func reclaim_postit():
|
||||||
attatched_postIt.on_board = true
|
if is_empty():
|
||||||
return attatched_postIt
|
attatched_postIt.on_board = false
|
||||||
|
attatched_postIt.tween_transform_to(ancor.global_position)
|
||||||
func return_postit():
|
await attatched_postIt.transform_tween_finished
|
||||||
attatched_postIt.on_board = false
|
attatched_postIt.reparent(self)
|
||||||
attatched_postIt.tween_transform_to(ancor.global_position)
|
attatched_postIt.owner = self.owner
|
||||||
await attatched_postIt.transform_tween_finished
|
|
||||||
attatched_postIt.reparent(self)
|
|
||||||
attatched_postIt.owner = self.owner
|
|
||||||
|
|
||||||
func dissolve():
|
func dissolve():
|
||||||
|
if attatched_postIt.attatched_to == self: attatched_postIt.attatched_to = null
|
||||||
var height_tween: Tween = create_tween()
|
var height_tween: Tween = create_tween()
|
||||||
height_tween.tween_property(self, "custom_minimum_size", Vector2.ZERO, 0.3)
|
height_tween.tween_property(self, "custom_minimum_size", Vector2.ZERO, 0.3)
|
||||||
await height_tween.finished
|
await height_tween.finished
|
||||||
self.free()
|
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
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ size_flags_horizontal = 6
|
||||||
size_flags_vertical = 6
|
size_flags_vertical = 6
|
||||||
mouse_filter = 1
|
mouse_filter = 1
|
||||||
script = ExtResource("3_8v4c4")
|
script = ExtResource("3_8v4c4")
|
||||||
dropzone_padding = null
|
|
||||||
|
|
||||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,8 @@ var mouse_offset: Vector2
|
||||||
|
|
||||||
@onready var diameter = $CollisionShape2D.shape.height
|
@onready var diameter = $CollisionShape2D.shape.height
|
||||||
@export_range(1.0, 10.0) var bounce_speed: float = 8
|
@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:
|
func _ready() -> void:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue