Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add strictness slider, close #301 #320

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/multiplayer/room.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ <h1 id="funny-toast-text" class="me-auto text-danger"></h1>
<div class="mb-2"></div>
<label for="reading-speed">Reading speed: <span id="reading-speed-display">50</span><br></label>
<input class="form-range" id="reading-speed" type="range" min="0" max="100" step="5">
<label for="strictness">Strictness: <span id="strictness-display">7</span><br></label>
<input class="form-range" id="strictness" type="range" min="0" max="20" step="1" value="7">
<div>
View more settings <a href="/settings">here</a>.
</div>
Expand Down
22 changes: 19 additions & 3 deletions client/multiplayer/room.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* globals WebSocket */

import account from '../scripts/accounts.js';
import questionStats from '../scripts/auth/question-stats.js';
import api from '../scripts/api/index.js';
Expand All @@ -26,7 +24,7 @@ let tossup = {};
let USER_ID = window.localStorage.getItem('USER_ID') || 'unknown';
let username = window.localStorage.getItem('multiplayer-username') || api.getRandomName();

const socket = new WebSocket(
const socket = new window.WebSocket(
window.location.href.replace('http', 'ws') +
(window.location.href.endsWith('?private=true') ? '&' : '?') +
new URLSearchParams({
Expand Down Expand Up @@ -74,6 +72,7 @@ socket.onmessage = function (event) {
case 'set-difficulties': return setDifficulties(data);
case 'set-reading-speed': return setReadingSpeed(data);
case 'set-packet-numbers': return setPacketNumbers(data);
case 'set-strictness': return setStrictness(data);
case 'set-set-name': return setSetName(data);
case 'set-username': return setUsername(data);
case 'set-year-range': return setYearRange(data);
Expand Down Expand Up @@ -207,6 +206,8 @@ function connectionAcknowledged ({

document.getElementById('reading-speed').value = settings.readingSpeed;
document.getElementById('reading-speed-display').textContent = settings.readingSpeed;
document.getElementById('strictness').value = settings.strictness;
document.getElementById('strictness-display').textContent = settings.strictness;

document.getElementById('toggle-rebuzz').checked = settings.rebuzz;

Expand Down Expand Up @@ -574,6 +575,12 @@ function setReadingSpeed ({ username, readingSpeed }) {
document.getElementById('reading-speed-display').textContent = readingSpeed;
}

function setStrictness ({ strictness, username }) {
logEvent(username, `changed the strictness to ${strictness}`);
document.getElementById('strictness').value = strictness;
document.getElementById('strictness-display').textContent = strictness;
}

function setSetName ({ username, setName }) {
logEvent(username, setName.length > 0 ? `changed set name to ${setName}` : 'cleared set name');
document.getElementById('set-name').value = setName;
Expand Down Expand Up @@ -858,6 +865,15 @@ document.getElementById('set-name').addEventListener('change', async function ()
}));
});

document.getElementById('strictness').addEventListener('change', function () {
this.blur();
socket.send(JSON.stringify({ type: 'set-strictness', strictness: this.value }));
});

document.getElementById('strictness').addEventListener('input', function () {
document.getElementById('strictness-display').textContent = this.value;
});

document.getElementById('toggle-lock').addEventListener('click', function () {
this.blur();
socket.send(JSON.stringify({ type: 'toggle-lock', lock: this.checked }));
Expand Down
10 changes: 5 additions & 5 deletions client/multiplayer/room.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/scripts/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export default class api {
* directedPrompt: String | null
* }>}
*/
static async checkAnswer (answerline, givenAnswer) {
static async checkAnswer (answerline, givenAnswer, strictness = 7) {
if (givenAnswer === '') {
return { directive: 'reject', directedPrompt: null };
}

return await fetch('/api/check-answer?' + new URLSearchParams({ answerline, givenAnswer }))
return await fetch('/api/check-answer?' + new URLSearchParams({ answerline, givenAnswer, strictness }))
.then(response => response.json());
}

Expand Down
2 changes: 2 additions & 0 deletions client/singleplayer/tossups/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ <h1 id="funny-toast-text" class="me-auto text-danger"></h1>
<div class="mb-2"></div>
<label for="reading-speed">Reading speed: <span id="reading-speed-display">50</span><br></label>
<input class="form-range" id="reading-speed" type="range" min="0" max="100" step="5">
<label for="strictness">Strictness: <span id="strictness-display">7</span><br></label>
<input class="form-range" id="strictness" type="range" min="0" max="20" step="1" value="7">
<div>
View more settings <a href="/settings">here</a>.
</div>
Expand Down
20 changes: 18 additions & 2 deletions client/singleplayer/tossups/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import account from '../../scripts/accounts.js';
import api from '../../scripts/api/index.js';
import questionStats from '../../scripts/auth/question-stats.js';
import audio from '../../audio/index.js';
// import Player from '../../../quizbowl/Player.js';
import Player from '../../../quizbowl/Player.js';
import ClientTossupRoom from '../ClientTossupRoom.js';
import CategoryManager from '../../../quizbowl/category-manager.js';
Expand All @@ -15,7 +14,7 @@ let maxPacketNumber = 24;

const categoryManager = new CategoryManager();
const queryVersion = '2024-10-11';
const settingsVersion = '2024-10-11';
const settingsVersion = '2024-10-16';
const USER_ID = 'user';

const room = new ClientTossupRoom();
Expand All @@ -40,6 +39,7 @@ function onmessage (message) {
case 'reveal-answer': return revealAnswer(data);
case 'set-categories': return setCategories(data);
case 'set-difficulties': return setDifficulties(data);
case 'set-strictness': return setStrictness(data);
case 'set-reading-speed': return setReadingSpeed(data);
case 'set-packet-numbers': return setPacketNumbers(data);
case 'set-set-name': return setSetName(data);
Expand Down Expand Up @@ -183,6 +183,12 @@ function setDifficulties ({ difficulties }) {
window.localStorage.setItem('singleplayer-tossup-query', JSON.stringify({ ...room.query, version: queryVersion }));
}

function setStrictness ({ strictness }) {
document.getElementById('strictness').value = strictness;
document.getElementById('strictness-display').textContent = strictness;
window.localStorage.setItem('singleplayer-tossup-settings', JSON.stringify({ ...room.settings, version: settingsVersion }));
}

function setPacketNumbers ({ packetNumbers }) {
document.getElementById('packet-number').value = arrayToRange(packetNumbers);
window.localStorage.setItem('singleplayer-tossup-query', JSON.stringify({ ...room.query, version: queryVersion }));
Expand Down Expand Up @@ -351,6 +357,15 @@ document.getElementById('start').addEventListener('click', function () {
socket.sendToServer({ type: 'start' });
});

document.getElementById('strictness').addEventListener('change', function () {
this.blur();
socket.sendToServer({ type: 'set-strictness', strictness: this.value });
});

document.getElementById('strictness').addEventListener('input', function () {
document.getElementById('strictness-display').textContent = this.value;
});

document.getElementById('toggle-correct').addEventListener('click', function () {
this.blur();
socket.sendToServer({ type: 'toggle-correct', correct: this.textContent === 'I was right' });
Expand Down Expand Up @@ -459,6 +474,7 @@ if (window.localStorage.getItem('singleplayer-tossup-settings')) {
try {
const savedSettings = JSON.parse(window.localStorage.getItem('singleplayer-tossup-settings'));
if (savedSettings.version !== settingsVersion) { throw new Error(); }
socket.sendToServer({ type: 'set-strictness', ...savedSettings });
socket.sendToServer({ type: 'set-reading-speed', ...savedSettings });
socket.sendToServer({ type: 'toggle-rebuzz', ...savedSettings });
socket.sendToServer({ type: 'toggle-show-history', ...savedSettings });
Expand Down
Loading
Loading