restore orders library functionality

develop
Myk Taylor 2023-01-17 21:26:33 -08:00
parent bb3f640afa
commit acd2256900
No known key found for this signature in database
3 changed files with 10 additions and 14 deletions

@ -36,6 +36,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## New Plugins ## New Plugins
## Fixes ## Fixes
- `orders`: allow the orders library to be listed and imported properly (if you previously copied the orders library into your ``dfhack-config/orders`` directory to work around this bug, you can remove those files now)
## Misc Improvements ## Misc Improvements

@ -23,7 +23,7 @@ Usage
one-time orders first, then yearly, seasonally, monthly, and finally, daily. one-time orders first, then yearly, seasonally, monthly, and finally, daily.
You can keep your orders automatically sorted by adding the following command to You can keep your orders automatically sorted by adding the following command to
your ``onMapLoad.init`` file:: your ``dfhack-config/init/onMapLoad.init`` file::
repeat -name orders-sort -time 1 -timeUnits days -command [ orders sort ] repeat -name orders-sort -time 1 -timeUnits days -command [ orders sort ]

@ -41,7 +41,7 @@ DFHACK_PLUGIN("orders");
REQUIRE_GLOBAL(world); REQUIRE_GLOBAL(world);
static const std::string ORDERS_DIR = "dfhack-config/orders"; static const std::string ORDERS_DIR = "dfhack-config/orders";
static const std::string ORDERS_LIBRARY_DIR = "dfhack-config/orders/library"; static const std::string ORDERS_LIBRARY_DIR = "hack/data/orders";
static command_result orders_command(color_ostream & out, std::vector<std::string> & parameters); static command_result orders_command(color_ostream & out, std::vector<std::string> & parameters);
@ -86,6 +86,11 @@ static command_result orders_command(color_ostream & out, std::vector<std::strin
return orders_list_command(out); return orders_list_command(out);
} }
if (!Core::getInstance().isWorldLoaded()) {
out.printerr("Cannot run %s without a loaded world.\n", plugin_name);
return CR_FAILURE;
}
if (parameters[0] == "export" && parameters.size() == 2) if (parameters[0] == "export" && parameters.size() == 2)
{ {
return orders_export_command(out, parameters[1]); return orders_export_command(out, parameters[1]);
@ -139,19 +144,9 @@ static command_result orders_list_command(color_ostream & out)
// support subdirs so we can identify and ignore subdirs with ".json" names. // support subdirs so we can identify and ignore subdirs with ".json" names.
// also listdir_recursive will alphabetize the list for us. // also listdir_recursive will alphabetize the list for us.
std::map<std::string, bool> files; std::map<std::string, bool> files;
if (0 < Filesystem::listdir_recursive(ORDERS_DIR, files, 0, false)) Filesystem::listdir_recursive(ORDERS_DIR, files, 0, false);
{
out << COLOR_LIGHTRED << "Unable to list files in directory: " << ORDERS_DIR << std::endl;
return CR_FAILURE;
}
if (files.empty()) for (auto it : files) {
{
out << COLOR_YELLOW << "No exported orders yet. Create manager orders and export them with 'orders export <name>', or copy pre-made orders .json files into " << ORDERS_DIR << "." << std::endl << std::endl;
}
for (auto it : files)
{
if (it.second) if (it.second)
continue; // skip directories continue; // skip directories
std::string name = it.first; std::string name = it.first;