deckhearth/lib/custom-cards-fields.js
Randall Stillwell c0051dd6d5 feat(designer): game targeting and custom game spaces
- game system selector: standalone, existing system (MTG/Pokemon/Lorcana/
  SWU/FaB/One Piece/Sorcery/Grand Archive — codes match catalog imports),
  or a user's custom game
- custom_games table + CRUD API (private per user, unique names)
- /games hub with create form; /games/[id] space with rename, delete,
  card gallery, and ?game= deep-link into the designer
- catalog twin resolves game: system code, custom game name, or 'Custom'
- my-designs shows each design's game association
- migration 1787693311000
2026-08-24 21:01:04 -05:00

32 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),
};
}