Skip to content

Commit cbee34f

Browse files
committed
chore: manage name and desc in base
1 parent ec123ae commit cbee34f

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

public/resources/modules/elements/base.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import { v4 } from 'https://ga.jspm.io/npm:uuid@9.0.0';
22

33
export default class Base {
4+
name = '';
45
#id;
6+
description = '';
57
#type;
68

79
constructor({
810
id = v4(),
911
type,
12+
...props
1013
}) {
1114
if (!type) throw new Error('Element requires type');
1215
this.#id = id;
1316
this.#type = type;
17+
Object.assign(this, props)
1418
}
1519

1620
get id() {
@@ -37,6 +41,7 @@ export default class Base {
3741
type,
3842
} = this;
3943
return {
44+
...this,
4045
id,
4146
type,
4247
};

public/resources/modules/elements/card.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import style from './card.css' assert { type: 'css' };
12
import BaseElement from './base.js';
23
import { Elements } from './types.js';
34

5+
document.adoptedStyleSheets.push(style);
6+
47
export default class Card extends BaseElement {
58
constructor({
69
attack,
710
cost = 0,
8-
description = '',
911
effects = [''],
1012
health,
1113
image = '',
12-
name = '',
13-
pack = '',
1414
rarity = '',
1515
soul = '',
1616
tribes = [''],
@@ -22,31 +22,31 @@ export default class Card extends BaseElement {
2222
});
2323
this.attack = attack;
2424
this.cost = cost;
25-
this.description = description;
2625
this.effects = effects.filter((_) => _);
2726
this.health = health;
2827
this.image = image;
29-
this.name = name;
30-
this.pack = pack;
3128
this.rarity = rarity;
3229
this.soul = soul;
3330
this.tribes = tribes.filter((_) => _);
3431
}
3532

36-
get isMonster() {
37-
return typeof this.health === 'number';
33+
setMonster() {
34+
if (this.health !== undefined) return;
35+
this.health = 0;
36+
this.attack = 0;
37+
}
38+
39+
get isSpell() {
40+
return this.health === undefined;
3841
}
3942

4043
toJSON() {
4144
const {
4245
attack,
4346
cost,
44-
description,
4547
effects,
4648
health,
4749
image,
48-
name,
49-
pack,
5050
rarity,
5151
soul,
5252
tribes,
@@ -55,12 +55,9 @@ export default class Card extends BaseElement {
5555
...super.toJSON(),
5656
attack,
5757
cost,
58-
description,
5958
effects,
6059
health,
6160
image,
62-
name,
63-
pack,
6461
rarity,
6562
soul,
6663
tribes,

0 commit comments

Comments
 (0)