# card-framework
**Repository Path**: lihuiZhang/card-framework
## Basic Information
- **Project Name**: card-framework
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-04-26
- **Last Updated**: 2025-04-26
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Card Framework
**Card Framework** is a lightweight, extensible toolkit for **creating 2D card games** in the **Godot Engine**. Whether you're building a **classic Solitaire**, a **TCG (Trading Card Game)**, or a **deck-building roguelike**, the Card Framework provides flexible card handling and UI structures to speed up development. Use this framework as a **starting point** for card-based gameplay in any 2D project.


## Features
* **Card Creation & Management**: Easily define and instantiate cards with custom attributes or visuals.
* **Drag-and-Drop Interactions**: Built-in 2D control nodes to handle common card movements.
* **Card Container**: Create and manage various modules like Piles or Hands, enabling flexible card organization in different game scenarios.
* **Scalable Architecture**: Extend or modify the base classes to suit various genres (Solitaire, TCG, etc.).
* **Lightweight & Modular**: Include only the parts you need, so it won't bloat your project.
## Table of Contents
- [Installation](#installation)
- [Getting Started](#getting-started)
- [Classes](#classes)
- [CardManager](#cardmanager)
- [Properties](#properties)
- [Methods](#methods)
- [Card](#card)
- [Properties](#properties-1)
- [Methods](#methods-1)
- [CardFactory](#cardfactory)
- [Properties](#properties-2)
- [Methods](#methods-2)
- [CardContainer](#cardcontainer)
- [Properties](#properties-3)
- [Methods](#methods-3)
- [Pile](#pile)
- [Properties](#properties-4)
- [Methods](#methods-4)
- [Hand](#hand)
- [Properties](#properties-5)
- [Methods](#methods-5)
- [Creating Card Info JSON Files](#creating-card-info-json-files)
- [Example](#example)
- [Sample Projects](#sample-projects)
- [Example1](#example1)
- [Freecell](#freecell)
- [Contributing](#contributing)
- [License / Credits](#license--credits)
- [Kenney.nl Card Assets](#kenneynl-card-assets)
- [ChatGPT-Generated Spot Images](#chatgpt-generated-spot-images)
- [Thanks To](#thanks-to)
- [Changelog](#changelog)
- [1.0.0 (2025-01-03)](#100-2025-01-03)
## Installation
1. **Download from Godot Editor’s AssetLib**
* Open Godot and navigate to the **AssetLib** tab.
* Search for **Card Framework** and download the latest version.
2. **Manual Download to** `addons/card-framework`
* Alternatively, download the latest version directly.
* Copy or move the contents to your project under `res://addons/card-framework`.
3. **Check Usage Examples**
* The folders `example1` and `freecell` demonstrate usage in real scenarios.
* If you don’t need them, you can remove those folders from your project.
## Getting Started
1. **Instantiate the Card Manager**
* In any scene that needs card functionality, **instantiate** the scene at `card-framework/card_manager.tscn`.
2. **Organize Card Images**
* Save the images for your card fronts (and other card-related art) inside the designated `card_asset_dir` folder.
3. **Prepare Card Metadata**
* Create JSON files that describe each card’s metadata (e.g., name, rank, suit, custom properties), and place them into the `card_info_dir` folder. [See example](#creating-card-info-json-files)
4. **Set Up the CardManager**
* In the **Inspector** for your `CardManager` node, configure:
* `card_size`: The default width/height for each card.
* `card_asset_dir`: The folder containing your card images.
* `card_info_dir`: The folder containing your JSON metadata.
* `back_image`: The texture to use for the card’s backside.
5. **Assign a CardFactory**
* Under the `CardManager`, choose the `CardFactory` class to use.
* You can use the default `CardFactory` or **create a custom factory** (by extending `CardFactory`) and set it here.
6. **Add Card Containers**
* Within `CardManager`, instantiate and arrange `Pile`, `Hand`, or any custom `CardContainer` nodes you’ve created.
* Use these containers to organize the deck, discard piles, player hands, or any other card layout required by your game.
## Classes
### CardManager
The **Root Node** for the Card Framework.
* Oversees all card-related nodes, manages card factories, and coordinates card creation, movement, and container relationships.
#### Properties
| Type | Name | Default | Description |
| ------------ | ------------------ | ------------- | ----------------------------------------------------------- |
| **Vector2** | `card_size` | (150, 210) | The default size (width × height) for each card. |
| **String** | `card_asset_dir` | *null* | Directory containing the card image assets. **(Required)** |
| **String** | `card_info_dir` | *null* | Directory containing JSON files for card information. **(Required)** |
| **Texture2D**| `back_image` | *null* | The texture used for the backside of all cards. **(Required)** |
| **PackedScene** | `card_factory_scene` | *null* | The scene responsible for spawning new card objects. **(Required)** |
#### Methods
| Method Signature | Description |
| ----------------------- | -------------------------------------------------- |
| **func undo() -> void** | Reverts the last recorded move in the history. |
| **func reset_history() -> void** | Clears all move records from the history. |
[⬆ Back to Top](#cardmanager)
---
### Card
A **Node** representing a single playing card.
* Stores information about name, card image, or custom data.
#### Properties
| Type | Name | Default | Description |
| ------------- | ---------------------- | ------------- | --------------------------------------------------------------------------------------------------- |
| **String** | `card_name` | *null* | The name of the card. |
| **Vector2** | `card_size` | (150, 210) | The width/height of the card. |
| **Texture2D** | `front_image` | *null* | The texture used for the card’s front face. |
| **Texture2D** | `back_image` | *null* | The texture used for the card’s back face. |
| **bool** | `show_front` | true | Determines whether the front face is shown (`true`) or the back face (`false`). |
| **int** | `moving_speed` | 2000 | The speed at which the card moves during animations or transitions. |
| **bool** | `can_be_interacted_with` | true | Whether the card can be interacted with (e.g., clicked, dragged). |
| **int** | `hover_distance` | 10 | How many pixels the card **hovers** above its position when interacted with (e.g., picking up a card).|
#### Methods
| Method Signature | Description |
| ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| **func set_faces(front_face: Texture2D, back_face: Texture2D) -> void** | Sets the card’s front and back textures (`front_face_texture` and `back_face_texture`). |
| **func return_card() -> void** | Return card to stored `destination`. |
| **func move(target_destination: Vector2, degree: float) -> void** | Moves the card to `target_destination` at a given rotation angle (`degree`). |
| **func start_hovering() -> void** | Initiates a **hover** effect (raising the card visually). |
| **func end_hovering(restore_card_position: bool) -> void** | Ends the **hover** effect. |
| **func set_holding() -> void** | Marks the card as **holding**. |
| **func set_releasing() -> void** | Unmarks the card as **holding**. |
| **func get_string() -> String** | Returns `card_name` as a string representation of the card. |
[⬆ Back to Top](#card)
---
### CardFactory
A **Class** responsible for creating cards.
* Instanced by the `CardManager` to spawn `Card` nodes.
#### Properties
| Type | Name | Default | Description |
| ------------ | ------------------- | ------- | -------------------------------------- |
| **PackedScene** | `default_card_scene` | *null* | A base card scene to instantiate. **(Required)** |
#### Methods
| Method Signature | Description |
| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **func create_card(card_name: String, target: CardContainer) -> Card** | Creates a new `Card` under the specified `CardContainer`.