@@ -3,41 +3,42 @@ import { shuffle, cloneDeep } from 'lodash'
33import Card from './Card'
44import Cards from './Cards'
55import CardName from './enum/CardName'
6+ import { ref } from 'vue'
67
78export default class CardSlots {
89
9- private _slots : Card [ ]
10- private _upgradedCards : CardName [ ]
10+ private readonly _slots
11+ private readonly _upgradedCards
1112
1213 public constructor ( slots : Card [ ] , upgradedCards : CardName [ ] ) {
13- this . _slots = slots
14- this . _upgradedCards = upgradedCards
14+ this . _slots = ref ( slots )
15+ this . _upgradedCards = ref ( upgradedCards )
1516 }
1617
1718 public get slots ( ) : readonly Card [ ] {
18- return this . _slots
19+ return this . _slots . value
1920 }
2021
2122 public get upgradedCardNames ( ) : readonly CardName [ ] {
22- return this . _upgradedCards
23+ return this . _upgradedCards . value
2324 }
2425
2526 /**
2627 * Get card at slot position.
2728 * @param slot Slot number (1-based)
2829 */
2930 public get ( slot : number ) : Card {
30- if ( slot < 1 || slot > this . _slots . length ) {
31+ if ( slot < 1 || slot > this . _slots . value . length ) {
3132 throw new Error ( `Invalid slot number: ${ slot } ` )
3233 }
33- return this . _slots [ slot - 1 ]
34+ return this . _slots . value [ slot - 1 ]
3435 }
3536
3637 /**
3738 * Check if card is upgraded.
3839 */
3940 public isUpgraded ( card : Card ) : boolean {
40- return this . _upgradedCards . includes ( card . name )
41+ return this . _upgradedCards . value . includes ( card . name )
4142 }
4243
4344 /**
@@ -47,7 +48,7 @@ export default class CardSlots {
4748 if ( this . isUpgraded ( card ) ) {
4849 throw new Error ( `Card is already upgraded: ${ card . name } ` )
4950 }
50- this . _upgradedCards . push ( card . name )
51+ this . _upgradedCards . value . push ( card . name )
5152 }
5253
5354 /**
@@ -57,31 +58,31 @@ export default class CardSlots {
5758 if ( ! this . isUpgraded ( card ) ) {
5859 throw new Error ( `Card is not upgraded: ${ card . name } ` )
5960 }
60- this . _upgradedCards = this . _upgradedCards . filter ( item => item != card . name )
61+ this . _upgradedCards . value = this . _upgradedCards . value . filter ( item => item != card . name )
6162 }
6263
6364 /**
6465 * ARNO can upgrade max. 3 cards.
6566 * @return true if less then 3 cards are upgraded.
6667 */
6768 public canUpgradeCard ( ) : boolean {
68- return this . _upgradedCards . length < 3
69+ return this . _upgradedCards . value . length < 3
6970 }
7071
7172 /**
7273 * @returns Whether upgrade cards can be reverted (at least one is upgraded).
7374 */
7475 public canRevertUpgradeCard ( ) : boolean {
75- return this . _upgradedCards . length > 0
76+ return this . _upgradedCards . value . length > 0
7677 }
7778
7879 /**
7980 * Move card to first position after usage.
8081 */
8182 public moveFirst ( card : Card ) : void {
82- this . _slots = [
83+ this . _slots . value = [
8384 card ,
84- ...this . _slots . filter ( item => item . name != card . name )
85+ ...this . _slots . value . filter ( item => item . name != card . name )
8586 ]
8687 }
8788
@@ -90,8 +91,8 @@ export default class CardSlots {
9091 */
9192 public toPersistence ( ) : CardSlotsPersistence {
9293 return {
93- slots : this . _slots . map ( card => card . name ) ,
94- upgradedCards : cloneDeep ( this . _upgradedCards )
94+ slots : this . _slots . value . map ( card => card . name ) ,
95+ upgradedCards : cloneDeep ( this . _upgradedCards . value )
9596 }
9697 }
9798
0 commit comments