From 2507e38739e465eb7d8c669939febeaa4e6f3c02 Mon Sep 17 00:00:00 2001 From: raeleus Date: Sun, 29 Sep 2024 12:12:09 -0700 Subject: [PATCH] Allow #deletenote to erase more than one note at a time. Resolve #20 --- Input.js | 28 +++++++++++++++++++--------- Output.js | 3 ++- README.md | 1 + 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Input.js b/Input.js index 4ba498f..aec3288 100644 --- a/Input.js +++ b/Input.js @@ -709,7 +709,7 @@ function doSetDefaultDifficulty(command) { difficultyPatternNames.push("\\d+") var difficulty = getArgument(command, 0) if (difficulty == null) difficulty = "easy" - + var difficultyIndex = difficultyNames.indexOf(difficulty) if (difficultyIndex >= 0 && difficultyIndex < difficultyNames.length) { difficulty = difficultyScores[difficultyIndex] @@ -1716,18 +1716,28 @@ function doClearInventory(command) { } function doEraseNote(command) { - var arg0 = getArgument(command, 0) + var arg0 = getArgumentRemainder(command, 0) if (arg0 == null) arg0 = 1 - arg0 = parseInt(arg0) - 1 - if (arg0 >= state.notes.length) { - state.show = "none" - return "\n[Error: Note does not exist. Call #showNotes.]\n" - } + var list = arg0.split(/\D/) + list.sort(function(a, b) { + return b - a; + }); - state.notes.splice(arg0, 1) + var text = "\n" + list.forEach(x => { + var num = parseInt(x) - 1 + if (num >= state.notes.length) { + state.show = "none" + return `\n[Error: Note ${x} does not exist. Call #showNotes.]\n` + } + + state.notes.splice(num, 1) + text += `[Note #${x} removed]\n` + }) + state.show = "none" - return `[Note #${arg0 + 1} removed]` + return text } function doRemoveCharacter(command) { diff --git a/Output.js b/Output.js index 8f073cd..f84047f 100644 --- a/Output.js +++ b/Output.js @@ -102,6 +102,7 @@ const modifier = (text) => { state.notes.forEach(function(x) { text += `\n${counter++}. ${x}` }) + if (state.notes.length == 0) text += "\nThere are no notes!" text += "\n**************\n\n" break case "clearNotes": @@ -198,7 +199,7 @@ const modifier = (text) => { text += "\n#clearnotes" text += "\n Removes all notes." text += "\n#removenote value" - text += "\n Removes the specified note as indicated by the number listed in #shownotes." + text += "\n Removes the specified note as indicated by the number listed in #shownotes. To delete multiple notes, type the numbers with spaces or commas between them. This is safer than calling #removenote multiple times because the numbers shift as notes are deleted." text += "\n\n--Characters--" text += "\n#setup" diff --git a/README.md b/README.md index 9637e1a..554a116 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ v. 0.1.0 * Added `#renameitem` to rename an existing item * Added `#renamecharacter` to rename an existing character * Added `#clonecharacter` to copy an existing character +* `#removenote` can remove more than one note at a time * Minor bug fixes and improvements v. 0.0.6