wip: refactoring casrd board

This commit is contained in:
betalars 2023-08-30 11:07:22 +02:00
parent f962cdfe7a
commit 6824a75e29
4 changed files with 58 additions and 45 deletions

View File

@ -182,33 +182,35 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
# Logic for attaching a postit to a card. Also reset postit positions if the card cannot be attached # 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, update_dict = false): func attach_postit_to_card(postit: Area2D, card: Area2D, update_dict = false):
if postit.is_in_group(card.name): if card.has_postit_attached():
if active_context == ui_context.ASSIGN_POST_IT:
_return_postit_to_panels(postit) # don't attach if card has already a post-it attached
return
if card.has_postit_attached():
if active_context == ui_context.ASSIGN_POST_IT: postit.set_owner(self)
_return_postit_to_panels(postit) # don't attach if card has already a post-it attached
return if update_dict:
area_dict["post_its_in_list"].erase(postit)
postit.reparent(card.get_child(3, true)) area_dict["dropzone_content"].push_back(postit)
postit.position = Vector2(0,0)
postit.on_board = false reorder_areas("dropzone_content")
postit.set_owner(self) reorder_areas("cards")
postit.position = card.get_child(3).position reorder_areas("post_its_in_list")
if update_dict: if mementos_collected == 4:
area_dict["post_its_in_list"].erase(postit) for fluff in area_dict["dropzone_content"]:
area_dict["dropzone_content"].push_back(postit) if fluff is Card:
if not fluff.has_postit_attached():
reorder_areas("dropzone_content") return
reorder_areas("cards") emit_signal("board_completed")
reorder_areas("post_its_in_list")
func is_board_lore() -> bool:
if mementos_collected == 4: for post_it in area_dict["dropzone_content"]:
for fluff in area_dict["dropzone_content"]: if post_it is PostIt:
if fluff is Card: var card = post_it.get_parent().get_parent()
if not fluff.has_postit_attached(): if not post_it.is_in_group(card.name): return false
return return true
emit_signal("board_completed")
# Mark area that was hovered over as currently selected # Mark area that was hovered over as currently selected
func handle_hover(to_handle: Area2D): func handle_hover(to_handle: Area2D):
@ -347,7 +349,7 @@ func _enter_assignment_context():
# move the post it so it floats next to the card where it should be attached # move the post it so it floats next to the card where it should be attached
func _select_card_for_assigning(post_it: Area2D, card: Area2D): func _select_card_for_assigning(post_it: Area2D, card: Area2D):
post_it.tween_transform_to(card.get_child(3).global_position + Vector2(0, 50)) post_it.tween_transform_to(card.get_child(3).global_position)
# leaves the context for assigning postit via button controls # leaves the context for assigning postit via button controls
func _leave_assignment_context(): func _leave_assignment_context():

View File

@ -4,6 +4,11 @@ extends Area2D
class_name Card class_name Card
var compatible_postits: Array[PostIt] = [] var compatible_postits: Array[PostIt] = []
var own_postits: Array[PostIt] = [] var own_postits: Array[PostIt] = []
var current_post_it: PostIt = null
var is_in_preview: bool = false:
set(preview):
is_in_preview = preview
highlighted = preview
var wiggle_pos: float = 0 var wiggle_pos: float = 0
var wiggle_intensity: float = 0 var wiggle_intensity: float = 0
var noise: Noise = FastNoiseLite.new() var noise: Noise = FastNoiseLite.new()
@ -152,8 +157,29 @@ func _move_card():
position += (get_viewport().get_mouse_position() - position) - mouse_offset position += (get_viewport().get_mouse_position() - position) - mouse_offset
func has_postit_attached() -> bool: func has_postit_attached() -> bool:
return postit_anchor.get_child(-1) is PostIt return is_instance_valid(current_post_it) and not is_in_preview
func preview_postit(postit: PostIt) -> bool:
is_in_preview = attach_postit(postit)
return is_in_preview
func attach_postit(postit: PostIt) -> bool:
if is_instance_valid(current_post_it):
return false
postit.reparent(get_child(3, true))
postit.position = Vector2(0,0)
postit.on_board = false
if not is_in_preview: current_post_it = postit
return true
func remove_postit() -> PostIt:
var former_child:PostIt = current_post_it
current_post_it = null
former_child.reparent(get_parent())
former_child.on_board = true
is_in_preview = false
return former_child
func check_hover(): func check_hover():
if is_mouse_entered: if is_mouse_entered:
_on_mouse_entered() _on_mouse_entered()

View File

@ -83,7 +83,7 @@ theme_type_variation = &"card_text"
autowrap_mode = 3 autowrap_mode = 3
[node name="postit anchor" type="Node2D" parent="."] [node name="postit anchor" type="Node2D" parent="."]
position = Vector2(0, 21) position = Vector2(-66, 83)
[connection signal="input_event" from="." to="." method="_on_input_event"] [connection signal="input_event" from="." to="." method="_on_input_event"]
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] [connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]

View File

@ -1,9 +1,8 @@
[gd_scene load_steps=11 format=3 uid="uid://bnskiyx1sksww"] [gd_scene load_steps=10 format=3 uid="uid://bnskiyx1sksww"]
[ext_resource type="Texture2D" uid="uid://bi3xqdknw5tpe" path="res://logic-scenes/board/board-texture/Cork002_2K_Color.png" id="1_8brxc"] [ext_resource type="Texture2D" uid="uid://bi3xqdknw5tpe" path="res://logic-scenes/board/board-texture/Cork002_2K_Color.png" id="1_8brxc"]
[ext_resource type="Shader" path="res://logic-scenes/board/physics-board.gdshader" id="1_ggnth"] [ext_resource type="Shader" path="res://logic-scenes/board/physics-board.gdshader" id="1_ggnth"]
[ext_resource type="Script" path="res://logic-scenes/board/card-board.gd" id="3_8v4c4"] [ext_resource type="Script" path="res://logic-scenes/board/card-board.gd" id="3_8v4c4"]
[ext_resource type="PackedScene" uid="uid://dy5rd437h5hsw" path="res://logic-scenes/board/card.tscn" id="3_mg053"]
[ext_resource type="PackedScene" uid="uid://bvowj4l8dtceu" path="res://dev-util/board of devs.tscn" id="4_sskx2"] [ext_resource type="PackedScene" uid="uid://bvowj4l8dtceu" path="res://dev-util/board of devs.tscn" id="4_sskx2"]
[ext_resource type="PackedScene" path="res://logic-scenes/board/empty_postIt_panel.tscn" id="5_dr0qs"] [ext_resource type="PackedScene" path="res://logic-scenes/board/empty_postIt_panel.tscn" id="5_dr0qs"]
[ext_resource type="Script" path="res://logic-scenes/board/card collider.gd" id="6_wpxls"] [ext_resource type="Script" path="res://logic-scenes/board/card collider.gd" id="6_wpxls"]
@ -41,20 +40,6 @@ layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
mouse_filter = 1 mouse_filter = 1
[node name="card3" parent="HBoxContainer/dropzone" instance=ExtResource("3_mg053")]
process_mode = 4
visible = false
z_as_relative = false
position = Vector2(371, 290)
collision_layer = 2147483649
is_dragable = true
[node name="card" parent="HBoxContainer/dropzone" instance=ExtResource("3_mg053")]
process_mode = 4
visible = false
position = Vector2(640, 659)
is_dragable = true
[node name="ScrollContainer" type="ScrollContainer" parent="HBoxContainer"] [node name="ScrollContainer" type="ScrollContainer" parent="HBoxContainer"]
layout_mode = 2 layout_mode = 2
horizontal_scroll_mode = 0 horizontal_scroll_mode = 0