Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
blob: fd1c66193a376f01473e4f8976a182ae88314efe (plain)
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
customElements.define(
  'damage-block',
  class extends HTMLSpanElement {
    constructor() {
      super();

      const template = document.querySelector('#damage-block'),
        templateContent = template.content,
        shadowRoot = this.attachShadow({ mode: "open" });

      shadowRoot.appendChild(templateContent.cloneNode(true));
    }

    connectedCallback() {
      const el = this.shadowRoot.querySelector('.damage-effect-indicator');

      el.addEventListener('click', e => {
        e.stopPropagation()

        this.#cycleThroughDamageStates(el);
      });
    }

    #cycleThroughDamageStates(el) {
      if (el.classList.contains('bruise')) {
        el.classList.remove('bruise');
        el.classList.add('lethal');
      } else if (el.classList.contains('lethal')) {
        el.classList.remove('lethal');
      } else {
        el.classList.add('bruise');
      }
    }
  },
  { extends: 'span' }
);

customElements.define(
  'soldier-record-block',
  class extends HTMLDivElement {
    constructor() {
      super();

      const template = document.querySelector('#soldier-record-block'),
        templateContent = template.content,
        shadowRoot = this.attachShadow({ mode: "open" });

      shadowRoot.appendChild(templateContent.cloneNode(true));
    }
  },
  { extends: 'div' }
);