4 changed files with 167 additions and 3 deletions
@ -0,0 +1,114 @@ |
|||
import { Injectable } from '@angular/core'; |
|||
import { CardInfo } from '../models/card.model'; |
|||
|
|||
const MAX_BASES = 1; |
|||
const MAX_LEADER = 1; |
|||
const PLAYSET_SIZE = 3; |
|||
const MAX_HYPERSPACE = 1; |
|||
|
|||
@Injectable({ |
|||
providedIn: 'root', |
|||
}) |
|||
|
|||
export class FilterService { |
|||
showTrades: boolean = true; |
|||
showPlaysets: boolean = true; |
|||
showAtLeastOne: boolean = true; |
|||
includeFoilInPlayset: boolean = false; |
|||
|
|||
showAll = true; |
|||
showOnlyTrades = false; |
|||
showOnlyMissing = false; |
|||
showNeedsMore = false; |
|||
|
|||
setFilter(all: boolean, trades : boolean, missing: boolean, need : boolean) |
|||
{ |
|||
this.showAll = all; |
|||
this.showOnlyTrades = trades; |
|||
this.showOnlyMissing = missing; |
|||
this.showNeedsMore = need; |
|||
} |
|||
|
|||
cardPassesFilter(card: CardInfo, hyperspace: boolean) : boolean |
|||
{ |
|||
if(this.showAll) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
if (this.showOnlyTrades) |
|||
{ |
|||
return this.hasTrades(card, hyperspace); |
|||
} |
|||
|
|||
if(this.showOnlyMissing) |
|||
{ |
|||
return this.getCardCount(card, hyperspace) == 0; |
|||
} |
|||
|
|||
if(this.showNeedsMore) |
|||
{ |
|||
return this.hasPlayset(card, hyperspace) == false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
hasTrades(card: CardInfo, hyperspace: boolean) : boolean { |
|||
|
|||
let quantity = this.getCardCount(card, hyperspace); |
|||
|
|||
if(card.isLeader && quantity > MAX_LEADER) { |
|||
return true; |
|||
} |
|||
|
|||
if(card.isBase && quantity > MAX_BASES) { |
|||
return true; |
|||
} |
|||
|
|||
if(hyperspace && quantity > MAX_HYPERSPACE) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
if(quantity > PLAYSET_SIZE) { |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
hasPlayset(card: CardInfo, hyperspace: boolean) : boolean { |
|||
|
|||
let quantity = this.getCardCount(card, hyperspace); |
|||
|
|||
if(card.isLeader && quantity >= MAX_LEADER) { |
|||
return true; |
|||
} |
|||
|
|||
if(card.isBase && quantity >= MAX_BASES) { |
|||
return true; |
|||
} |
|||
|
|||
let check = hyperspace ? MAX_HYPERSPACE : PLAYSET_SIZE; |
|||
if(quantity >= check ) { |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
hasAtleastOne(card: CardInfo, hyperspace: boolean) : boolean { |
|||
let quantity = this.getCardCount(card, hyperspace); |
|||
return quantity >= 1; |
|||
} |
|||
|
|||
getCardCount(card: CardInfo, hyperspace: boolean) : number { |
|||
let quantity = card.standardQuantity + (this.includeFoilInPlayset ? card.foilQuantity : 0); |
|||
if(hyperspace) |
|||
{ |
|||
quantity = card.hyperspaceQuantity + (this.includeFoilInPlayset ? card.hyperspaceFoilQuantity : 0);; |
|||
} |
|||
return quantity; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue