Skip to content

Commit

Permalink
fix conter reset
Browse files Browse the repository at this point in the history
  • Loading branch information
zichy committed Oct 26, 2021
1 parent 7b445d9 commit 6c02c00
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class ResetButton {
this.$el = $el;
this.$input = $input;
this.life = life;
this.$counters = $el.closest('.player').querySelectorAll('.counter__input');
this.$player = $el.closest('.player');
this.$counters = this.$player.querySelectorAll('.counter__input');

this.$el.addEventListener('click', (e) => {
e.preventDefault();
Expand All @@ -85,6 +86,9 @@ class ResetButton {
this.$counters.forEach(($counter) => {
$counter.value = 0;
});

new LifeCounter(this.$player);
new SecondaryCounters(this.$player);
});
}
}
Expand Down Expand Up @@ -120,15 +124,13 @@ class Player {
this.$content = document.querySelector('.content');
this.$intro = document.querySelector('.intro');

// Get player template
// Include player template
this.playerTemplate = document.querySelector('.player-template');
this.clone = document.importNode(this.playerTemplate.content, true);
this.$el.appendChild(this.clone);

// Initialize counters
// Get current player
this.$currentPlayer = this.$content.querySelector('.player:last-of-type');
new LifeCounter(this.$currentPlayer);
new SecondaryCounters(this.$currentPlayer);

// Set life count
this.$currentLife = this.$currentPlayer.querySelector('.life__input');
Expand All @@ -142,6 +144,10 @@ class Player {
this.$currentResetButton = this.$currentPlayer.querySelector('.counter__reset');
new ResetButton(this.$currentResetButton, this.$currentLife, this.life);

// Initialize counters
new LifeCounter(this.$currentPlayer);
new SecondaryCounters(this.$currentPlayer);

// Insert template
this.$el.appendChild(this.$intro);
this.$currentPlayer.focus();
Expand Down

1 comment on commit 6c02c00

@vercel
Copy link

@vercel vercel bot commented on 6c02c00 Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.