diff --git a/src/js/script.js b/src/js/script.js index a82d49701..9d5bfda7e 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -5405,6 +5405,27 @@ function handleSpace(event, isEnter) { } } //end of line wrap + let wpmAndRaw = liveWpmAndRaw(); + + let acc = Misc.roundTo2( + (accuracyStats.correct / + (accuracyStats.correct + accuracyStats.incorrect)) * + 100 + ); + + let progress = 0; + if (config.mode === "time") { + progress = 100 - ((time + 1) / config.time) * 100; + } else { + let outof = wordsList.length; + if (config.mode === "words") { + outof = config.words; + } + progress = Math.floor((currentWordIndex / (outof - 1)) * 100); + } + + mp_sendTestProgress(wpmAndRaw.wpm, acc, progress); + updateCaretPosition(); if (config.keymapMode === "react") { diff --git a/src/js/tribe.js b/src/js/tribe.js index 0610363bd..2be770464 100644 --- a/src/js/tribe.js +++ b/src/js/tribe.js @@ -17,6 +17,18 @@ let MP = { pageTransition: false, }; +let tribeSounds = { + join: new Audio("../sound/tribe_ui/join.wav"), + leave: new Audio("../sound/tribe_ui/leave.wav"), + start: new Audio("../sound/tribe_ui/start.wav"), + chat1: new Audio("../sound/tribe_ui/chat1.wav"), + chat2: new Audio("../sound/tribe_ui/chat2.wav"), + finish: new Audio("../sound/tribe_ui/finish.wav"), + finish_win: new Audio("../sound/tribe_ui/finish_win.wav"), + cd: new Audio("../sound/tribe_ui/cd.wav"), + cd_go: new Audio("../sound/tribe_ui/cd_go.wav"), +}; + //-1 - disconnected //1 - connected //10 - lobby @@ -84,6 +96,11 @@ function mp_refreshUserList() { }); } +function mp_playSound(sound) { + tribeSounds[sound].currentTime = 0; + tribeSounds[sound].play(); +} + function mp_resetLobby() { $(".pageTribe .lobby .userlist .list").empty(); $(".pageTest #result .tribeResultChat .chat .messages").empty(); @@ -215,9 +232,30 @@ function mp_refreshTestUserList() { $(".tribeResult table tbody").append(` ${user.name} -
-
-
-
-
-
-
-
-
+ +
+
-
+
+
+
+
-
+
+
+ + +
+
-
+
+
+
+
-
+
+
+ + +
-
+
-
+
@@ -470,6 +508,7 @@ MP.socket.on("connect_error", (f) => { }); MP.socket.on("mp_room_joined", (data) => { + mp_playSound("join"); MP.room = data.room; if ( MP.room.users.filter((user) => user.socketId === MP.socket.id)[0].isLeader @@ -512,6 +551,7 @@ MP.socket.on("mp_room_leave", () => { }); MP.socket.on("mp_room_user_left", (data) => { + mp_playSound("leave"); MP.room = data.room; if (data.newLeader !== "" && data.newLeader === MP.id) { MP.room.isLeader = true; @@ -529,6 +569,7 @@ MP.socket.on("mp_room_config_update", (data) => { }); MP.socket.on("mp_chat_message", (data) => { + mp_playSound("chat2"); let cls = "message"; let author = ""; if (data.isSystem) { @@ -599,10 +640,12 @@ MP.socket.on("mp_room_test_start", (data) => { // Notifications.add("test starting",0); updateCountdown("Go"); fadeoutCountdown(); + mp_playSound("cd_go"); }); MP.socket.on("mp_room_test_countdown", (data) => { updateCountdown(data.val); + mp_playSound("cd"); // Notifications.add(`countdown ${data.val}`,0); }); @@ -619,6 +662,7 @@ MP.socket.on("mp_room_finishTimer_over", (data) => { }); MP.socket.on("mp_room_test_init", (data) => { + mp_playSound("start"); MP.room.testStats = {}; seedrandom(data.seed, { global: true }); mp_refreshTestUserList(); @@ -640,10 +684,10 @@ MP.socket.on("mp_room_user_test_progress_update", (data) => { $(`.tribePlayers .player[socketId=${data.socketId}] .acc`).text( Math.floor(data.stats.acc) + "%" ); - $(`.tribeResult table .player[socketId=${data.socketId}] .wpm`).text( + $(`.tribeResult table .player[socketId=${data.socketId}] .wpm .text`).text( data.stats.wpm ); - $(`.tribeResult table .player[socketId=${data.socketId}] .acc`).text( + $(`.tribeResult table .player[socketId=${data.socketId}] .acc .text`).text( Math.floor(data.stats.acc) + "%" ); $(`.tribePlayers .player[socketId=${data.socketId}] .bar`) @@ -673,10 +717,10 @@ MP.socket.on("mp_room_user_test_progress_update", (data) => { }); MP.socket.on("mp_room_user_finished", (data) => { - $(`.tribeResult table .player[socketId=${data.socketId}] .wpm`).text( + $(`.tribeResult table .player[socketId=${data.socketId}] .wpm .text`).text( data.result.wpm ); - $(`.tribeResult table .player[socketId=${data.socketId}] .acc`).text( + $(`.tribeResult table .player[socketId=${data.socketId}] .acc .text`).text( data.result.acc + "%" ); // $(`.tribeResult table .player[socketId=${data.socketId}] .progress`).remove(); @@ -688,7 +732,7 @@ MP.socket.on("mp_room_user_finished", (data) => { //
//
// `); - $(`.tribeResult table .player[socketId=${data.socketId}] .raw`).text( + $(`.tribeResult table .player[socketId=${data.socketId}] .raw .text`).text( data.result.raw ); let val = "-"; @@ -705,16 +749,16 @@ MP.socket.on("mp_room_user_finished", (data) => { $(`.tribeResult table .player[socketId=${data.socketId}] .char`).text( data.result.char ); - $(`.tribeResult table .player[socketId=${data.socketId}] .con`).text( + $(`.tribeResult table .player[socketId=${data.socketId}] .con .text`).text( data.result.con + "%" ); - if (data.result.failed || data.result.invalid) { + if (data.result.failed || data.result.invalid || data.result.afk) { $(`.tribePlayers .player[socketId=${data.socketId}]`).addClass("failed"); $(`.tribeResult .player[socketId=${data.socketId}]`).addClass("failed"); } - if (config.mode !== "time" && !data.result.failed) { + if (config.mode !== "time" && !data.result.failed && !data.result.afk) { $(`.tribePlayers .player[socketId=${data.socketId}] .bar`) .stop(true, false) .animate( @@ -741,11 +785,15 @@ MP.socket.on("mp_room_winner", (data) => { if (data.official) { hideResultCountdown(); } + let userwon = false; data.sorted.forEach((sid) => { $(`.tribeResult table [socketId=${sid.sid}] .pos .num`).text( `${pos}${Misc.getNumberSuffix(pos)}` ); if (data.official && pos == 1) { + if (sid.sid === MP.socket.id) { + userwon = true; + } $(`.tribeResult table [socketId=${sid.sid}] .crown .fa-crown`).animate( { opacity: 1 }, 125 @@ -758,6 +806,23 @@ MP.socket.on("mp_room_winner", (data) => { } pos++; }); + if (userwon && data.official) { + mp_playSound("finish_win"); + } else if (!userwon && data.official) { + mp_playSound("finish"); + } +}); + +MP.socket.on("mp_room_miniCrowns", (data) => { + Object.keys(data.crowns).forEach((c) => { + let crown = data.crowns[c]; + crown.sidList.forEach((sid) => { + $(`.tribeResult table [socketId=${sid}] .${c} .miniCrown`).animate( + { opacity: 0.5 }, + 125 + ); + }); + }); }); MP.socket.on("mp_room_points", (data) => { diff --git a/src/sass/style.scss b/src/sass/style.scss index 9fefb390a..4ed9f0e88 100644 --- a/src/sass/style.scss +++ b/src/sass/style.scss @@ -1593,14 +1593,24 @@ key { .progressAndGraph { width: 25%; } - .acc, - .con, - .other { + .acc .text, + .con .text, + .other .text { opacity: 0.5; } .crown { width: 1px; } + .text { + display: inline-block; + } + .miniCrown { + display: inline-block; + width: 0; + font-size: 0.5rem; + vertical-align: super; + opacity: 0; + } .pos { width: 5.6rem; .num { diff --git a/static/sound/tribe_ui/alert.wav b/static/sound/tribe_ui/alert.wav new file mode 100644 index 000000000..aa93c1152 Binary files /dev/null and b/static/sound/tribe_ui/alert.wav differ diff --git a/static/sound/tribe_ui/cd.wav b/static/sound/tribe_ui/cd.wav new file mode 100644 index 000000000..f87ee7243 Binary files /dev/null and b/static/sound/tribe_ui/cd.wav differ diff --git a/static/sound/tribe_ui/cd_go.wav b/static/sound/tribe_ui/cd_go.wav new file mode 100644 index 000000000..3d7cd727e Binary files /dev/null and b/static/sound/tribe_ui/cd_go.wav differ diff --git a/static/sound/tribe_ui/chat1.wav b/static/sound/tribe_ui/chat1.wav new file mode 100644 index 000000000..c48c43a0d Binary files /dev/null and b/static/sound/tribe_ui/chat1.wav differ diff --git a/static/sound/tribe_ui/chat2.wav b/static/sound/tribe_ui/chat2.wav new file mode 100644 index 000000000..f1ba6638f Binary files /dev/null and b/static/sound/tribe_ui/chat2.wav differ diff --git a/static/sound/tribe_ui/finish.wav b/static/sound/tribe_ui/finish.wav new file mode 100644 index 000000000..cea824880 Binary files /dev/null and b/static/sound/tribe_ui/finish.wav differ diff --git a/static/sound/tribe_ui/finish_win.wav b/static/sound/tribe_ui/finish_win.wav new file mode 100644 index 000000000..4c9363842 Binary files /dev/null and b/static/sound/tribe_ui/finish_win.wav differ diff --git a/static/sound/tribe_ui/join.wav b/static/sound/tribe_ui/join.wav new file mode 100644 index 000000000..02b3052e1 Binary files /dev/null and b/static/sound/tribe_ui/join.wav differ diff --git a/static/sound/tribe_ui/leave.wav b/static/sound/tribe_ui/leave.wav new file mode 100644 index 000000000..69efe2910 Binary files /dev/null and b/static/sound/tribe_ui/leave.wav differ diff --git a/static/sound/tribe_ui/start.wav b/static/sound/tribe_ui/start.wav new file mode 100644 index 000000000..dcc0eafb3 Binary files /dev/null and b/static/sound/tribe_ui/start.wav differ