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:
hypercross 2026-04-21 20:15:06 +08:00
parent 2ec0e323c4
commit f834e15412
3 changed files with 47 additions and 26 deletions

View File

@ -1,5 +1,7 @@
import type { PlayerDeck } from "../deck/types"; import { Part } from "@/core/part";
import { Region } from "@/core/region";
import { import {
CardData,
EnemyData, EnemyData,
IntentData, IntentData,
ItemData, ItemData,
@ -16,10 +18,20 @@ export type CombatEntity = {
isAlive: boolean; 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 & { export type PlayerEntity = CombatEntity & {
energy: number; energy: number;
maxEnergy: number; maxEnergy: number;
deck: PlayerDeck; deck: IPlayerDeck;
itemEffects: Record<string, EffectTable>; itemEffects: Record<string, EffectTable>;
}; };

View File

@ -1,8 +1,7 @@
import { moveToRegion } from "@/core/region"; import { moveToRegion } from "@/core/region";
import { createRegion } from "@/core/region"; import { createRegion } from "@/core/region";
import type { GameItemMeta, GridInventory } from "../grid-inventory/types";
import type { CardData } from "../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 { function generateCardId(itemId: string, cellIndex: number): string {
return `card-${itemId}-${cellIndex}`; return `card-${itemId}-${cellIndex}`;
@ -31,9 +30,7 @@ function createDeckRegions(): DeckRegions {
}; };
} }
function generateDeckFromInventory( function generateDeckFromInventory(inventory: IInventory): PlayerDeck {
inventory: GridInventory<GameItemMeta>,
): PlayerDeck {
const cards: Record<string, GameCard> = {}; const cards: Record<string, GameCard> = {};
const regions = createDeckRegions(); const regions = createDeckRegions();

View File

@ -1,14 +1,26 @@
import type { Part } from '@/core/part'; import type { Part } from "@/core/part";
import {CardData} from "@/samples/slay-the-spire-like/system/types"; import { CardData, ItemData } from "@/samples/slay-the-spire-like/system/types";
import {Region} from "@/core/region"; import { Region } from "@/core/region";
import { ParsedShape } from "../utils/parse-shape";
/** /**
* Metadata for a game card. * Metadata for a game card.
* Bridges inventory item data with the card system. * Bridges inventory item data with the card system.
*/ */
export interface GameCardMeta { export interface GameCardMeta {
cardData: CardData; cardData: CardData;
itemId: string; 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. * Player deck structure containing card pools.
*/ */
export interface PlayerDeck { export interface PlayerDeck {
/** All cards indexed by ID */ /** All cards indexed by ID */
cards: Record<string, GameCard>; cards: Record<string, GameCard>;
regions: DeckRegions; regions: DeckRegions;
} }
export interface DeckRegions{ export interface DeckRegions {
/** Card IDs in the draw pile */ /** Card IDs in the draw pile */
drawPile: Region; drawPile: Region;
/** Card IDs in the player's hand */ /** Card IDs in the player's hand */
hand: Region; hand: Region;
/** Card IDs in the discard pile */ /** Card IDs in the discard pile */
discardPile: Region; discardPile: Region;
/** Card IDs in the exhaust pile (removed from combat) */ /** Card IDs in the exhaust pile (removed from combat) */
exhaustPile: Region; exhaustPile: Region;
} }