-
Notifications
You must be signed in to change notification settings - Fork 4
/
vellum-spell-level.js
65 lines (55 loc) · 1.29 KB
/
vellum-spell-level.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { LitElement, html, css } from 'lit-element'
class SpellLevel extends LitElement {
static get styles() {
return css`
.spells {
font-style: italic;
}`
}
static get is() { return 'vellum-spell-level' }
static get properties() {
return {
level: String,
spells: Array,
slots: Number
}
}
render() {
return html`
<span class="spell-level">
<span class="level">
${this.displayTitle() ? this.displayTitle() : html`${this.level} level`}
${this.slots > 0 ? this.renderSlots() : ''}
</span>
<span class="spells">${this.renderSpells()}</span>
</span>`
}
displayTitle() {
switch (this.level.toLowerCase()) {
case 'cantrips':
return 'Cantrips (at will):'
case 'at-will':
return 'At will:'
case '1/day':
return '1/day each:'
default:
return false
}
}
renderSlots() {
return html`
(${this.slots} ${this.slots > 1 ? html`slots):` : html`slot):`}`
}
renderSpells() {
if (Array.isArray(this.spells)) {
return this.spells.join(', ')
} else {
try {
return JSON.parse(this.spells).join(', ')
} catch (error) {
return this.spells
}
}
}
}
customElements.define(SpellLevel.is, SpellLevel)