feat: Implement new pack generation algorithm, enhance card metadata, and add IndexedDB persistence.
This commit is contained in:
@@ -22,3 +22,9 @@
|
||||
- [2025-12-16-221000_lobby_improvements.md](./devlog/2025-12-16-221000_lobby_improvements.md): Plan for kick functionality and exit button relocation.
|
||||
- [Fix Draft UI Layout](./devlog/2025-12-16-215500_fix_draft_ui_layout.md): Completed. Fixed "Waiting for next pack" layout to be consistently full-screen.
|
||||
- [Draft Timer Enforcement](./devlog/2025-12-16-222500_draft_timer.md): Completed. Implemented server-side 60s timer per pick, AFK auto-pick, and global draft timer loop.
|
||||
- [Pack Generation Update](./devlog/2025-12-16-224000_pack_generation_update.md): Completed. Implemented new 15-slot Play Booster algorithm with lands, tokens, and wildcards.
|
||||
- [Card Metadata Enhancement](./devlog/2025-12-16-224500_card_metadata_enhancement.md): Completed. Extended Scryfall fetching and `DraftCard` interfaces to include full metadata (CMC, Oracle Text, etc.).
|
||||
- [Rich Metadata Expansion](./devlog/2025-12-16-223000_enhance_metadata.md): Completed. Further expanded metadata to include legalities, finishes, artist, frame effects, and produced mana.
|
||||
- [Persist Metadata](./devlog/2025-12-16-230000_persist_metadata.md): Completed. Implemented IndexedDB persistence for Scryfall metadata to ensure offline availability and reduce API calls.
|
||||
- [Bulk Parse Feedback](./devlog/2025-12-16-231500_bulk_parse_feedback.md): Completed. Updated `CubeManager` to handle metadata generation properly and provide feedback on missing cards.
|
||||
- [Full Metadata Passthrough](./devlog/2025-12-16-234500_full_metadata_passthrough.md): Completed. `DraftCard` now includes a `definition` property containing the complete, raw Scryfall object for future-proofing and advanced algorithm usage.
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Plan: Enhance Card Metadata
|
||||
|
||||
## Objective
|
||||
Update Scryfall fetching and parsing logic to include comprehensive metadata for cards. This will enable more precise pack generation algorithms in the future (e.g., filtering by legality, format, artist, or specific frame effects).
|
||||
|
||||
## Steps
|
||||
|
||||
1. **Update `ScryfallCard` Interface (`src/client/src/services/ScryfallService.ts`)**
|
||||
* Add fields for `legalities`, `finishes`, `games`, `produced_mana`, `artist`, `released_at`, `frame_effects`, `security_stamp`, `promo_types`.
|
||||
* Define a more robust `ScryfallCardFace` interface.
|
||||
|
||||
2. **Update `DraftCard` Interface (`src/client/src/services/PackGeneratorService.ts`)**
|
||||
* Add corresponding fields to the internal `DraftCard` interface to store this data in the application state.
|
||||
|
||||
3. **Update `PackGeneratorService.processCards`**
|
||||
* Map the new fields from `ScryfallCard` to `DraftCard` during the processing phase.
|
||||
* Ensure `cardFaces` are also mapped correctly if present (useful for Flip cards where we might want front/back info).
|
||||
|
||||
4. **Verification**
|
||||
* Build the project to ensure no type errors.
|
||||
* (Optional) Run a test script or verify in browser if possible, but static analysis should suffice for interface updates.
|
||||
@@ -0,0 +1,30 @@
|
||||
# Pack Generation Algorithm Update
|
||||
|
||||
## Objective
|
||||
Update the pack generation logic to match a new 15-slot "Play Booster" structure.
|
||||
The new structure includes:
|
||||
- **Slots 1-6:** Commons (Color Balanced).
|
||||
- **Slot 7:** Common (87%), List (C/U 10%, R/M 2%), or Special Guest (1%).
|
||||
- **Slots 8-10:** Uncommons (3).
|
||||
- **Slot 11:** Rare (7/8) or Mythic (1/8).
|
||||
- **Slot 12:** Basic Land or Common Dual Land (20% Foil).
|
||||
- **Slot 13:** Wildcard (Non-Foil) - Weighted Rarity.
|
||||
- **Slot 14:** Wildcard (Foil) - Weighted Rarity.
|
||||
- **Slot 15:** Marketing Token / Art Card.
|
||||
|
||||
## Implementation Details
|
||||
1. **Updated `PackGeneratorService.ts`**:
|
||||
- Modified `processedPools` to explicitly categorize `lands` (Basic + Common Dual) and `tokens`.
|
||||
- Updated `processCards` to sort cards into these new pools (instead of filtering them out completely).
|
||||
- Rewrote `buildSinglePack` (for `standard` rarity mode) to implement the 15-slot sequencing.
|
||||
- Implemented logic for:
|
||||
- Color balancing commons (naive attempt).
|
||||
- "The List" simulation (using Wildcard logic from pools).
|
||||
- Slots 13/14 Wildcards with weighted probabilities.
|
||||
- Foil application (cloning card and setting `finish`).
|
||||
- Slot 12 Land selection (preferring separate land pool).
|
||||
- Added interfaces for `typeLine` and `layout` to `DraftCard`.
|
||||
|
||||
## Status
|
||||
- Implemented and Verified via static check (TS linting was fixed).
|
||||
- Ready for testing in the client.
|
||||
@@ -0,0 +1,26 @@
|
||||
# Card Metadata Enhancement
|
||||
|
||||
## Objective
|
||||
Enhance the Scryfall data fetching and internal card representation to include full metadata (CMC, Oracle Text, Power/Toughness, Collector Number, etc.). This allows strictly precise pack generation and potential future features like mana curve analysis or specific slot targeting.
|
||||
|
||||
## Changes
|
||||
1. **Updated `ScryfallService.ts`**:
|
||||
- Extended `ScryfallCard` interface to include:
|
||||
- `cmc` (number)
|
||||
- `mana_cost` (string)
|
||||
- `oracle_text` (string)
|
||||
- `power`, `toughness` (strings)
|
||||
- `collector_number` (string)
|
||||
- `color_identity` (string[])
|
||||
- `keywords` (string[])
|
||||
- `booster` (boolean)
|
||||
- `promo`, `reprint` (booleans)
|
||||
- Verified that `fetch` calls already return this data; TS interface update exposes it.
|
||||
|
||||
2. **Updated `PackGeneratorService.ts`**:
|
||||
- Extended `DraftCard` internal interface to include the same metadata fields (normalized names like `manaCost`, `oracleText`).
|
||||
- Updated `processCards` function to map these fields from the Scryfall response to the `DraftCard` object.
|
||||
|
||||
## Impact
|
||||
- Pack generation now has access to rich metadata.
|
||||
- Future-proofs the system for "The List" exact matching (via collector number or promo types) and game logic (CMC sorting).
|
||||
@@ -0,0 +1,28 @@
|
||||
# Plan: Persist Scryfall Metadata
|
||||
|
||||
## Objective
|
||||
Persist fetched Scryfall card metadata in the browser's IndexedDB. This ensures that:
|
||||
1. Metadata (including the newly added rich fields) is saved across sessions.
|
||||
2. Pack generation can rely on this data without re-fetching.
|
||||
3. The application works better offline or with poor connection after initial fetch.
|
||||
|
||||
## Implementation Steps
|
||||
|
||||
1. **Create `src/client/src/utils/db.ts`**
|
||||
* Implement a lightweight IndexedDB wrapper.
|
||||
* Database Name: `mtg-draft-maker`
|
||||
* Store Name: `cards`
|
||||
* Methods: `putCard`, `getCard`, `getAllCards`, `bulkPut`.
|
||||
|
||||
2. **Update `ScryfallService.ts`**
|
||||
* Import the DB utilities.
|
||||
* In `constructor` or a new `initialize()` method, load all persisted cards into memory (`cacheById` and `cacheByName`).
|
||||
* In `fetchCollection`, `fetchSetCards`, etc., whenever cards are fetched from API, save them to DB via `bulkPut`.
|
||||
* Modify `fetchCollection` to check memory cache (which is now pre-filled from DB) before network.
|
||||
|
||||
3. **Refactor `fetchCollection` deduplication**
|
||||
* Since cache is pre-filled, the existing check `if (this.cacheById.has(...))` will effectively check the persisted data.
|
||||
|
||||
## Verification
|
||||
* Reload page -> Check if cards are loaded immediately without network requests (network tab).
|
||||
* Check Application -> Storage -> IndexedDB in browser devtools (mental check).
|
||||
@@ -0,0 +1,20 @@
|
||||
# Plan: Improve Parse Bulk Feedback
|
||||
|
||||
## Objective
|
||||
Enhance the "Parse Bulk" workflow in `CubeManager` to provide explicit feedback on the result of the Scryfall metadata fetching. This ensures the user knows that "images and metadata" have been successfully generated (fetched) for their list, fulfilling the request for precision.
|
||||
|
||||
## Steps
|
||||
|
||||
1. **Update `CubeManager.tsx`**
|
||||
* In `fetchAndParse` function:
|
||||
* Track `notFoundCount` (identifiers that returned no Scryfall data).
|
||||
* Track `successCount` (identifiers that were successfully enriched).
|
||||
* After the loop, check if `notFoundCount > 0`.
|
||||
* Show a summary notification/alert: "Processed X cards. Y cards could not be identified."
|
||||
* (Optional) If many failures, maybe show a list of names? For now, just the count is a good start.
|
||||
|
||||
2. **Verify Data Integrity**
|
||||
* Ensure that the `processedData` uses the fully enriched `DraftCard` objects (which we know it does from previous steps).
|
||||
|
||||
## Why This Matters
|
||||
The user asked to "Generate image and metadata... upon Parse bulk". While the backend/service logic is done, the UI needs to confirm this action took place to give the user confidence that the underlying algorithm now has the precise data it needs.
|
||||
@@ -0,0 +1,20 @@
|
||||
# Plan: Full Metadata Passthrough
|
||||
|
||||
## Objective
|
||||
Ensure that the `DraftCard` objects used throughout the application (and eventually sent to the backend) contain the **complete** original metadata from Scryfall. The user has explicitly requested access to "all cards informations" for future algorithms.
|
||||
|
||||
## Steps
|
||||
|
||||
1. **Update `ScryfallService.ts`**
|
||||
* Add an index signature `[key: string]: any;` to the `ScryfallCard` interface. This acknowledges that the object contains more fields than strictly typed, preventing TypeScript from complaining when accessing obscure fields, and correctly modeling the API response.
|
||||
|
||||
2. **Update `PackGeneratorService.ts`**
|
||||
* Add `sourceData: ScryfallCard;` (or similar name like `scryfallData`) to the `DraftCard` interface.
|
||||
* In `processCards`, assign the incoming `cardData` (the full Scryfall object) to this new property.
|
||||
|
||||
## Impact
|
||||
* **Data Size**: Payload size for rooms will increase, but this is acceptable (and requested) for the richness of data required.
|
||||
* **Flexibility**: Future updates to pack generation (e.g., checking specific `frame_effects` or `prices`) will not require interface updates; the data will already be there in `card.sourceData`.
|
||||
|
||||
## Verification
|
||||
* The valid "Parse Bulk" operation will now produce `DraftCard`s that, if inspected, contain the full Scryfall JSON.
|
||||
Reference in New Issue
Block a user