Put trading and giving up front and suggest the players who need each card

The Échanges et dons page now opens on two illustrated tiles, centred and
360 px wide at most: trade (L'Échange Écarlate) and give (the Dawn card,
renamed Le Don de l'Aube with a gift story). Each counts the cards missing
on either side and previews a few. In the composer, the most useful players
come first in the list and as suggested chips, and missing duplicates lead
with a badge; nothing is filtered, so owned duplicates stay tradeable for
Awakenings. GET /api/cards/traders adds `wants`: which of the viewer's own
duplicates each player lacks, and nothing else of their collection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-12-01 17:01:56 +01:00
parent 2f3c371d7b
commit 17e5cd5e63
12 changed files with 302 additions and 46 deletions

View file

@ -1210,7 +1210,10 @@ export class CardsService {
return this.getState(playerId);
}
/** Joueurs à qui donner ou proposer un échange : seuls leur identité publique et leurs doublons disponibles sont exposés, jamais leur collection. */
/**
* Joueurs à qui donner ou proposer un échange : leur identité publique, leurs doublons disponibles et, dans `wants`,
* ceux des doublons du demandeur qu'ils ne possèdent pas. Le reste de leur collection n'est jamais exposé.
*/
listTraders(playerId) {
this.expireTransfers();
const rows = this.db.prepare("SELECT id, display_name, avatar_url FROM players WHERE id != ? AND deleted_at IS NULL ORDER BY display_name COLLATE NOCASE").all(playerId);
@ -1227,12 +1230,20 @@ export class CardsService {
if (!duplicates.has(row.player_id)) duplicates.set(row.player_id, []);
duplicates.get(row.player_id).push({ editionId: row.edition_id, spare });
}
// Seules les cartes que le demandeur peut donner sont comparées : c'est tout ce qu'il apprend des autres collections.
const mySpares = (duplicates.get(playerId) || []).map((entry) => entry.editionId);
const owners = new Map(mySpares.map((editionId) => [editionId, new Set()]));
if (mySpares.length) {
for (const row of this.db.prepare(`SELECT player_id, edition_id FROM collection_cards
WHERE quantity > 0 AND edition_id IN (SELECT value FROM json_each(?))`).all(JSON.stringify(mySpares))) owners.get(row.edition_id).add(row.player_id);
}
return {
traders: rows.map((row) => ({
id: row.id,
displayName: row.display_name,
avatarUrl: row.avatar_url,
duplicates: duplicates.get(row.id) || []
duplicates: duplicates.get(row.id) || [],
wants: mySpares.filter((editionId) => !owners.get(editionId).has(row.id))
}))
};
}