|
|
@ -4,10 +4,13 @@ const input = document.querySelector("#shiritori-input");
|
|
|
|
const players = document.querySelector("#shiritori-players");
|
|
|
|
const players = document.querySelector("#shiritori-players");
|
|
|
|
let id = null;
|
|
|
|
let id = null;
|
|
|
|
|
|
|
|
|
|
|
|
function displayWord(_word, end) {
|
|
|
|
function displayWord(_word, end, delay) {
|
|
|
|
let { word, reading } = _word;
|
|
|
|
let { word, reading } = _word;
|
|
|
|
p = document.createElement("p");
|
|
|
|
p = document.createElement("p");
|
|
|
|
p.innerHTML = reading || word === reading ? (word === "" ? reading : `<ruby>${word}<rp>(</rp><rt>${reading}<rt/><rp>)</rp></ruby>`) : word;
|
|
|
|
p.innerHTML = reading || word === reading ? (word === "" ? reading : `<ruby>${word}<rp>(</rp><rt>${reading}<rt/><rp>)</rp></ruby>`) : word;
|
|
|
|
|
|
|
|
if (delay != 0) {
|
|
|
|
|
|
|
|
p.style.animationDelay = `${delay}s`;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (end) {
|
|
|
|
if (end) {
|
|
|
|
div.append(p);
|
|
|
|
div.append(p);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -24,16 +27,16 @@ ws.onmessage = e => {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "word":
|
|
|
|
case "word":
|
|
|
|
let waiting = data.author === id;
|
|
|
|
let waiting = data.author === id;
|
|
|
|
displayWord(data.word, true);
|
|
|
|
displayWord(data.word, true, 0);
|
|
|
|
input.placeholder = waiting ? "Waiting for other players..." : `${data.next_mora}…`;
|
|
|
|
input.placeholder = waiting ? "Waiting for other players..." : `${data.next_mora}…`;
|
|
|
|
input.disabled = waiting;
|
|
|
|
input.disabled = waiting;
|
|
|
|
if (!waiting) input.focus();
|
|
|
|
if (!waiting) input.focus();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "history":
|
|
|
|
case "history":
|
|
|
|
console.log(data);
|
|
|
|
console.log(data);
|
|
|
|
data.words.forEach(word => {
|
|
|
|
for (let i = 0; i < data.words.length; i++) {
|
|
|
|
displayWord(word, false);
|
|
|
|
displayWord(data.words[i], false, 0.1 * i);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "playerCount":
|
|
|
|
case "playerCount":
|
|
|
|
let otherPlayers = data.players - 1;
|
|
|
|
let otherPlayers = data.players - 1;
|
|
|
|