updating card handling

This commit is contained in:
betalars 2023-08-01 10:59:24 +02:00
parent 7546367370
commit a96e5630c8
7 changed files with 127 additions and 105 deletions

View File

@ -0,0 +1,40 @@
extends Control
func get_cards_by_scene_id(id: int) -> Array:
var output:Array
var scene = get_child(id)
for i in range(scene.get_child_count()):
output.append(scene.get_child(i))
for post in output[i].get_children():
if post is PostIt:
output[i].remove_child(post)
for card in output:
card.transform = Transform3D()
for postIt in card.own_postits:
postIt.transform = Transform3D()
return output
func get_cards_by_name_array(names: Array) -> Dictionary:
var output:Dictionary = {
"cards": [],
"postIts": []
}
for scene in get_children():
for card in scene.get_children():
for postIt in card.get_children():
if names.has(postIt.name):
postIt.transform = Transform3D()
output['postIts'].append(postIt)
if names.has(card.name):
card.transform = Transform3D()
output['cards'].append(card)
for child in card.get_children():
if child is PostIt:
card.remove_child(child)
return output

View File

@ -13,6 +13,7 @@ var has_stage = false:
if focus: if focus:
has_stage = true has_stage = true
self.mouse_filter = Control.MOUSE_FILTER_PASS self.mouse_filter = Control.MOUSE_FILTER_PASS
get_tree().call_group("interactables", "collapse")
else: else:
has_stage = false has_stage = false
self.mouse_filter = Control.MOUSE_FILTER_IGNORE self.mouse_filter = Control.MOUSE_FILTER_IGNORE
@ -25,9 +26,11 @@ var has_stage = false:
visible = has_stage visible = has_stage
@onready var dropzone = $HBoxContainer/dropzone @onready var dropzone = $HBoxContainer/dropzone
var dropzone_size: Vector2
@export var dropzone_padding = 100
@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"
@onready var base_postit_panel = $HBoxContainer/ScrollContainer/VBoxContainer/Panel var base_postit_panel: Panel
@onready var active_context = ui_context.DROPZONE # 0 = dropzone, 1 = post it list @onready var active_context = ui_context.DROPZONE # 0 = dropzone, 1 = post it list
@onready var instructions = $instructions_panel/HBoxContainer/cards_remaining @onready var instructions = $instructions_panel/HBoxContainer/cards_remaining
@ -59,12 +62,15 @@ signal board_completed
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
base_postit_panel = $HBoxContainer/ScrollContainer/VBoxContainer/Panel
postit_container.remove_child(base_postit_panel)
#var test_arr = ["c_Joy","p_effort","c_backlash","c_body","c_hit","p_slut","p_worried_mother","p_cross_friend"] dropzone_size = get_viewport_rect().size - Vector2(dropzone_padding + base_postit_panel.custom_minimum_size.x, dropzone_padding)
#var test_arr = ["c_Joy","c_body","c_hit"]
if get_parent() == get_tree().root:
populate_board(["c_void", 'c_joy', "p_wet", "p_thomas"])
populate_board(["c_fighting", 'c_hit', "p_girly", "p_vent"])
#populate_board(test_arr)
#reorder_areas("dropzone_content")
active_context = ui_context.DROPZONE active_context = ui_context.DROPZONE
has_stage = has_stage has_stage = has_stage
@ -81,63 +87,31 @@ func _process(delta):
# Will be used later to spawn Cards and Post-Its and remember them in the dictionary # Will be used later to spawn Cards and Post-Its and remember them in the dictionary
func populate_board(card_names: Array): func populate_board(card_names: Array):
mementos_collected += 1 mementos_collected += 1
cache.append_array(card_names)
if mementos_collected < 4: return var all_new:Dictionary = board_of_devs.get_cards_by_name_array(card_names)
else: card_names = cache
var all_cards = Array() var new_cards:Array = all_new["cards"]
var all_postits = Array() var new_postits:Array = all_new["postIts"]
# to remember panel positions # spawning the cards and adding them to the dictionary
area_dict["post_it_panels"] = [base_postit_panel] for new_card in all_new["cards"]:
new_card.position = Vector2(randi_range(dropzone_padding, dropzone_size.x), randi_range(dropzone_padding, dropzone_size.y))
# check how many post-it panels we need new_card.reparent(dropzone, false)
var amount = -1 # starting with -1 to compensate for the base panel new_card.set_owner(self)
for card_name in card_names: area_dict["dropzone_content"].push_back(new_card)
if "p_" in card_name: area_dict["cards"].push_back(new_card)
amount += 1 new_card.is_dragable = true
while amount > 0: # creating panels up to the number of post-its 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"].push_back(new_panel) area_dict["post_it_panels"].append(new_panel)
amount -= 1 new_panel.add_child(new_postit)
new_postit.set_owner(self)
# get all the cards and post-its from the board of devs area_dict["post_its_in_list"].push_back(new_postit)
for child in board_of_devs.get_children(): new_postit.position = new_panel.get_child(0).position
for child_2 in child.get_children(): # put all cards in all_cards array new_postit.is_dragable = true
all_cards.push_back(child_2)
for child_3 in child_2.get_children(): # put all post-its in all_postits array
if "p_" in child_3.name: # post-its are currently children of cards.
all_postits.push_back(child_3) # If this changes, this logic needs to be adjusted.
# spawning the cards and adding them to the dictionary
for card_name in card_names:
if "c_" in card_name: # spawning a card
var new_card = _find_area_by_string(all_cards, card_name).duplicate()
for child in new_card.get_children(): # We need to clear all the post-its from the cards on the dev-board
if "p_" in child.name:
new_card.remove_child(child) # dev-board has post-its attached to the cards, which need to be removed
new_card.position = Vector2(randi_range(0, dropzone.size.x), randi_range(0, dropzone.size.y))
dropzone.add_child(new_card)
new_card.set_owner(self)
area_dict["dropzone_content"].push_back(new_card)
area_dict["cards"].push_back(new_card)
#new_card.position = Vector2(randf_range(new_card.diameter, dropzone.size.x), randf_range(new_card.diameter, dropzone.size.y)) - Vector2(new_card.diameter/2, new_card.diameter/2)
new_card.is_dragable = true
if "p_" in card_name: # spawning a post-it
var new_postit = _find_area_by_string(all_postits, card_name).duplicate()
for panel in area_dict["post_it_panels"]: # still mad I can't use the return_postit-func for this...
if panel.get_child_count() == 1:
panel.add_child(new_postit)
new_postit.set_owner(self)
area_dict["post_its_in_list"].push_back(new_postit)
new_postit.position = panel.get_child(0).position
new_postit.is_dragable = true
break
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
@ -145,15 +119,6 @@ func populate_board(card_names: Array):
reorder_areas("cards") reorder_areas("cards")
reorder_areas("post_its_in_list") reorder_areas("post_its_in_list")
# Handy function to filter an array of areas by the name of a card
func _find_area_by_string(area_arr: Array, name: String) -> Area2D:
for area in area_arr:
if area.name == name:
return area
return null
# 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): if (dropzone.size.x < to_check.global_position.x or dropzone.size.y < to_check.global_position.y):
@ -241,8 +206,7 @@ func attach_postit_to_card(postit: Area2D, card: Area2D, update_dict = false):
if not fluff.has_postit_attached(): if not fluff.has_postit_attached():
return return
emit_signal("board_completed") 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):
if to_handle != currently_selected_node: if to_handle != currently_selected_node:
@ -392,14 +356,14 @@ func _leave_assignment_context():
# handles everything to return a post it to the panels # handles everything to return a post it to the panels
func _return_postit_to_panels(post_it: Area2D): func _return_postit_to_panels(post_it: Area2D):
for panel in area_dict["post_it_panels"]: for panel in area_dict["post_it_panels"]:
print(area_dict["post_it_panels"])
if panel.get_child_count() == 1: if panel.get_child_count() == 1:
area_dict["dropzone_content"].erase(post_it) area_dict["dropzone_content"].erase(post_it)
post_it.on_board = false post_it.on_board = false
area_dict["post_its_in_list"].push_back(post_it) area_dict["post_its_in_list"].push_back(post_it)
post_it.tween_transform_to(panel.get_child(0).position) #post_it.tween_transform_to(panel.get_child(0).position)
post_it.rotation = post_it.base_rotation
post_it.scale = post_it.base_scale
post_it.reparent(panel) post_it.reparent(panel)
post_it.transform = panel.get_child(0).transform
post_it.set_owner(self) post_it.set_owner(self)
reorder_areas("dropzone_content") reorder_areas("dropzone_content")
reorder_areas("post_its_in_list") reorder_areas("post_its_in_list")

View File

@ -96,12 +96,15 @@ func _process(delta: float) -> void:
if area is Card or area is CardCollider: if area is Card or area is CardCollider:
if area is CardCollider: if area is CardCollider:
position += area.direction * delta position += area.direction * delta
elif not area.highlighted or self.highlighted: elif not (area.highlighted or self.highlighted) and area.is_dragable:
var diff:Vector2 = position - area.position var diff:Vector2 = position - area.position
position -= diff.normalized() * ((diff.length()-diameter)/diameter) * bounce_speed * (delta/(1.0/60)) position -= diff.normalized() * ((diff.length()-diameter)/diameter) * bounce_speed * (delta/(1.0/60))
_move_card() _move_card()
func get_text() -> String:
return $Label.text
func _handle_wiggle(delta): func _handle_wiggle(delta):
wiggle_pos += delta * wiggle_speed * wiggle_intensity wiggle_pos += delta * wiggle_speed * wiggle_intensity

View File

@ -0,0 +1,9 @@
[gd_scene format=3 uid="uid://chwf61qpn2sqw"]
[node name="Panel" type="Panel"]
self_modulate = Color(1, 1, 1, 0)
custom_minimum_size = Vector2(400, 120)
mouse_filter = 1
[node name="post-it_anchor1" type="Node2D" parent="."]
position = Vector2(105, 57)

View File

@ -1,10 +1,11 @@
[gd_scene load_steps=10 format=3 uid="uid://bnskiyx1sksww"] [gd_scene load_steps=11 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://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" 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"]
@ -61,14 +62,8 @@ horizontal_scroll_mode = 0
[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/ScrollContainer"] [node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/ScrollContainer"]
layout_mode = 2 layout_mode = 2
[node name="Panel" type="Panel" parent="HBoxContainer/ScrollContainer/VBoxContainer"] [node name="Panel" parent="HBoxContainer/ScrollContainer/VBoxContainer" instance=ExtResource("5_dr0qs")]
self_modulate = Color(1, 1, 1, 0)
custom_minimum_size = Vector2(400, 120)
layout_mode = 2 layout_mode = 2
mouse_filter = 1
[node name="post-it_anchor1" type="Node2D" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel"]
position = Vector2(105, 57)
[node name="board of devs" parent="." instance=ExtResource("4_sskx2")] [node name="board of devs" parent="." instance=ExtResource("4_sskx2")]
process_mode = 4 process_mode = 4
@ -133,9 +128,11 @@ shape = SubResource("RectangleShape2D_ivo5o")
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 4 size_flags_horizontal = 4
size_flags_vertical = 0 size_flags_vertical = 0
mouse_filter = 2
[node name="HBoxContainer" type="HBoxContainer" parent="instructions_panel"] [node name="HBoxContainer" type="HBoxContainer" parent="instructions_panel"]
layout_mode = 2 layout_mode = 2
mouse_filter = 2
[node name="VSeparator2" type="VSeparator" parent="instructions_panel/HBoxContainer"] [node name="VSeparator2" type="VSeparator" parent="instructions_panel/HBoxContainer"]
custom_minimum_size = Vector2(15, 0) custom_minimum_size = Vector2(15, 0)

View File

@ -11,19 +11,19 @@ enum {
DONE DONE
} }
@onready var debug_board:Control = $"board of devs" @onready var source_board:Control = $"board of devs"
var has_stage = false: var has_stage = false:
set(focus): set(focus):
if not focus == has_stage: if not focus == has_stage:
if focus: if focus:
if selection_state == INI or CARDS: process_mode = Node.PROCESS_MODE_INHERIT
for player in anim_players: player.play("reveal")
self.show() self.show()
self.mouse_filter = Control.MOUSE_FILTER_IGNORE self.mouse_filter = Control.MOUSE_FILTER_IGNORE
else: else:
self.mouse_filter = Control.MOUSE_FILTER_STOP self.mouse_filter = Control.MOUSE_FILTER_STOP
self.hide() self.hide()
process_mode = Node.PROCESS_MODE_DISABLED
has_stage = focus has_stage = focus
var _input_locked = true var _input_locked = true
@ -58,40 +58,51 @@ signal cards_picked(Array)
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
if get_parent() == get_tree().root: selection_state = CARDS
reset() reset()
func reset(): func reset():
output = [] output = []
options = [] options = []
anim_players = [] anim_players = []
curr_selection_id = -1
var card_controls = $cards.get_children() var card_controls = $cards.get_children()
for control in card_controls: for control in card_controls:
options.append(control.get_child(1)) options.append(control.get_child(1))
anim_players.append(control.get_child(0)) anim_players.append(control.get_child(0))
curr_selection_id = 0
for player in anim_players: player.play("reveal")
func fill_card_slots(id: int): func fill_card_slots(id: int):
for i in range($cards.get_child_count()): var new_cards = source_board.get_cards_by_scene_id(id)
var card:Card = $cards.get_child(i).get_child(1)
card.replace_with(debug_board.get_child(id).get_child(i) as Card) for i in range(new_cards.size()):
card.connect("mouse_entered", Callable(self, "get_highlight")) $cards.get_child(i).remove_child($cards.get_child(i).get_child(1))
card.owner = self var new_card = new_cards[i]
new_card.reparent($cards.get_child(i), false)
new_card.owner = self
new_card.connect("mouse_entered", Callable(self, "get_highlight"))
options.append(new_card)
anim_players.append($cards.get_child(i).get_child(0))
reset()
func fill_post_slots(): func fill_post_slots():
var post_its: Array[PostIt] = [] var post_its: Array[PostIt] = []
for card in output: for card in output:
post_its.append_array(card.own_postits) post_its.append_array(card.own_postits)
print(card.own_postits)
post_its.shuffle()
options = []
for ancor in $postIts.get_children():
ancor.remove_child(ancor.get_child(1))
for i in range(post_its.size()): for i in range(post_its.size()):
options[i].replace_with(post_its[i]) options.append(post_its[i])
$postIts.get_child(i).add_child(options[i], false)
options[i].owner = self options[i].owner = self
func _input(event): func _input(event):
if event.is_action_pressed("ui_end"): if event.is_action_pressed("ui_end"):
scene_finished(1, false) fill_card_slots(3)
selection_state = CARDS
if has_stage and not _input_locked: if has_stage and not _input_locked:
if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_left") or event.is_action_pressed("ui_focus_next"): if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_left") or event.is_action_pressed("ui_focus_next"):
@ -102,6 +113,7 @@ func _input(event):
pick(curr_selection_id) pick(curr_selection_id)
func pick(id: int): func pick(id: int):
print("PICK")
if id == -1: if id == -1:
curr_selection_id = 0 curr_selection_id = 0
return return
@ -115,25 +127,25 @@ func pick(id: int):
var yield_to = anim_players[id].animation_finished var yield_to = anim_players[id].animation_finished
output.append(options[id]) output.append(options[id])
var sibling_id = -1
if selection_state == POSTS:
sibling_id = options.find(options[id].sibling)
print("yeet sibling ", sibling_id)
options.remove_at(id) options.remove_at(id)
anim_players.remove_at(id) anim_players.remove_at(id)
var sibling_id = -1
if selection_state == POSTS_SELECTED:
sibling_id = options.find(output.back().sibling)
options.remove_at(sibling_id)
anim_players[sibling_id].play("unshuffle")
anim_players.remove_at(sibling_id)
print("yeet sibling ", sibling_id)
var winning_id var winning_id
if options[1].text == "" and not id == 1: print(options[1].text)
if !(options[1].text == "" and not id == 1):
randomize() randomize()
winning_id = randi() % options.size() winning_id = randi() % options.size()
print("Winning ID ", id) print("Winning ID ", id)
if winning_id == sibling_id:
winning_id = (winning_id + 1) % options.size()
elif options[0].text == "": elif options[0].text == "":
winning_id = 0 winning_id = 0
else: else:

View File

@ -133,9 +133,6 @@ func _on_pick_button_pressed():
collected = true collected = true
else: else:
emit_signal("open_board") emit_signal("open_board")
func _on_pick_button_released():
hide() hide()