-
Notifications
You must be signed in to change notification settings - Fork 4
/
vellum-npc.js
90 lines (73 loc) · 2.29 KB
/
vellum-npc.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { StatBlock } from './vellum-stat-block.js'
import { html, css } from 'lit-element'
import { capitalise } from './lib/capitalise'
import './vellum-stat-block-divider.js'
import './vellum-stat.js'
import './vellum-stat-block-ability-scores.js'
import './vellum-spell-level.js'
import './vellum-stat-block-section.js'
import './vellum-attack.js'
import './vellum-legendary-action.js'
class NonPlayerCharacter extends StatBlock {
static get styles() {
return css`
${StatBlock.styles}
p.description {
font-style: italics;
margin-bottom: 0;
}
#npc-header p::first-letter {
text-transform: capitalize;
}
a {
color: var(--stat-block-header-color, black);
text-decoration: none;
}
`
}
static get is() { return 'vellum-npc' }
static get properties() {
return {
name: String,
description: String,
race: String,
statblock: String,
statblockref: String,
dndbeyond: Boolean,
alignment: String,
attitude: String,
gender: String,
pronouns: String
}
}
renderHeader() {
const paranthesis =
[this.gender, this.pronouns, this.alignment, this.attitude]
.filter(e => e !== undefined)
.filter(s => s !== '')
const ref = this.dndbeyond ? `https://www.dndbeyond.com/monsters/${this.statblock}` : this.statblockref
return html`
<div id="npc-header">
<h1>${this.name}</h1>
<p>
${capitalise(this.gender)}
${!this.gender ? capitalise(this.race) : this.race}
<strong id="statblock">${this.renderStatblock(!this.gender && !this.race ? capitalise(this.statblock) : this.statblock, ref)}</strong>
(${paranthesis.join(', ')})</p>
</div>`
}
renderStatblock(statblock, link) {
return link ? html`<a href="${link}" alt="${statblock}">${statblock}</a>` : statblock
}
renderStats() {
const descriptionTemplate = html`
<p id="description">${this.description}</p>
<vellum-stat-block-divider id="description-divider"></vellum-stat-block-divider>`
return html`
<div id="npc-stats">
${this.description ? descriptionTemplate : html``}
<slot></slot>
</div>`
}
}
customElements.define(NonPlayerCharacter.is, NonPlayerCharacter)