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 {
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>;
};

View File

@ -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();

View File

@ -1,6 +1,7 @@
import type { Part } from '@/core/part';
import {CardData} from "@/samples/slay-the-spire-like/system/types";
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.
@ -11,6 +12,17 @@ export interface GameCardMeta {
itemId: string;
}
export interface IInventory {
items: Map<
string,
{
id: string;
meta?: { itemData: ItemData };
shape: ParsedShape;
}
>;
}
/**
* A card instance in the game.
* Cards are generated from inventory items or created as status effects.