Don't repeat dump_order fields
authoradvil <rawlins@gmail.com>
Fri, 31 Jul 2020 17:00:51 +0000 (13:00 -0400)
committeradvil <rawlins@gmail.com>
Fri, 31 Jul 2020 17:04:52 +0000 (13:04 -0400)
I can't think of a good use case for repeating dump_order fields, and
allowing it seems to cause more annoyance than anything whenever we
change the defaults, or have an alpha-only default (as is currently the
case with turns_by_level). This version uses the first instance in an
order, so if you want to reorder the defaults it will require removing
and then re-adding.

There's no elegant implementation of arbitrary order + unique elements
in c++ that I know of, and simply keeping two data structures seemed
like the least unaesthetic to me.

crawl-ref/source/initfile.cc
crawl-ref/source/options.h

index 8c24b44..d9c49bd 100644 (file)
@@ -811,11 +811,18 @@ void game_options::new_dump_fields(const string &text, bool add, bool prepend)
     // Easy; chardump.cc has most of the intelligence.
     vector<string> fields = split_string(",", text, true, true);
     if (add)
+    {
+        erase_if(fields, [this](const string &x) { return dump_fields.count(x) > 0; });
+        dump_fields.insert(fields.begin(), fields.end());
         merge_lists(dump_order, fields, prepend);
+    }
     else
     {
         for (const string &field : fields)
+        {
+            dump_fields.erase(field);
             erase_val(dump_order, field);
+        }
     }
 }
 
@@ -1155,6 +1162,7 @@ void game_options::reset_options()
 
     // Clear vector options.
     dump_order.clear();
+    dump_fields.clear();
     new_dump_fields("header,hiscore,stats,misc,inventory,"
                     "skills,spells,overview,mutations,messages,"
                     "screenshot,monlist,kills,notes,screenshots,vaults,"
@@ -3278,7 +3286,10 @@ void game_options::read_option_line(const string &str, bool runscript)
     else if (key == "dump_order")
     {
         if (plain)
+        {
+            dump_fields.clear();
             dump_order.clear();
+        }
 
         new_dump_fields(field, !minus_equal, caret_equal);
     }
index f999f1b..9e285b5 100644 (file)
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <algorithm>
+#include <unordered_set>
 
 #include "activity-interrupt-type.h"
 #include "char-set-type.h"
@@ -400,6 +401,7 @@ public:
     int         dump_item_origins;  // Show where items came from?
     int         dump_item_origin_price;
 
+    unordered_set<string> dump_fields;
     // Order of sections in the character dump.
     vector<string> dump_order;