From deb0784409d899abe850a3665cc62da79117e686 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Tue, 5 Nov 2024 20:04:53 +0000 Subject: [PATCH] clean up decklist template and add latestPrinting getter to card model --- app/components/deck/writeup.gjs | 87 ++++++++++++++++- app/models/card.js | 8 ++ app/models/decklist.js | 6 +- app/routes/decklist.js | 167 +------------------------------- app/routes/faction.js | 3 - app/templates/decklist.hbs | 2 +- 6 files changed, 96 insertions(+), 177 deletions(-) diff --git a/app/components/deck/writeup.gjs b/app/components/deck/writeup.gjs index f59fc53..c8f1fb1 100644 --- a/app/components/deck/writeup.gjs +++ b/app/components/deck/writeup.gjs @@ -1,12 +1,22 @@ +import Component from '@glimmer/component'; +import { get } from '@ember/helper'; import { and } from 'netrunnerdb/utils/template-operators'; import gt from 'ember-truth-helpers/helpers/gt'; import notEq from 'ember-truth-helpers/helpers/not-eq'; -import Component from '@glimmer/component'; import Icon from '../icon'; import CardLinkTo from '../card/link-to'; import InfluencePips from '../card/influence-pips'; export default class Writeup extends Component { + // Sorts a decklist's cards into an array of arrays of objects: + // [[{ + // name + // cardTypeId + // cards + // count + // }]] + // Each top level array represents a column on the decklist view + // Each nested array represents the types (or subtypes) of cards within each subtype formatCards(cards, cardTypes, decklist) { let row1CardTypes = cardTypes.filter((type) => [ @@ -87,9 +97,75 @@ export default class Writeup extends Component { return [row1Cards, row2Cards]; } + // Counts the number of individual cards in a decklist are from a list of distinct cards + countCards(cards, decklist) { + let count = 0; + cards.forEach((card) => { + count += decklist.cardSlots[card.id]; + }); + return count; + } + + // Collect the ice from a list of cards and separate them by subtype + formatIce(cards) { + cards = cards.filter((card) => card.cardTypeId == 'ice'); + + let barriers = []; + let codeGates = []; + let sentries = []; + let multis = []; + let misc = []; + + cards.forEach((card) => { + let isBarrier = card.cardSubtypeIds.includes('barrier'); + let isCodeGate = card.cardSubtypeIds.includes('code_gate'); + let isSentry = card.cardSubtypeIds.includes('sentry'); + + if ( + (isBarrier && isCodeGate) || + (isBarrier && isSentry) || + (isCodeGate && isSentry) + ) { + multis.push(card); + } else if (isBarrier) { + barriers.push(card); + } else if (isCodeGate) { + codeGates.push(card); + } else if (isSentry) { + sentries.push(card); + } else { + misc.push(card); + } + }); + + return { barriers, codeGates, sentries, multis, misc }; + } + + // Collect the programs from a list of cards and separate them by icebreaker vs non-icebreaker + formatPrograms(cards) { + cards = cards.filter((card) => card.cardTypeId == 'program'); + + let icebreakers = cards.filter((card) => + card.cardSubtypeIds.includes('icebreaker'), + ); + let misc = cards.filter( + (card) => !card.cardSubtypeIds.includes('icebreaker'), + ); + + return { icebreakers, misc }; + } + + get cardsByCategory() { + return this.formatCards( + this.args.decklist.cards, + this.args.cardTypes, + this.args.decklist, + ); + } +