Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/card_3d/scenes/card_collection_3d.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=4 format=3 uid="uid://d1uvcisduvvj"]

[ext_resource type="Script" uid="uid://bhsbphug3lcqi" path="res://addons/card_3d/scripts/card_collection_3d.gd" id="1_0ckh6"]
[ext_resource type="Script" uid="uid://bhsbphug3lcqi" path="res://addons/card_3d/scripts/card_collection/card_collection_3d.gd" id="1_0ckh6"]
[ext_resource type="Script" uid="uid://jkfm6q5w8u83" path="res://addons/card_3d/scripts/card_collection/drop_zone_editor_tool.gd" id="2_l4h6k"]
[ext_resource type="Shape3D" uid="uid://cicwtlugivwj4" path="res://addons/card_3d/shapes_3d/default_card_collection_3d_drop_zone_shape_3d.tres" id="2_xh0md"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const _DEFAULT_DROP_ZONE_Z_OFFSET: float = 1.6
set(strategy):
card_layout_strategy = strategy
apply_card_layout()
@export var drag_strategy: DragStrategy = DragStrategy.new():
set(strategy):
drag_strategy = strategy if strategy else DragStrategy.new()
@export var dropzone_collision_shape: Shape3D = null:
Comment thread
tdecker91 marked this conversation as resolved.
set(v):
$DropZone/CollisionShape3D.shape = v if v else _DEFAULT_DROP_ZONE_SHAPE_3D
Expand Down Expand Up @@ -234,19 +237,18 @@ func _on_drop_zone_mouse_exited():
_preview_drop_index = -1
mouse_exit_drop_zone.emit()

# whether or not a card can be selected
func can_select_card(_card) -> bool:
return true

func can_select_card(card: Card3D) -> bool:
return drag_strategy.can_select_card(card, self)


func can_remove_card(_card) -> bool:
return true
func can_remove_card(card: Card3D) -> bool:
return drag_strategy.can_remove_card(card, self)


func can_reorder_card(_card) -> bool:
return true
func can_reorder_card(card: Card3D) -> bool:
return drag_strategy.can_reorder_card(card, self)


# if the card can be inserted to the collection
func can_insert_card(_card, _from_collection) -> bool:
return true
func can_insert_card(card: Card3D, from_collection: CardCollection3D) -> bool:
return drag_strategy.can_insert_card(card, self, from_collection)
41 changes: 41 additions & 0 deletions addons/card_3d/scripts/card_collection/drag_strategy.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class_name DragStrategy
extends Resource
"""
DragStrategy
======================

This module defines an interface that describes how cards can drag from different collections.
It can be configured either by:
1. Setting the drag strategy on your collection to a new DragStrategy resource via the Inspector
(Add Resource → DragStrategy) and configuring the default boolean values.
2. Creating a custom script that extends DragStrategy and overriding the hooks
(can_select_card, can_remove_card, can_reorder_card, can_insert_card)
to implement checks based on the card and collection.
"""


@export_group("Default Behavior")
@export var can_select: bool = true
@export var can_remove: bool = true
@export var can_reorder: bool = true
@export var can_insert: bool = true


func can_select_card(_card, _to_collection: CardCollection3D) -> bool:
return can_select


func can_remove_card(_card, _to_collection: CardCollection3D) -> bool:
return can_remove


func can_reorder_card(_card, _to_collection: CardCollection3D) -> bool:
return can_reorder


func can_insert_card(
_card,
_to_collection: CardCollection3D,
_from_collection: CardCollection3D
) -> bool:
return can_insert
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://drpbrbrd8kfxn
2 changes: 1 addition & 1 deletion example_battle/scenes/battle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func _on_play_zone_card_added(card: BattleCard3D):
card.queue_free()
monster.health -= card.damage
if monster.health <= 0:
$DragController/PlayZone.play_enabled = false
$DragController/PlayZone.drag_strategy.play_enabled = false
Comment thread
tdecker91 marked this conversation as resolved.
monster.queue_free()
16 changes: 12 additions & 4 deletions example_battle/scenes/battle.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://fdx3muhixky4"]
[gd_scene load_steps=11 format=3 uid="uid://fdx3muhixky4"]

[ext_resource type="Script" uid="uid://bwet1jv3qfdxg" path="res://example_battle/scenes/battle.gd" id="1_wmhlq"]
[ext_resource type="PackedScene" uid="uid://d1uvcisduvvj" path="res://addons/card_3d/scenes/card_collection_3d.tscn" id="2_6x4v1"]
Expand All @@ -13,6 +13,16 @@ size = Vector2(50, 50)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_s1erc"]
albedo_color = Color(0.207843, 0.396078, 0.301961, 1)

[sub_resource type="Resource" id="Resource_q3f0o"]
resource_name = "PlayZoneDragStrategy"
script = ExtResource("4_d6qeg")
play_enabled = true
can_select = true
can_remove = false
can_reorder = false
can_insert = true
metadata/_custom_type_script = "uid://blba82h7r8vut"

[sub_resource type="Resource" id="Resource_eexvo"]
script = ExtResource("3_0udwp")
direction = 0
Expand Down Expand Up @@ -43,9 +53,7 @@ card_drag_plane = Plane(0, 0, 1, 4)

[node name="PlayZone" parent="DragController" instance=ExtResource("2_6x4v1")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.309844)
script = ExtResource("4_d6qeg")
play_enabled = true
highlight_on_hover = false
drag_strategy = SubResource("Resource_q3f0o")

[node name="CardCollection3D" parent="DragController" instance=ExtResource("2_6x4v1")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -3.39072, 0)
Expand Down
20 changes: 6 additions & 14 deletions example_battle/scripts/play_card_dropzone.gd
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
class_name PlayCardDropzone
extends CardCollection3D
extends DragStrategy


@export var play_enabled: bool = true


func can_insert_card(_card: BattleCard3D, _from_collection) -> bool:
func can_insert_card(
_card: BattleCard3D,
_to_collection: CardCollection3D,
_from_collection: CardCollection3D
) -> bool:
return play_enabled


func can_reorder_card(_card: BattleCard3D) -> bool:
return false


func can_select_card(_card: BattleCard3D) -> bool:
return false


func can_remove_card(_card: BattleCard3D) -> bool:
return false
11 changes: 11 additions & 0 deletions example_solitaire/resources/card_column_drag_strategy.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[gd_resource type="Resource" script_class="CardColumnDragStrategy" load_steps=2 format=3 uid="uid://cb1c1q85i4ka2"]

[ext_resource type="Script" uid="uid://c4eh7en1au78a" path="res://example_solitaire/scripts/card_column.gd" id="1_auo7v"]

[resource]
script = ExtResource("1_auo7v")
can_select = true
can_remove = true
can_reorder = true
can_insert = true
metadata/_custom_type_script = "uid://c4eh7en1au78a"
11 changes: 11 additions & 0 deletions example_solitaire/resources/suit_discard_drag_strategy.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[gd_resource type="Resource" script_class="SuitDiscard" load_steps=2 format=3 uid="uid://dl7ll3l0opi0a"]

[ext_resource type="Script" uid="uid://crx78y6320odd" path="res://example_solitaire/scripts/suit_discard.gd" id="1_potsm"]

[resource]
script = ExtResource("1_potsm")
can_select = false
can_remove = false
can_reorder = false
can_insert = true
metadata/_custom_type_script = "uid://crx78y6320odd"
3 changes: 0 additions & 3 deletions example_solitaire/scenes/solitaire.gd
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ func _on_drag_controller_card_moved(_card: FaceCard3D, from_collection: CardColl
if from_collection == to_collection:
return

if not from_collection is CardColumn or not to_collection is CardColumn:
return

while from_collection.cards.size() > from_index:
var new_position = from_collection.cards[from_index].global_position
var card = from_collection.remove_card(from_index)
Expand Down
Loading