Include next mora in greeting event

master
Elnu 1 year ago
parent 53fb1f3c4e
commit f157c847bb

@ -19,18 +19,25 @@ function displayWord(_word, end, delay) {
div.scrollTop = div.offsetHeight;
}
function updateInput(data) {
if (data.next_mora !== null) {
let waiting = data.author === id;
input.placeholder = waiting ? "Waiting for other players..." : `${data.next_mora}`;
input.disabled = waiting;
if (!waiting) input.focus();
}
}
ws.onmessage = e => {
const { event, data } = JSON.parse(e.data);
switch (event) {
case "greeting":
id = data.id;
updateInput(data);
break;
case "word":
let waiting = data.author === id;
displayWord(data.word, true, 0);
input.placeholder = waiting ? "Waiting for other players..." : `${data.next_mora}`;
input.disabled = waiting;
if (!waiting) input.focus();
updateInput(data);
break;
case "history":
console.log(data);

@ -26,6 +26,7 @@ impl MessageResponse {
enum MessageResponseData {
Greeting {
id: u64,
next_mora: Option<String>,
},
Word {
author: u64,
@ -165,7 +166,8 @@ impl Server {
fn handle_connection(&mut self, client_id: u64, responder: Responder) -> Result<(), ServerError> {
println!("A client connected with id #{}", client_id);
responder.send(MessageResponseData::Greeting {
id: client_id
id: client_id,
next_mora: self.next_mora.clone(),
}.into_message());
responder.send(MessageResponseData::History {
words: self.database.load_words_before(self.database.last_word_id + 1)?

Loading…
Cancel
Save