Split card design into front+back, add sound effects & background music
Card design: - Separate cardFront + cardBack (each own/equip independently) - Fronts: classic (free), ivory/rosegold (buy), parchment/mint (earned) - Backs: classic (free), sapphire/emerald (buy), ruby/royal (earned) - PlayingCard `front` prop; table applies front to all faces, back to opponents - Profile has front + back pickers; shop has both sections Audio: - Web Audio synth engine (no asset files): SFX for card/deal/trump/trick, win/lose, message, notify, award, levelup, purchase, kot + ambient music - Toggles in profile (Audio) + mute button in game HUD; prefs persisted - Wired across game-store, rewards, daily, shop, chat Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
import {
|
||||
AchievementDef,
|
||||
AchievementUnlock,
|
||||
CardStyleDef,
|
||||
CardBackDef,
|
||||
CardFrontDef,
|
||||
LeagueInfo,
|
||||
MatchSummary,
|
||||
PlayerStats,
|
||||
@@ -218,16 +219,51 @@ export function titleUnlocked(
|
||||
|
||||
/* ---------------------------- Card styles ---------------------------- */
|
||||
|
||||
export const CARD_STYLES: CardStyleDef[] = [
|
||||
{ id: "classic", nameFa: "کلاسیک", nameEn: "Classic", c1: "#14274f", c2: "#0a142e", accent: "#d4af37", price: 0 },
|
||||
// Card BACKS (pattern on the reverse of every card).
|
||||
export const CARD_BACKS: CardBackDef[] = [
|
||||
{ id: "classic", nameFa: "کلاسیک", nameEn: "Classic", c1: "#14274f", c2: "#0a142e", accent: "#d4af37", price: 0, default: true },
|
||||
{ id: "sapphire", nameFa: "یاقوت کبود", nameEn: "Sapphire", c1: "#0b3a82", c2: "#06173a", accent: "#6aa6ff", price: 800 },
|
||||
{ id: "ruby", nameFa: "یاقوت", nameEn: "Ruby", c1: "#7f1d2e", c2: "#2b0a12", accent: "#ff7a90", price: 800 },
|
||||
{ id: "emerald", nameFa: "زمرد", nameEn: "Emerald", c1: "#0d6b5e", c2: "#062420", accent: "#2dd4bf", price: 1000 },
|
||||
{ id: "royal", nameFa: "سلطنتی", nameEn: "Royal", c1: "#4a1d7f", c2: "#1a0a2e", accent: "#c77dff", price: 1500 },
|
||||
{ id: "ruby", nameFa: "یاقوت", nameEn: "Ruby", c1: "#7f1d2e", c2: "#2b0a12", accent: "#ff7a90", price: 0, unlockRating: 1300 }, // earned
|
||||
{ id: "royal", nameFa: "سلطنتی", nameEn: "Royal", c1: "#4a1d7f", c2: "#1a0a2e", accent: "#c77dff", price: 0, unlockWins: 50 }, // earned
|
||||
];
|
||||
|
||||
export function cardStyleById(id: string): CardStyleDef {
|
||||
return CARD_STYLES.find((c) => c.id === id) ?? CARD_STYLES[0];
|
||||
// Card FRONTS (the face background/border behind the suit + rank).
|
||||
export const CARD_FRONTS: CardFrontDef[] = [
|
||||
{ id: "classic", nameFa: "کلاسیک", nameEn: "Classic", bg1: "#fffdf7", bg2: "#f3ead2", border: "rgba(0,0,0,0.12)", price: 0, default: true },
|
||||
{ id: "ivory", nameFa: "عاج", nameEn: "Ivory", bg1: "#ffffff", bg2: "#eef2f8", border: "#c9ccd6", price: 600 },
|
||||
{ id: "rosegold", nameFa: "رزگلد", nameEn: "Rose Gold", bg1: "#fff1ee", bg2: "#f6d9cf", border: "#d98a72", price: 900 },
|
||||
{ id: "parchment", nameFa: "پوستنوشت", nameEn: "Parchment", bg1: "#fbf2d8", bg2: "#efd9a3", border: "#caa84a", price: 0, unlockRating: 1300 }, // earned
|
||||
{ id: "mint", nameFa: "نعنایی", nameEn: "Mint", bg1: "#f0fff8", bg2: "#d3f3e3", border: "#57c79a", price: 0, unlockWins: 50 }, // earned
|
||||
];
|
||||
|
||||
export function cardBackById(id: string): CardBackDef {
|
||||
return CARD_BACKS.find((c) => c.id === id) ?? CARD_BACKS[0];
|
||||
}
|
||||
export function cardFrontById(id: string): CardFrontDef {
|
||||
return CARD_FRONTS.find((c) => c.id === id) ?? CARD_FRONTS[0];
|
||||
}
|
||||
|
||||
function ownedCosmeticIds(
|
||||
defs: { id: string; price: number; default?: boolean; unlockRating?: number; unlockWins?: number }[],
|
||||
profile: UserProfile,
|
||||
purchased: string[]
|
||||
): string[] {
|
||||
const ids = new Set<string>();
|
||||
for (const d of defs) {
|
||||
const earned =
|
||||
(d.unlockRating != null && profile.rating >= d.unlockRating) ||
|
||||
(d.unlockWins != null && profile.stats.wins >= d.unlockWins);
|
||||
if (d.default || earned || purchased.includes(d.id)) ids.add(d.id);
|
||||
}
|
||||
return [...ids];
|
||||
}
|
||||
|
||||
export function ownedCardBackIds(profile: UserProfile): string[] {
|
||||
return ownedCosmeticIds(CARD_BACKS, profile, profile.ownedCardBacks ?? []);
|
||||
}
|
||||
export function ownedCardFrontIds(profile: UserProfile): string[] {
|
||||
return ownedCosmeticIds(CARD_FRONTS, profile, profile.ownedCardFronts ?? []);
|
||||
}
|
||||
|
||||
/* --------------------- Reactions (Sheklak / شکلک) -------------------- */
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
// with timers, and computes rewards via gamification.ts.
|
||||
|
||||
import {
|
||||
CARD_STYLES,
|
||||
CARD_BACKS,
|
||||
CARD_FRONTS,
|
||||
REACTION_PACKS,
|
||||
STICKER_PACKS,
|
||||
applyMatchResult,
|
||||
@@ -116,12 +117,14 @@ function defaultProfile(session: AuthSession): UserProfile {
|
||||
currentWinStreak: 0,
|
||||
},
|
||||
ownedAvatars: [AVATARS[0].id, AVATARS[1].id],
|
||||
ownedCardStyles: ["classic"],
|
||||
ownedCardFronts: ["classic"],
|
||||
ownedCardBacks: ["classic"],
|
||||
ownedTitles: ["novice"],
|
||||
ownedReactionPacks: [],
|
||||
ownedStickerPacks: [],
|
||||
title: "novice",
|
||||
cardStyle: "classic",
|
||||
cardFront: "classic",
|
||||
cardBack: "classic",
|
||||
achievements: {},
|
||||
unlocked: [],
|
||||
createdAt: Date.now(),
|
||||
@@ -130,16 +133,19 @@ function defaultProfile(session: AuthSession): UserProfile {
|
||||
|
||||
/** Backfill fields on older persisted profiles so the app never crashes. */
|
||||
function migrateProfile(p: UserProfile): UserProfile {
|
||||
const legacy = p as unknown as { ownedCardStyles?: string[]; cardStyle?: string };
|
||||
return {
|
||||
...p,
|
||||
plan: p.plan ?? "free",
|
||||
ownedAvatars: p.ownedAvatars ?? [AVATARS[0].id],
|
||||
ownedCardStyles: p.ownedCardStyles ?? ["classic"],
|
||||
ownedCardFronts: p.ownedCardFronts ?? ["classic"],
|
||||
ownedCardBacks: p.ownedCardBacks ?? legacy.ownedCardStyles ?? ["classic"],
|
||||
ownedTitles: p.ownedTitles ?? ["novice"],
|
||||
ownedReactionPacks: p.ownedReactionPacks ?? [],
|
||||
ownedStickerPacks: p.ownedStickerPacks ?? [],
|
||||
title: p.title ?? "novice",
|
||||
cardStyle: p.cardStyle ?? "classic",
|
||||
cardFront: p.cardFront ?? "classic",
|
||||
cardBack: p.cardBack ?? legacy.cardStyle ?? "classic",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -328,7 +334,7 @@ export class MockOnlineService implements OnlineService {
|
||||
|
||||
async updateProfile(
|
||||
patch: Partial<
|
||||
Pick<UserProfile, "displayName" | "avatar" | "avatarImage" | "title" | "cardStyle">
|
||||
Pick<UserProfile, "displayName" | "avatar" | "avatarImage" | "title" | "cardFront" | "cardBack">
|
||||
>
|
||||
) {
|
||||
const p = await this.getProfile();
|
||||
@@ -756,14 +762,22 @@ export class MockOnlineService implements OnlineService {
|
||||
price: 500 + i * 150,
|
||||
preview: a.emoji,
|
||||
}));
|
||||
const cardItems: ShopItem[] = CARD_STYLES.filter((c) => c.price > 0).map((c) => ({
|
||||
const backItems: ShopItem[] = CARD_BACKS.filter((c) => c.price > 0).map((c) => ({
|
||||
id: c.id,
|
||||
kind: "cardstyle",
|
||||
kind: "cardback",
|
||||
nameFa: c.nameFa,
|
||||
nameEn: c.nameEn,
|
||||
price: c.price,
|
||||
preview: c.accent,
|
||||
}));
|
||||
const frontItems: ShopItem[] = CARD_FRONTS.filter((c) => c.price > 0).map((c) => ({
|
||||
id: c.id,
|
||||
kind: "cardfront",
|
||||
nameFa: c.nameFa,
|
||||
nameEn: c.nameEn,
|
||||
price: c.price,
|
||||
preview: c.bg2,
|
||||
}));
|
||||
const reactionItems: ShopItem[] = REACTION_PACKS.filter((r) => r.price > 0).map((r) => ({
|
||||
id: r.id,
|
||||
kind: "reactionpack",
|
||||
@@ -780,7 +794,7 @@ export class MockOnlineService implements OnlineService {
|
||||
price: p.price,
|
||||
preview: p.stickers[0], // sticker id; ShopScreen renders via <Sticker>
|
||||
}));
|
||||
return [...avatarItems, ...cardItems, ...reactionItems, ...stickerItems];
|
||||
return [...avatarItems, ...frontItems, ...backItems, ...reactionItems, ...stickerItems];
|
||||
}
|
||||
|
||||
async buyItem(id: string) {
|
||||
@@ -788,15 +802,15 @@ export class MockOnlineService implements OnlineService {
|
||||
const items = await this.getShopItems();
|
||||
const item = items.find((i) => i.id === id);
|
||||
if (!item) return { ok: false, messageFa: "آیتم یافت نشد", messageEn: "Item not found" };
|
||||
const owned =
|
||||
item.kind === "avatar"
|
||||
? p.ownedAvatars.includes(id)
|
||||
: item.kind === "cardstyle"
|
||||
? p.ownedCardStyles.includes(id)
|
||||
: item.kind === "reactionpack"
|
||||
? p.ownedReactionPacks.includes(id)
|
||||
: p.ownedStickerPacks.includes(id);
|
||||
if (owned) return { ok: false, messageFa: "قبلاً خریداری شده", messageEn: "Already owned" };
|
||||
const ownedMap: Record<string, string[]> = {
|
||||
avatar: p.ownedAvatars,
|
||||
cardfront: p.ownedCardFronts,
|
||||
cardback: p.ownedCardBacks,
|
||||
reactionpack: p.ownedReactionPacks,
|
||||
stickerpack: p.ownedStickerPacks,
|
||||
};
|
||||
if (ownedMap[item.kind]?.includes(id))
|
||||
return { ok: false, messageFa: "قبلاً خریداری شده", messageEn: "Already owned" };
|
||||
if (p.coins < item.price)
|
||||
return { ok: false, messageFa: "سکه کافی نیست", messageEn: "Not enough coins" };
|
||||
|
||||
@@ -804,8 +818,10 @@ export class MockOnlineService implements OnlineService {
|
||||
...p,
|
||||
coins: p.coins - item.price,
|
||||
ownedAvatars: item.kind === "avatar" ? [...p.ownedAvatars, id] : p.ownedAvatars,
|
||||
ownedCardStyles:
|
||||
item.kind === "cardstyle" ? [...p.ownedCardStyles, id] : p.ownedCardStyles,
|
||||
ownedCardFronts:
|
||||
item.kind === "cardfront" ? [...p.ownedCardFronts, id] : p.ownedCardFronts,
|
||||
ownedCardBacks:
|
||||
item.kind === "cardback" ? [...p.ownedCardBacks, id] : p.ownedCardBacks,
|
||||
ownedReactionPacks:
|
||||
item.kind === "reactionpack" ? [...p.ownedReactionPacks, id] : p.ownedReactionPacks,
|
||||
ownedStickerPacks:
|
||||
|
||||
@@ -46,7 +46,7 @@ export interface OnlineService {
|
||||
getProfile(): Promise<UserProfile>;
|
||||
updateProfile(
|
||||
patch: Partial<
|
||||
Pick<UserProfile, "displayName" | "avatar" | "avatarImage" | "title" | "cardStyle">
|
||||
Pick<UserProfile, "displayName" | "avatar" | "avatarImage" | "title" | "cardFront" | "cardBack">
|
||||
>
|
||||
): Promise<UserProfile>;
|
||||
upgradePlan(): Promise<UserProfile>;
|
||||
|
||||
+28
-5
@@ -52,12 +52,14 @@ export interface UserProfile {
|
||||
|
||||
// cosmetics
|
||||
ownedAvatars: string[];
|
||||
ownedCardStyles: string[];
|
||||
ownedCardFronts: string[];
|
||||
ownedCardBacks: string[];
|
||||
ownedTitles: string[];
|
||||
ownedReactionPacks: string[]; // purchased reaction packs
|
||||
ownedStickerPacks: string[]; // purchased sticker packs
|
||||
title: string | null; // equipped title id
|
||||
cardStyle: string; // equipped card-back style id
|
||||
cardFront: string; // equipped card-front style id
|
||||
cardBack: string; // equipped card-back style id
|
||||
|
||||
achievements: Record<string, number>; // achievementId -> progress count
|
||||
unlocked: string[]; // achievementId list already unlocked
|
||||
@@ -124,14 +126,30 @@ export interface TitleDef {
|
||||
hintEn: string;
|
||||
}
|
||||
|
||||
export interface CardStyleDef {
|
||||
export interface CardBackDef {
|
||||
id: string;
|
||||
nameFa: string;
|
||||
nameEn: string;
|
||||
c1: string; // back gradient start
|
||||
c2: string; // back gradient end
|
||||
accent: string; // pattern/border accent
|
||||
price: number; // 0 = free/default
|
||||
price: number; // >0 = purchasable
|
||||
default?: boolean;
|
||||
unlockRating?: number;
|
||||
unlockWins?: number;
|
||||
}
|
||||
|
||||
export interface CardFrontDef {
|
||||
id: string;
|
||||
nameFa: string;
|
||||
nameEn: string;
|
||||
bg1: string; // face gradient start
|
||||
bg2: string; // face gradient end
|
||||
border: string; // face border color
|
||||
price: number;
|
||||
default?: boolean;
|
||||
unlockRating?: number;
|
||||
unlockWins?: number;
|
||||
}
|
||||
|
||||
/* --------------------- Reactions (Sheklak / شکلک) -------------------- */
|
||||
@@ -293,7 +311,12 @@ export interface LeaderboardEntry {
|
||||
|
||||
/* ------------------------------- Shop -------------------------------- */
|
||||
|
||||
export type ShopItemKind = "avatar" | "cardstyle" | "reactionpack" | "stickerpack";
|
||||
export type ShopItemKind =
|
||||
| "avatar"
|
||||
| "cardfront"
|
||||
| "cardback"
|
||||
| "reactionpack"
|
||||
| "stickerpack";
|
||||
|
||||
export interface ShopItem {
|
||||
id: string;
|
||||
|
||||
Reference in New Issue
Block a user