WIP: refactoring card_board

This commit is contained in:
betalars 2023-08-30 13:23:37 +02:00
parent a1e186c2c6
commit 5f1322fe93
2 changed files with 35 additions and 38 deletions

View File

@ -1,11 +1,11 @@
extends PanelContainer extends PanelContainer
var area_dict = { #var area_dict = {
"dropzone_content": [], # "dropzone_content": [],
"cards": [], # "cards": [],
"post_its_in_list": [], # "post_its_in_list": [],
"post_it_panels": [] # "post_it_panels": []
} #}
enum ui_context {DROPZONE, POST_IT_LIST, ASSIGN_POST_IT} enum ui_context {DROPZONE, POST_IT_LIST, ASSIGN_POST_IT}
var has_stage = false: var has_stage = false:
@ -18,11 +18,10 @@ var has_stage = false:
has_stage = false has_stage = false
self.mouse_filter = Control.MOUSE_FILTER_IGNORE self.mouse_filter = Control.MOUSE_FILTER_IGNORE
if is_node_ready(): if is_node_ready():
for child in area_dict["dropzone_content"]+area_dict["post_its_in_list"]: if focus:
if focus: process_mode = Node.PROCESS_MODE_INHERIT
child.process_mode = Node.PROCESS_MODE_INHERIT else:
else: process_mode = Node.PROCESS_MODE_DISABLED
child.process_mode = Node.PROCESS_MODE_DISABLED
visible = has_stage visible = has_stage
@onready var dropzone = $HBoxContainer/dropzone @onready var dropzone = $HBoxContainer/dropzone
@ -99,21 +98,22 @@ func populate_board(card_names: Array):
new_card.position = Vector2(randi_range(dropzone_padding, dropzone_size.x), randi_range(dropzone_padding, dropzone_size.y)) new_card.position = Vector2(randi_range(dropzone_padding, dropzone_size.x), randi_range(dropzone_padding, dropzone_size.y))
new_card.reparent(dropzone, false) new_card.reparent(dropzone, false)
new_card.set_owner(self) new_card.set_owner(self)
area_dict["dropzone_content"].push_back(new_card) #area_dict["dropzone_content"].push_back(new_card)
area_dict["cards"].push_back(new_card) #area_dict["cards"].push_back(new_card)
new_card.is_dragable = true new_card.is_dragable = true
for new_postit in all_new["postIts"]: # spawning a post-it for new_postit in all_new["postIts"]: # spawning a post-it
var new_panel = base_postit_panel.duplicate() var new_panel = base_postit_panel.duplicate()
postit_container.add_child(new_panel) postit_container.add_child(new_panel)
new_panel.set_owner(self) new_panel.set_owner(self)
area_dict["post_it_panels"].append(new_panel) #area_dict["post_it_panels"].append(new_panel)
new_panel.add_child(new_postit) new_panel.add_child(new_postit)
new_postit.set_owner(self) new_postit.set_owner(self)
area_dict["post_its_in_list"].push_back(new_postit) #area_dict["post_its_in_list"].push_back(new_postit)
new_postit.position = new_panel.get_child(0).position new_postit.position = new_panel.get_child(0).position
new_postit.is_dragable = true new_postit.is_dragable = true
currently_selected_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default #currently_selected_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default
currently_selected_node = dropzone.get_child(0)
reorder_areas("dropzone_content") reorder_areas("dropzone_content")
reorder_areas("cards") reorder_areas("cards")
@ -121,12 +121,7 @@ func populate_board(card_names: Array):
# Checks if a Node is currently inside the dropzone # Checks if a Node is currently inside the dropzone
func is_in_dropzone(to_check: Node) -> bool: func is_in_dropzone(to_check: Node) -> bool:
if (dropzone.size.x < to_check.global_position.x or dropzone.size.y < to_check.global_position.y): return dropzone.get_rect().has_point(to_check.global_position)
return false
elif (to_check.global_position.x < 0 or to_check.global_position.y < 0):
return false
else:
return true
# called if a mouse button is pressed # called if a mouse button is pressed
func handle_mouse_button(to_handle: Area2D, input: InputEvent): func handle_mouse_button(to_handle: Area2D, input: InputEvent):
@ -156,8 +151,8 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
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
area_dict["post_its_in_list"].erase(to_handle) #area_dict["post_its_in_list"].erase(to_handle)
area_dict["dropzone_content"].push_back(to_handle) #area_dict["dropzone_content"].push_back(to_handle)
elif input.is_action_pressed("mouse_right"): elif input.is_action_pressed("mouse_right"):
_return_postit_to_panels(to_handle) _return_postit_to_panels(to_handle)
to_handle.is_dragged = false to_handle.is_dragged = false
@ -180,7 +175,7 @@ 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, preview = false):
if card.has_postit_attached(): if card.has_postit_attached():
if active_context == ui_context.ASSIGN_POST_IT: if active_context == ui_context.ASSIGN_POST_IT:
@ -190,26 +185,27 @@ func attach_postit_to_card(postit: Area2D, card: Area2D, update_dict = false):
postit.set_owner(self) postit.set_owner(self)
if update_dict: #if update_dict:
area_dict["post_its_in_list"].erase(postit) # area_dict["post_its_in_list"].erase(postit)
area_dict["dropzone_content"].push_back(postit) # area_dict["dropzone_content"].push_back(postit)
reorder_areas("dropzone_content") reorder_areas("dropzone_content")
reorder_areas("cards") reorder_areas("cards")
reorder_areas("post_its_in_list") reorder_areas("post_its_in_list")
func is_board_complete() -> bool:
if mementos_collected == 4: if mementos_collected == 4:
for fluff in area_dict["dropzone_content"]: for card in dropzone.get_children():
if fluff is Card: if card is Card:
if not fluff.has_postit_attached(): if not card.has_postit_attached():
return return false
emit_signal("board_completed") return true
return false
func is_board_lore() -> bool: func is_board_lore() -> bool:
for post_it in area_dict["dropzone_content"]: for card in dropzone.get_children():
if post_it is PostIt: if card.has_postit_attached():
var card = post_it.get_parent().get_parent() if not card.current_post_it.is_in_group(card.name): return false
if not post_it.is_in_group(card.name): return false
return true return true
# Mark area that was hovered over as currently selected # Mark area that was hovered over as currently selected

View File

@ -4,7 +4,7 @@
[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://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" uid="uid://chwf61qpn2sqw" 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"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ttqei"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_ttqei"]
@ -30,6 +30,7 @@ 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