From 844ccb667dc1c69149f621b4d9d2fb184a4eacad Mon Sep 17 00:00:00 2001 From: Matthew Reishus Date: Wed, 8 Jan 2020 11:17:01 -0600 Subject: [PATCH] Fix bug of "move ding" audio playing every time the clock ticked --- apps/demon_spirit_web/assets/js/hooks/update_ding.js | 10 ++++++++-- .../templates/game/live_show.html.leex | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/demon_spirit_web/assets/js/hooks/update_ding.js b/apps/demon_spirit_web/assets/js/hooks/update_ding.js index ba48c7c..0bf6287 100644 --- a/apps/demon_spirit_web/assets/js/hooks/update_ding.js +++ b/apps/demon_spirit_web/assets/js/hooks/update_ding.js @@ -1,9 +1,15 @@ let move_audio = new Audio(); -move_audio.src = '/sounds/move.mp3'; +move_audio.src = "/sounds/move.mp3"; + +let moves = 0; let UpdateDing = { updated() { - move_audio.play(); + let new_moves = this.el.getAttribute("data-moves"); + if (new_moves != moves) { + moves = new_moves; + move_audio.play(); + } } }; export default UpdateDing; diff --git a/apps/demon_spirit_web/lib/demon_spirit_web/templates/game/live_show.html.leex b/apps/demon_spirit_web/lib/demon_spirit_web/templates/game/live_show.html.leex index 40c2a72..fc09d1a 100644 --- a/apps/demon_spirit_web/lib/demon_spirit_web/templates/game/live_show.html.leex +++ b/apps/demon_spirit_web/lib/demon_spirit_web/templates/game/live_show.html.leex @@ -92,7 +92,7 @@ td .content { <%= render "show/ready.html", state: @state, socket: @socket, guest: @guest %> <% end %> -