From 770681945b4a3ceccd89634b974ac0a4e6bfb9d3 Mon Sep 17 00:00:00 2001 From: stonedDiscord <10584181+stonedDiscord@users.noreply.github.com> Date: Mon, 7 Sep 2020 20:08:48 +0200 Subject: make the button work and play automatically --- webAO/client.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/webAO/client.js b/webAO/client.js index 9817390..de22a0e 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -250,12 +250,21 @@ class Client extends EventEmitter { * Hook for sending messages to the client * @param {string} message the message to send */ - sendSelf(message) { - document.getElementById("client_ooclog").value += message + "\r\n"; + handleSelf(message) { const message_event = new MessageEvent('websocket', { data: message }); setTimeout(() => this.onMessage(message_event), 1); + } + + /** + * Hook for sending messages to the client + * @param {string} message the message to send + */ + sendSelf(message) { + document.getElementById("client_ooclog").value += message + "\r\n"; + this.handleSelf(message); } + /** * Sends an out-of-character chat message. * @param {string} message the message to send @@ -542,6 +551,22 @@ class Client extends EventEmitter { document.getElementById("client_chartable").innerHTML = ""; } + /** + * Parse the lines in the OOC and play them + * @param {*} args packet arguments + */ + handleReplay() { + const ooclog = document.getElementById("client_ooclog"); + const rtime = document.getElementById("client_replaytimer").value; + + const clines = ooclog.value.split(/\r?\n/); + if (clines[0]) { + this.handleSelf(clines[0]); + ooclog.value = clines.slice(1).join("\r\n"); + setTimeout(() => onReplayGo(""), rtime); + } + } + /** * Handles an in-character chat message. * @param {*} args packet arguments @@ -2159,6 +2184,15 @@ export function onOOCEnter(event) { } window.onOOCEnter = onOOCEnter; +/** + * Triggered when the user click replay GOOOOO + * @param {KeyboardEvent} event + */ +export function onReplayGo(_event) { + client.handleReplay(); +} +window.onReplayGo = onReplayGo; + /** * Triggered when the Return key is pressed on the in-character chat input box. * @param {KeyboardEvent} event -- cgit