fix/func: added beginnings of turn winning function. Fixed "Card_Container"s not appearing & dissapearing properly
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Hyunjoon Park
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,35 @@
|
||||
# Card Framework
|
||||
|
||||
Professional Godot 4.x addon for creating 2D card games.
|
||||
|
||||
## Overview
|
||||
|
||||
Build Solitaire, TCG, or deck-building roguelikes with:
|
||||
- **Drag & Drop System** - Built-in card interactions
|
||||
- **Flexible Containers** - Pile (stacks) and Hand (fans)
|
||||
- **JSON Card Data** - Metadata-driven card creation
|
||||
- **Extensible Design** - Factory patterns and inheritance
|
||||
|
||||
## Quick Start
|
||||
|
||||
1. Add `CardManager` node to your scene
|
||||
2. Configure `JsonCardFactory` with asset directories
|
||||
3. Create JSON card definitions
|
||||
4. Add `Pile` or `Hand` container nodes
|
||||
|
||||
## Documentation & Examples
|
||||
|
||||
**Full Documentation:** https://github.com/chun92/card-framework
|
||||
|
||||
**Download Examples:** https://github.com/chun92/card-framework/releases/latest
|
||||
- Look for `card-framework-vX.X.X-full.zip`
|
||||
- Includes complete example projects (basic demo + FreeCell game)
|
||||
- Full API reference and tutorials included
|
||||
|
||||
## Version
|
||||
|
||||
1.3.2 - Godot 4.6+ compatible
|
||||
|
||||
## License
|
||||
|
||||
MIT License - Copyright (c) 2025 Hyunjoon Park
|
||||
@@ -29,7 +29,7 @@ extends Control
|
||||
|
||||
# Static counter for unique container identification
|
||||
static var next_id: int = 0
|
||||
|
||||
signal played
|
||||
|
||||
@export_group("drop_zone")
|
||||
## Enables or disables the drop zone functionality.
|
||||
@@ -98,6 +98,20 @@ func _ready() -> void:
|
||||
else:
|
||||
drop_zone.sensor_outline.visible = false
|
||||
|
||||
func _redraw_drop_zone():
|
||||
if enable_drop_zone:
|
||||
drop_zone = drop_zone_scene.instantiate()
|
||||
add_child(drop_zone)
|
||||
drop_zone.init(self, [CardManager.CARD_ACCEPT_TYPE])
|
||||
# If sensor_size is not set, they will follow the card size.
|
||||
if sensor_size == Vector2(0, 0):
|
||||
sensor_size = card_manager.card_size
|
||||
drop_zone.set_sensor(sensor_size, sensor_position, sensor_texture, sensor_visibility)
|
||||
if debug_mode:
|
||||
drop_zone.sensor_outline.visible = true
|
||||
else:
|
||||
drop_zone.sensor_outline.visible = false
|
||||
drop_zone.redraw_sensor()
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if card_manager != null:
|
||||
@@ -286,7 +300,7 @@ func get_string() -> String:
|
||||
|
||||
|
||||
func on_card_move_done(_card: Card):
|
||||
pass
|
||||
played.emit()
|
||||
|
||||
|
||||
func on_card_pressed(_card: Card):
|
||||
|
||||
@@ -115,6 +115,30 @@ func init(_parent: Node, accept_types: Array =[]):
|
||||
vertical_partition = []
|
||||
horizontal_partition = []
|
||||
|
||||
func redraw_sensor():
|
||||
# Create invisible sensor for hit detection
|
||||
if sensor == null:
|
||||
sensor = TextureRect.new()
|
||||
sensor.name = "Sensor"
|
||||
sensor.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
sensor.z_index = CardFrameworkSettings.VISUAL_SENSOR_Z_INDEX # Behind everything else
|
||||
add_child(sensor)
|
||||
|
||||
# Create debugging outline (initially hidden)
|
||||
if sensor_outline == null:
|
||||
sensor_outline = ReferenceRect.new()
|
||||
sensor_outline.editor_only = false
|
||||
sensor_outline.name = "SensorOutline"
|
||||
sensor_outline.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
sensor_outline.border_color = CardFrameworkSettings.DEBUG_OUTLINE_COLOR
|
||||
sensor_outline.z_index = CardFrameworkSettings.VISUAL_OUTLINE_Z_INDEX
|
||||
add_child(sensor_outline)
|
||||
|
||||
# Initialize default values
|
||||
stored_sensor_size = Vector2(0, 0)
|
||||
stored_sensor_position = Vector2(0, 0)
|
||||
vertical_partition = []
|
||||
horizontal_partition = []
|
||||
|
||||
## Checks if the mouse cursor is currently within the drop zone sensor area.
|
||||
## @returns: True if mouse is inside the sensor bounds
|
||||
|
||||
@@ -72,6 +72,8 @@ func get_top_cards(n: int) -> Array:
|
||||
|
||||
return result
|
||||
|
||||
#func _process(delta: float) -> void:
|
||||
#play_check()
|
||||
|
||||
## Updates z-index values for all cards to maintain proper layering.
|
||||
## Pressed cards receive elevated z-index to appear above the pile.
|
||||
|
||||
+2
-1
@@ -34,7 +34,8 @@ version_control/autoload_on_startup=true
|
||||
|
||||
folder_colors={
|
||||
"res://cards/": "green",
|
||||
"res://scenes/": "red"
|
||||
"res://scenes/": "red",
|
||||
"res://scripts/": "purple"
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
extends Pile
|
||||
|
||||
signal played
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
func play_check():
|
||||
print("waiting")
|
||||
enable_drop_zone = true
|
||||
while true:
|
||||
if get_top_cards(1) != null:
|
||||
played.emit()
|
||||
break
|
||||
@@ -1 +0,0 @@
|
||||
uid://be2xbeq4mjtyi
|
||||
@@ -7,7 +7,6 @@
|
||||
[ext_resource type="Curve" uid="uid://bpxa7v4vk7pod" path="res://resources/Hand_Curve.tres" id="5_kdjyk"]
|
||||
[ext_resource type="Curve" uid="uid://c2d322obqbcgc" path="res://resources/Hand_Curve_Vert.tres" id="6_ikr1a"]
|
||||
[ext_resource type="Script" uid="uid://6ams8uvg43gu" path="res://addons/card-framework/pile.gd" id="7_rwigh"]
|
||||
[ext_resource type="Script" uid="uid://be2xbeq4mjtyi" path="res://scenes/player_1_play_pile.gd" id="8_el68r"]
|
||||
[ext_resource type="Texture2D" uid="uid://jxi7my6yp71x" path="res://icon.svg" id="8_waqni"]
|
||||
[ext_resource type="Texture2D" uid="uid://besq7oa4a37mb" path="res://icon_red_background.webp" id="9_ggwjq"]
|
||||
[ext_resource type="Curve" uid="uid://ddxsxuabgpk7w" path="res://resources/Hand_Curve_invert.tres" id="10_kdjyk"]
|
||||
@@ -65,17 +64,14 @@ hand_rotation_curve = ExtResource("5_kdjyk")
|
||||
hand_vertical_curve = ExtResource("6_ikr1a")
|
||||
metadata/_custom_type_script = "uid://dj46jo3lfbclo"
|
||||
|
||||
[node name="Player1PlayPile" type="Control" parent="CardManager" unique_id=1899485437]
|
||||
[node name="Player1PlayPile" type="Control" parent="CardManager" unique_id=2062119966]
|
||||
anchors_preset = 0
|
||||
offset_left = 790.0
|
||||
offset_top = 560.0
|
||||
offset_right = 790.0
|
||||
offset_bottom = 560.0
|
||||
script = ExtResource("8_el68r")
|
||||
stack_display_gap = 1
|
||||
max_stack_display = 1
|
||||
sensor_texture = ExtResource("8_waqni")
|
||||
sensor_visibility = true
|
||||
script = ExtResource("7_rwigh")
|
||||
sensor_texture = ExtResource("9_ggwjq")
|
||||
metadata/_custom_type_script = "uid://6ams8uvg43gu"
|
||||
|
||||
[node name="Team1Stiche" type="Control" parent="CardManager" unique_id=740577652]
|
||||
@@ -109,9 +105,7 @@ offset_top = 560.0
|
||||
offset_right = 980.0
|
||||
offset_bottom = 560.0
|
||||
script = ExtResource("7_rwigh")
|
||||
enable_drop_zone = false
|
||||
sensor_texture = SubResource("CanvasTexture_kdjyk")
|
||||
sensor_visibility = true
|
||||
metadata/_custom_type_script = "uid://6ams8uvg43gu"
|
||||
|
||||
[node name="Team2Stiche" type="Control" parent="CardManager" unique_id=561191290]
|
||||
|
||||
+122
-2
@@ -18,6 +18,8 @@ signal dealt
|
||||
|
||||
func _ready():
|
||||
trumpbuttons.trump.connect(define_trump.bind())
|
||||
player_1_pile.enable_drop_zone = false
|
||||
player_1_pile.sensor_visibility = false
|
||||
setup_game()
|
||||
|
||||
|
||||
@@ -31,7 +33,7 @@ func setup_game():
|
||||
deck._held_cards.shuffle()
|
||||
|
||||
# Deal initial hand
|
||||
const DEAL_PAUSE = 0.45
|
||||
const DEAL_PAUSE = 0.1
|
||||
var deal_r: int =1
|
||||
while true:
|
||||
deal_cards_to_hand(3, player_1_hand)
|
||||
@@ -55,9 +57,127 @@ func define_trump(suit : String):
|
||||
turn(first_player)
|
||||
|
||||
func turn(first):
|
||||
first.play_check()
|
||||
first.sensor_visibility = true
|
||||
first.enable_drop_zone = true
|
||||
first._redraw_drop_zone()
|
||||
await first.played
|
||||
first.enable_drop_zone = false
|
||||
first._redraw_drop_zone()
|
||||
match first:
|
||||
player_1_pile:
|
||||
|
||||
player_2_pile.sensor_visibility = true
|
||||
player_2_pile.enable_drop_zone = true
|
||||
player_2_pile._redraw_drop_zone()
|
||||
await player_2_pile.played
|
||||
player_2_pile.enable_drop_zone = false
|
||||
player_2_pile._redraw_drop_zone()
|
||||
|
||||
player_3_pile.sensor_visibility = true
|
||||
player_3_pile.enable_drop_zone = true
|
||||
player_3_pile._redraw_drop_zone()
|
||||
await player_3_pile.played
|
||||
player_3_pile.enable_drop_zone = false
|
||||
player_3_pile._redraw_drop_zone()
|
||||
|
||||
player_4_pile.sensor_visibility = true
|
||||
player_4_pile.enable_drop_zone = true
|
||||
player_4_pile._redraw_drop_zone()
|
||||
await player_4_pile.played
|
||||
player_4_pile.enable_drop_zone = false
|
||||
player_4_pile._redraw_drop_zone()
|
||||
|
||||
player_2_pile:
|
||||
|
||||
player_3_pile.sensor_visibility = true
|
||||
player_3_pile.enable_drop_zone = true
|
||||
player_3_pile._redraw_drop_zone()
|
||||
await player_3_pile.played
|
||||
player_3_pile.enable_drop_zone = false
|
||||
player_3_pile._redraw_drop_zone()
|
||||
|
||||
player_4_pile.sensor_visibility = true
|
||||
player_4_pile.enable_drop_zone = true
|
||||
player_4_pile._redraw_drop_zone()
|
||||
await player_4_pile.played
|
||||
player_4_pile.enable_drop_zone = false
|
||||
player_4_pile._redraw_drop_zone()
|
||||
|
||||
player_1_pile.sensor_visibility = true
|
||||
player_1_pile.enable_drop_zone = true
|
||||
player_1_pile._redraw_drop_zone()
|
||||
await player_1_pile.played
|
||||
player_1_pile.enable_drop_zone = false
|
||||
player_1_pile._redraw_drop_zone()
|
||||
|
||||
player_3_pile:
|
||||
|
||||
player_4_pile.sensor_visibility = true
|
||||
player_4_pile.enable_drop_zone = true
|
||||
player_4_pile._redraw_drop_zone()
|
||||
await player_4_pile.played
|
||||
player_4_pile.enable_drop_zone = false
|
||||
player_4_pile._redraw_drop_zone()
|
||||
|
||||
player_1_pile.sensor_visibility = true
|
||||
player_1_pile.enable_drop_zone = true
|
||||
player_1_pile._redraw_drop_zone()
|
||||
await player_1_pile.played
|
||||
player_1_pile.enable_drop_zone = false
|
||||
player_1_pile._redraw_drop_zone()
|
||||
|
||||
player_2_pile.sensor_visibility = true
|
||||
player_2_pile.enable_drop_zone = true
|
||||
player_2_pile._redraw_drop_zone()
|
||||
await player_2_pile.played
|
||||
player_2_pile.enable_drop_zone = false
|
||||
player_2_pile._redraw_drop_zone()
|
||||
|
||||
player_4_pile:
|
||||
player_1_pile.sensor_visibility = true
|
||||
player_1_pile.enable_drop_zone = true
|
||||
player_1_pile._redraw_drop_zone()
|
||||
await player_1_pile.played
|
||||
player_1_pile.enable_drop_zone = false
|
||||
player_1_pile._redraw_drop_zone()
|
||||
|
||||
player_2_pile.sensor_visibility = true
|
||||
player_2_pile.enable_drop_zone = true
|
||||
player_2_pile._redraw_drop_zone()
|
||||
await player_2_pile.played
|
||||
player_2_pile.enable_drop_zone = false
|
||||
player_2_pile._redraw_drop_zone()
|
||||
|
||||
player_3_pile.sensor_visibility = true
|
||||
player_3_pile.enable_drop_zone = true
|
||||
player_3_pile._redraw_drop_zone()
|
||||
await player_3_pile.played
|
||||
player_3_pile.enable_drop_zone = false
|
||||
player_3_pile._redraw_drop_zone()
|
||||
get_turn_winner()
|
||||
|
||||
|
||||
|
||||
|
||||
func get_turn_winner():
|
||||
var card_1 = player_1_pile.get_top_cards(1)[0]
|
||||
var card_2 = player_2_pile.get_top_cards(1)[0]
|
||||
var card_3 = player_3_pile.get_top_cards(1)[0]
|
||||
var card_4 = player_4_pile.get_top_cards(1)[0]
|
||||
var value_1 = card_1.card_info.value
|
||||
var value_2 = card_2.card_info.value
|
||||
var value_3 = card_3.card_info.value
|
||||
var value_4 = card_4.card_info.value
|
||||
|
||||
if trump == card_1.card_info.suit:
|
||||
match value_1:
|
||||
11:
|
||||
value_1 += 40
|
||||
9:
|
||||
value_1 += 30
|
||||
|
||||
func move_to_stiche(team: int):
|
||||
pass
|
||||
|
||||
func create_standard_deck():
|
||||
var suits = ["Club", "Diamond", "Heart", "Spade"]
|
||||
|
||||
Reference in New Issue
Block a user