feat: shape for cards

This commit is contained in:
hyper
2026-03-14 15:48:55 +08:00
parent 984b8aa1c8
commit 107e6fd6a2
7 changed files with 142 additions and 31 deletions
+11 -1
View File
@@ -2,7 +2,7 @@
import { calculateDimensions } from './dimensions';
import { loadCSV, CSV } from '../../utils/csv-loader';
import { initLayerConfigs, formatLayers, initLayerConfigsForSide } from './layer-parser';
import type { CardData, LayerConfig, Dimensions, CardSide } from '../types';
import type { CardData, LayerConfig, Dimensions, CardSide, CardShape } from '../types';
/**
* 默认配置常量
@@ -24,6 +24,7 @@ export interface DeckState {
gridH: number;
bleed: number;
padding: number;
shape: CardShape;
fixed: boolean;
src: string;
rawSrc: string; // 原始 CSV 路径(用于生成代码时保持相对路径)
@@ -75,6 +76,7 @@ export interface DeckActions {
setGridH: (grid: number) => void;
setBleed: (bleed: number) => void;
setPadding: (padding: number) => void;
setShape: (shape: CardShape) => void;
// 数据设置
setCards: (cards: CSV<CardData>) => void;
@@ -144,6 +146,7 @@ export function createDeckStore(
gridH: DECK_DEFAULTS.GRID_H,
bleed: DECK_DEFAULTS.BLEED,
padding: DECK_DEFAULTS.PADDING,
shape: 'rectangle',
fixed: false,
src: initialSrc,
rawSrc: initialSrc,
@@ -206,6 +209,9 @@ export function createDeckStore(
setState({ padding });
updateDimensions();
};
const setShape = (shape: CardShape) => {
setState({ shape });
};
const setCards = (cards: CSV<CardData>) => setState({ cards, activeTab: 0 });
const setActiveTab = (index: number) => setState({ activeTab: index });
@@ -313,6 +319,9 @@ export function createDeckStore(
if (state.padding !== DECK_DEFAULTS.PADDING) {
parts.push(`padding="${state.padding}" `);
}
if (state.shape !== 'rectangle') {
parts.push(`shape="${state.shape}" `);
}
parts.push(`layers="${frontLayersStr}" `);
if (backLayersString) {
@@ -368,6 +377,7 @@ export function createDeckStore(
setGridH,
setBleed,
setPadding,
setShape,
setCards,
setActiveTab,
updateCardData,