deckhearth/lib/custom-cards-fields.js
Randall Stillwell fe1695f7ad feat(designer): custom frame editor and cost symbols
- custom_frames: per-user frames with full 9-slot palette (JSONB),
  unique names; designer frame picker lists them alongside starters,
  click to use, edit/delete via inline editor with live preview
- custom_symbols: upload cost icons (PNG/WebP/SVG, 2MB) keyed by short
  code; re-uploading a code replaces the old icon; ManaPips renders
  icon pips for {CODE} tokens with graceful text fallback
- custom_cards.custom_frame_id links designs to custom frames; API GETs
  join and nest the palette; deleting a frame falls back to starter
- migration 1787700511000
2026-08-24 21:13:12 -05:00

33 lines
1.2 KiB
JavaScript

/**
* Shared field normalization for custom card designs.
* Single source of truth so the create and update routes never drift.
*/
export function pickDesignFields(body = {}) {
const str = (v) => (typeof v === 'string' ? v.trim() : null);
const int = (v) => {
const n = parseInt(v, 10);
return Number.isInteger(n) ? n : null;
};
const artMode = str(body.art_mode) || str(body.artMode) || 'framed';
const gameTarget = str(body.game_target) || str(body.gameTarget) || 'custom';
return {
name: str(body.name),
manaCost: str(body.mana_cost) || str(body.manaCost),
cardType: str(body.card_type) || str(body.cardType),
rarity: str(body.rarity),
rulesText: str(body.rules_text) || str(body.description),
actions: str(body.actions),
flavorQuote: str(body.flavor_quote) || str(body.flavorQuote),
power: str(body.power),
toughness: str(body.toughness),
frameId: str(body.frame_id) || str(body.frameId) || 'classic',
artworkUrl: str(body.artwork_url) || str(body.artworkUrl),
artMode: artMode === 'fullart' ? 'fullart' : 'framed',
gameTarget,
customGameId: int(body.custom_game_id) || int(body.customGameId),
customFrameId: int(body.custom_frame_id) || int(body.customFrameId),
};
}