]> git.cworth.org Git - empires-server/commitdiff
empathy: Don't allow a prompt with 0 items
authorCarl Worth <cworth@cworth.org>
Mon, 29 Jun 2020 20:52:10 +0000 (13:52 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 29 Jun 2020 20:52:10 +0000 (13:52 -0700)
Thanks to my clever nephews for finding this degenerate case that I
had missed when coding this up originally.

empathy.js

index a3faf5b11355f835b6b975958ed64ef5581002c9..c1d150f354d9bb4207f985b7da65540d4caa8ccd 100644 (file)
@@ -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++;