From 21eb36a1ad639f87d5f20064ef63da5ac2869904 Mon Sep 17 00:00:00 2001 From: haliphax Date: Wed, 24 Nov 2021 10:00:24 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20arguments=20for=20clearscores=20com?= =?UTF-8?q?mand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- drop-game/static/game.js | 15 +++++++++++++++ drop-game/static/index.js | 5 +++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9c2f6bb..074c717 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ connected. Some require that the user be either a moderator or the broadcaster. | Command | Access | Description | |---------|--------|-------------| -| `!clearscores` | Moderator | Reset the overlay's localStorage, clearing all score records. | +| `!clearscores [username] [username...]` | Moderator | Reset the overlay's localStorage, clearing score records. If no usernames are provided, all records are wiped. | | `!drop` | Everyone | Play the game! | | `!droplow` | Everyone | Show the lowest score from the last 24 hours. | | `!droprecent` | Everyone | Show the most recent drop scores. | diff --git a/drop-game/static/game.js b/drop-game/static/game.js index e4a8e96..c2e9b4a 100644 --- a/drop-game/static/game.js +++ b/drop-game/static/game.js @@ -24,6 +24,7 @@ export default class Game extends Phaser.Scene { emitter.on('droplow', this.onDropLow, this); emitter.on('droprecent', this.onDropRecent, this); emitter.on('droptop', this.onDropTop, this); + emitter.on('clearscores', this.onClearScores, this); emitter.on('lose', this.onLose, this); emitter.on('queuedrop', this.onQueueDrop, this); emitter.on('resetdrop', this.onResetDrop, this); @@ -33,6 +34,7 @@ export default class Game extends Phaser.Scene { this.tidyScores(); } + /** @type {Score[]} */ get scores() { return JSON.parse(localStorage.getItem('scores') || '[]'); } @@ -307,6 +309,19 @@ export default class Game extends Phaser.Scene { `Poooound Highest score in the past 24 hours: ${highest.username} ${highest.score.toFixed(2)}`); } + onClearScores(who) { + if (!who) { + localStorage.clear(); + twitch.say(qs.channel, 'Scores cleared.'); + } + else { + const update = this.scores.filter( + v => !who.includes(v.username.toLowerCase())); + localStorage.setItem('scores', JSON.stringify(update)); + twitch.say(qs.channel, `Scores cleared for ${who.join(', ')}.`); + } + } + onLose(avatar) { this.resetTimer(); avatar.container.body.enable = false; diff --git a/drop-game/static/index.js b/drop-game/static/index.js index f733666..78587ec 100644 --- a/drop-game/static/index.js +++ b/drop-game/static/index.js @@ -46,8 +46,9 @@ twitch.on('message', (channel, tags, message, self) => { if (!isBroadcaster(tags) && !isModerator(tags)) return; - localStorage.clear(); - twitch.say(qs.channel, 'Scores cleared.'); + const who = args ? args.split(' ').map(v => v.toLowerCase()) : null; + + emitter.emit('clearscores', who); break; case 'drop': emitter.emit('drop', tags['display-name']);