From: Carl Worth Date: Mon, 29 Jun 2020 20:52:10 +0000 (-0700) Subject: empathy: Don't allow a prompt with 0 items X-Git-Url: https://git.cworth.org/git?p=empires-server;a=commitdiff_plain;h=771e0ce4711a7ed723d216c28ab8d1472463d3ef empathy: Don't allow a prompt with 0 items Thanks to my clever nephews for finding this degenerate case that I had missed when coding this up originally. --- diff --git a/empathy.js b/empathy.js index a3faf5b..c1d150f 100644 --- a/empathy.js +++ b/empathy.js @@ -115,11 +115,19 @@ class Empathy extends Game { } add_prompt(items, prompt_string) { - if (items > MAX_PROMPT_ITEMS) + if (items > MAX_PROMPT_ITEMS) { return { valid: false, message: `Maximum number of items is ${MAX_PROMPT_ITEMS}` }; + } + + if (items < 1) { + return { + valid: false, + message: "Category must require at least one item" + }; + } const prompt = new Prompt(this.next_prompt_id, items, prompt_string); this.next_prompt_id++;