diff options
| author | RblSb <msrblsb@gmail.com> | 2020-02-22 07:26:52 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2020-02-22 07:26:52 +0300 |
| commit | 9fda2015a00b21911ef031cc5bfb0ea2e27d3d7f (patch) | |
| tree | ef540016f3e0391c19e3f9dc1afd3776baa388e1 /src/client/Main.hx | |
| parent | 08d068181045f91f0aa160f9b088a18048b948ec (diff) | |
Rewind command
Diffstat (limited to 'src/client/Main.hx')
| -rw-r--r-- | src/client/Main.hx | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/client/Main.hx b/src/client/Main.hx index f9232eb..dc5a803 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -201,6 +201,8 @@ class Main { final time = player.getTime(); if (Math.abs(time - newTime) < 2) return; player.setTime(newTime); + case Rewind: + player.setTime(data.rewind.time); case SetLeader: clients.setLeader(data.setLeader.clientName); updateUserList(); @@ -366,8 +368,12 @@ class Main { nameDiv.innerHTML = name + ": "; final textDiv = document.createSpanElement(); - for (filter in filters) { - text = filter.regex.replace(text, filter.replace); + if (text.startsWith("/")) { + if (name == personal.name) handleCommands(text.substr(1)); + } else { + for (filter in filters) { + text = filter.regex.replace(text, filter.replace); + } } textDiv.innerHTML = text; @@ -380,7 +386,7 @@ class Main { while (msgBuf.children.length > 200) msgBuf.removeChild(msgBuf.firstChild); msgBuf.scrollTop = msgBuf.scrollHeight; } - if (personal.name == name) { + if (name == personal.name) { msgBuf.scrollTop = msgBuf.scrollHeight; } if (document.hidden && onBlinkTab == null) { @@ -394,6 +400,20 @@ class Main { } } + final matchNumbers = ~/^-?[0-9]+$/; + + function handleCommands(text:String):Void { + switch (text) { + case "clear": + if (isAdmin()) send({type: ClearChat}); + } + if (matchNumbers.match(text)) { + send({type: Rewind, rewind: { + time: Std.parseInt(text) + }}); + } + } + function setLeaderButton(flag:Bool):Void { final leaderBtn = ge("#leader_btn"); if (isLeader()) { |
