refactor(slay-the-spire-like): update deck and inventory types
Refactor the player deck and inventory structures to use more explicit interfaces and improve type safety for combat entities.
This commit is contained in:
parent
2ec0e323c4
commit
f834e15412
|
|
@ -1,5 +1,7 @@
|
|||
import type { PlayerDeck } from "../deck/types";
|
||||
import { Part } from "@/core/part";
|
||||
import { Region } from "@/core/region";
|
||||
import {
|
||||
CardData,
|
||||
EnemyData,
|
||||
IntentData,
|
||||
ItemData,
|
||||
|
|
@ -16,10 +18,20 @@ export type CombatEntity = {
|
|||
isAlive: boolean;
|
||||
};
|
||||
|
||||
export interface IPlayerDeck {
|
||||
cards: Record<string, Part<{ cardData: CardData; itemId: string }>>;
|
||||
regions: {
|
||||
hand: Region;
|
||||
discardPile: Region;
|
||||
drawPile: Region;
|
||||
exhaustPile: Region;
|
||||
};
|
||||
}
|
||||
|
||||
export type PlayerEntity = CombatEntity & {
|
||||
energy: number;
|
||||
maxEnergy: number;
|
||||
deck: PlayerDeck;
|
||||
deck: IPlayerDeck;
|
||||
itemEffects: Record<string, EffectTable>;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { moveToRegion } from "@/core/region";
|
||||
import { createRegion } from "@/core/region";
|
||||
import type { GameItemMeta, GridInventory } from "../grid-inventory/types";
|
||||
import type { CardData } from "../types";
|
||||
import type { DeckRegions, GameCard, PlayerDeck } from "./types";
|
||||
import type { DeckRegions, GameCard, IInventory, PlayerDeck } from "./types";
|
||||
|
||||
function generateCardId(itemId: string, cellIndex: number): string {
|
||||
return `card-${itemId}-${cellIndex}`;
|
||||
|
|
@ -31,9 +30,7 @@ function createDeckRegions(): DeckRegions {
|
|||
};
|
||||
}
|
||||
|
||||
function generateDeckFromInventory(
|
||||
inventory: GridInventory<GameItemMeta>,
|
||||
): PlayerDeck {
|
||||
function generateDeckFromInventory(inventory: IInventory): PlayerDeck {
|
||||
const cards: Record<string, GameCard> = {};
|
||||
const regions = createDeckRegions();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,26 @@
|
|||
import type { Part } from '@/core/part';
|
||||
import {CardData} from "@/samples/slay-the-spire-like/system/types";
|
||||
import {Region} from "@/core/region";
|
||||
import type { Part } from "@/core/part";
|
||||
import { CardData, ItemData } from "@/samples/slay-the-spire-like/system/types";
|
||||
import { Region } from "@/core/region";
|
||||
import { ParsedShape } from "../utils/parse-shape";
|
||||
|
||||
/**
|
||||
* Metadata for a game card.
|
||||
* Bridges inventory item data with the card system.
|
||||
*/
|
||||
export interface GameCardMeta {
|
||||
cardData: CardData;
|
||||
itemId: string;
|
||||
cardData: CardData;
|
||||
itemId: string;
|
||||
}
|
||||
|
||||
export interface IInventory {
|
||||
items: Map<
|
||||
string,
|
||||
{
|
||||
id: string;
|
||||
meta?: { itemData: ItemData };
|
||||
shape: ParsedShape;
|
||||
}
|
||||
>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -21,19 +33,19 @@ export type GameCard = Part<GameCardMeta>;
|
|||
* Player deck structure containing card pools.
|
||||
*/
|
||||
export interface PlayerDeck {
|
||||
/** All cards indexed by ID */
|
||||
cards: Record<string, GameCard>;
|
||||
/** All cards indexed by ID */
|
||||
cards: Record<string, GameCard>;
|
||||
|
||||
regions: DeckRegions;
|
||||
regions: DeckRegions;
|
||||
}
|
||||
|
||||
export interface DeckRegions{
|
||||
/** Card IDs in the draw pile */
|
||||
drawPile: Region;
|
||||
/** Card IDs in the player's hand */
|
||||
hand: Region;
|
||||
/** Card IDs in the discard pile */
|
||||
discardPile: Region;
|
||||
/** Card IDs in the exhaust pile (removed from combat) */
|
||||
exhaustPile: Region;
|
||||
export interface DeckRegions {
|
||||
/** Card IDs in the draw pile */
|
||||
drawPile: Region;
|
||||
/** Card IDs in the player's hand */
|
||||
hand: Region;
|
||||
/** Card IDs in the discard pile */
|
||||
discardPile: Region;
|
||||
/** Card IDs in the exhaust pile (removed from combat) */
|
||||
exhaustPile: Region;
|
||||
}
|
||||
Loading…
Reference in New Issue