summaryrefslogtreecommitdiff
path: root/src/squeltch.cc
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 /src/squeltch.cc
parent25d4950957f86d0c31f77c2a0b39d918cad51a5f (diff)
Automatizer: Rework to use player-specific .atm file by default
Diffstat (limited to 'src/squeltch.cc')
-rw-r--r--src/squeltch.cc24
1 files changed, 12 insertions, 12 deletions
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;
}