-
Notifications
You must be signed in to change notification settings - Fork 4
/
vellum-stat-block-ability-scores.js
77 lines (66 loc) · 1.54 KB
/
vellum-stat-block-ability-scores.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
import { LitElement, html, css } from 'lit-element'
class AbilityScores extends LitElement {
static get styles() {
return css`
:host {
display: block;
}
table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
border-spacing: 0;
margin: 0.2em;
}
table th,
table td {
text-align: center;
width: 50px;
min-width: 50px;
padding: 0;
vertical-align: middle;
}`
}
static get is() { return 'vellum-stat-block-ability-scores' }
static get properties() {
return {
str: Number,
dex: Number,
con: Number,
int: Number,
wis: Number,
cha: Number
}
}
render() {
return html`
<table>
<thead>
<tr>
<th>STR</th>
<th>DEX</th>
<th>CON</th>
<th>INT</th>
<th>WIS</th>
<th>CHA</th>
</tr>
</thead>
<tbody>
<tr>
<td>${this.displayAbility(this.str)}</td>
<td>${this.displayAbility(this.dex)}</td>
<td>${this.displayAbility(this.con)}</td>
<td>${this.displayAbility(this.int)}</td>
<td>${this.displayAbility(this.wis)}</td>
<td>${this.displayAbility(this.cha)}</td>
</tr>
</tbody>
</table>`
}
displayAbility(ability) {
const bonus = Math.round((ability / 2.1) - 5)
if (bonus >= 0) return ability + ' (+' + bonus + ')'
else return ability + ' (' + bonus + ')'
}
}
customElements.define(AbilityScores.is, AbilityScores)