-
Notifications
You must be signed in to change notification settings - Fork 18
add drag strategy #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dd0c7a6
added drag strategy and start refactoring examples to use it
tdecker91 b58a275
finish fixing solitaire example to use drag strategy
tdecker91 7df4f14
fix lint
tdecker91 03d42f0
polish up by adding type annotations, fixing typos, and refactoring c…
tdecker91 f1711b1
clean up mixed tabs/spaces
tdecker91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| uid://drpbrbrd8kfxn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
11
example_solitaire/resources/card_column_drag_strategy.tres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
11
example_solitaire/resources/suit_discard_drag_strategy.tres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.