summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2015-04-14 06:39:21 +0200
committerBardur Arantsson <bardur@scientician.net>2015-04-14 06:39:21 +0200
commit08ff08397681d6839bae1fac89f86e1fa7bab289 (patch)
tree208ee16ee33b85c5a03a0874c6acefef742fb6a5
parent25d4950957f86d0c31f77c2a0b39d918cad51a5f (diff)
Automatizer: Rework to use player-specific .atm file by default
-rw-r--r--src/dungeon.cc21
-rw-r--r--src/init2.cc4
-rw-r--r--src/squeltch.cc24
-rw-r--r--src/squeltch.hpp3
4 files changed, 29 insertions, 23 deletions
diff --git a/src/dungeon.cc b/src/dungeon.cc
index 953ea536..abcc6cae 100644
--- a/src/dungeon.cc
+++ b/src/dungeon.cc
@@ -62,6 +62,7 @@
#include "xtra1.hpp"
#include "xtra2.hpp"
+#include <boost/filesystem.hpp>
#include <cassert>
#define TY_CURSE_CHANCE 100
@@ -5077,12 +5078,20 @@ static void load_all_pref_files(void)
/* Process that file */
process_pref_file(buf);
- /* Process player specific automatizer sets */
- /* TODO: Disabled temporarily because it causes duplicate
- * rules on save and subsequent game load. */
- /* sprintf(buf2, "%s.atm", player_name); */
- /* path_build(buf, sizeof(buf), ANGBAND_DIR_USER, buf2); */
- /* automatizer_load(buf); */
+ /* Load automatizer settings. Character-specific automatizer
+ * file gets priority over the "template" file. We do not try
+ * to merge the two files since that would require tracking
+ * the providence of rules and such to avoid the same
+ * duplication problems as caused when saving macros/keymaps. */
+ boost::filesystem::path userDirectory(ANGBAND_DIR_USER);
+ if (automatizer_load(userDirectory / (std::string(player_name) + ".atm")))
+ {
+ // Done
+ }
+ else if (automatizer_load(userDirectory / "automat.atm"))
+ {
+ // Done
+ }
}
/*
diff --git a/src/init2.cc b/src/init2.cc
index 7fe78d73..a0616434 100644
--- a/src/init2.cc
+++ b/src/init2.cc
@@ -2247,10 +2247,6 @@ void init_angband(void)
/* Process that file */
process_pref_file(buf);
- /* Load automatizer rules */
- path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "automat.atm");
- automatizer_load(buf);
-
/* Done */
note("[Initialisation complete]");
}
diff --git a/src/squeltch.cc b/src/squeltch.cc
index 4b2fd0b7..37b0f0fe 100644
--- a/src/squeltch.cc
+++ b/src/squeltch.cc
@@ -174,7 +174,8 @@ static void automatizer_save_rules()
Term_get_size(&wid, &hgt);
- sprintf(name, "automat.atm");
+ sprintf(name, "%s.atm", player_name);
+
if (!input_box("Save name?", hgt / 2, wid / 2, name, sizeof(name)))
{
return;
@@ -562,34 +563,33 @@ void automatizer_init()
}
/**
- * Load automatizer file. This function may be called multiple times
- * with different file names -- it should NOT clear any automatizer
- * state (including loaded rules).
+ * Load automatizer file. Returns true iff automatizer
+ * rules were loaded successfully.
*/
-void automatizer_load(cptr file_path)
+bool automatizer_load(boost::filesystem::path const &path)
{
- assert(file_path != NULL);
assert(automatizer != NULL);
- // Does the file exist?
- if (!file_exist(file_path))
+ // Does the path exist?
+ if (!boost::filesystem::exists(path))
{
- return; // Not fatal; just skip
+ return false; // Not fatal; just skip
}
// Parse file
json_error_t error;
std::shared_ptr<json_t> rules_json(
- json_load_file(file_path, 0, &error),
+ json_load_file(path.c_str(), 0, &error),
&json_decref);
if (rules_json == nullptr)
{
- msg_format("Error parsing automatizer rules from '%s'.", file_path);
+ msg_format("Error parsing automatizer rules from '%s'.", path.c_str());
msg_format("Line %d, Column %d", error.line, error.column);
msg_print(nullptr);
- return;
+ return false;
}
// Load rules
automatizer->load_json(rules_json.get());
+ return true;
}
diff --git a/src/squeltch.hpp b/src/squeltch.hpp
index 0d311d61..7c80c111 100644
--- a/src/squeltch.hpp
+++ b/src/squeltch.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "angband.h"
+#include <boost/filesystem.hpp>
extern void squeltch_inventory(void);
extern void squeltch_grid(void);
@@ -8,5 +9,5 @@ extern void do_cmd_automatizer(void);
extern void automatizer_add_rule(object_type *o_ptr);
extern bool_ automatizer_create;
extern void automatizer_init();
-extern void automatizer_load(cptr file_name);
+extern bool automatizer_load(boost::filesystem::path const &path);