File tree Expand file tree Collapse file tree
public/resources/modules/elements Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,62 +5,73 @@ import { Elements } from './types.js';
55document . adoptedStyleSheets . push ( style ) ;
66
77export default class Card extends BaseElement {
8+ /** @type {number | undefined } */
9+ #attack;
10+ cost = 0 ;
11+ /** @type {string[] } */
12+ effects = [ ] ;
13+ /** @type {number | undefined } */
14+ #health;
15+ image = '' ;
16+ rarity = '' ;
17+ soul = '' ;
18+ /** @type {string[] } */
19+ tribes = [ ] ;
20+
821 constructor ( {
922 attack,
10- cost = 0 ,
11- effects = [ '' ] ,
1223 health,
13- image = '' ,
14- rarity = '' ,
15- soul = '' ,
16- tribes = [ '' ] ,
24+ // soul = '',
1725 ...rest
1826 } = { } ) {
1927 super ( {
2028 ...rest ,
2129 type : Elements . Card ,
2230 } ) ;
23- this . attack = attack ;
24- this . cost = cost ;
25- this . effects = effects . filter ( ( _ ) => _ ) ;
26- this . health = health ;
27- this . image = image ;
28- this . rarity = rarity ;
29- this . soul = soul ;
30- this . tribes = tribes . filter ( ( _ ) => _ ) ;
31+ this . #attack = attack ;
32+ this . #health = health ;
33+ // this.#soul = soul;
34+ }
35+
36+ get attack ( ) {
37+ return this . #attack;
38+ }
39+
40+ set attack ( value = 0 ) {
41+ if ( this . isSpell ) throw new Error ( 'Adding attack to spell' ) ;
42+ if ( value < 0 ) throw new Error ( 'Invalid attack value' ) ;
43+ this . #attack = value ;
44+ }
45+
46+ get health ( ) {
47+ return this . #health;
48+ }
49+
50+ set health ( value = 0 ) {
51+ if ( this . isSpell ) throw new Error ( 'Adding health to spell' ) ;
52+ if ( value < 0 ) throw new Error ( 'Invalid health value' ) ;
53+ this . #health = value ;
3154 }
3255
3356 setMonster ( ) {
34- if ( this . health !== undefined ) return ;
35- this . health = 0 ;
36- this . attack = 0 ;
57+ if ( this . # health !== undefined ) return ;
58+ this . # health = 0 ;
59+ this . # attack = 0 ;
3760 }
3861
3962 get isSpell ( ) {
40- return this . health === undefined ;
63+ return this . # health === undefined ;
4164 }
4265
4366 toJSON ( ) {
4467 const {
4568 attack,
46- cost,
47- effects,
4869 health,
49- image,
50- rarity,
51- soul,
52- tribes,
5370 } = this ;
5471 return {
5572 ...super . toJSON ( ) ,
5673 attack,
57- cost,
58- effects,
5974 health,
60- image,
61- rarity,
62- soul,
63- tribes,
6475 } ;
6576 }
6677}
You can’t perform that action at this time.
0 commit comments