Skip to content

Commit f191334

Browse files
authored
Merge pull request #3027 from myk002/myk_buildingplan_reset
[buildingplan] add reset command for resetting all filters
2 parents 73e65f2 + b0f9ad6 commit f191334

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
4545
-@ `buildingplan`: you can now attach multiple weapons to spike traps
4646
-@ `buildingplan`: can now filter by whether a slab is engraved
4747
-@ `buildingplan`: add "minimize" button to temporarily get the planner overlay out of the way if you would rather use the vanilla UI for placing the current building
48+
-@ `buildingplan`: add ``buildingplan reset`` command for resetting all filters to defaults
4849
- `blueprint`: now writes blueprints to the ``dfhack-config/blueprints`` directory
4950
- `blueprint-library-guide`: library blueprints have moved from ``blueprints`` to ``hack/data/blueprints``
5051
- player-created blueprints should now go in the ``dfhack-config/blueprints`` folder. please move your existing blueprints from ``blueprints`` to ``dfhack-config/blueprints``. you don't need to move the library blueprints -- those can be safely deleted from the old ``blueprints`` directory.

docs/plugins/buildingplan.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Usage
6060

6161
buildingplan [status]
6262
buildingplan set <setting> (true|false)
63+
buildingplan reset
6364

6465
Examples
6566
--------
@@ -72,6 +73,10 @@ Examples
7273
When finding items to satisfy "building materials" requirements, don't
7374
select boulders. Use blocks or logs (if enabled) instead.
7475

76+
``buildingplan reset``
77+
Reset all settings and filters to their defaults. This command does not affect
78+
existing planned buildings.
79+
7580
.. _buildingplan-settings:
7681

7782
Global settings

plugins/buildingplan/buildingplan.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,24 @@ static void validate_config(color_ostream &out, bool verbose = false) {
261261
set_config_bool(config, CONFIG_BARS, false);
262262
}
263263

264-
static void clear_state(color_ostream &out) {
264+
static void reset_filters(color_ostream &out) {
265+
cur_heat_safety.clear();
266+
cur_item_filters.clear();
265267
call_buildingplan_lua(&out, "signal_reset");
266-
call_buildingplan_lua(&out, "reload_pens");
268+
}
269+
270+
static void clear_state(color_ostream &out) {
267271
planned_buildings.clear();
268272
tasks.clear();
269-
cur_heat_safety.clear();
270-
cur_item_filters.clear();
271273
for (auto &entry : job_item_cache ) {
272274
for (auto &jitem : entry.second) {
273275
delete jitem;
274276
}
275277
}
276278
job_item_cache.clear();
277279
mat_cache.clear();
280+
reset_filters(out);
281+
call_buildingplan_lua(&out, "reload_pens");
278282
}
279283

280284
DFhackCExport command_result plugin_load_data (color_ostream &out) {
@@ -582,6 +586,11 @@ static bool setSetting(color_ostream &out, string name, bool value) {
582586
return true;
583587
}
584588

589+
static void resetFilters(color_ostream &out) {
590+
DEBUG(status,out).print("entering resetFilters\n");
591+
reset_filters(out);
592+
}
593+
585594
static bool isPlannableBuilding(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom) {
586595
DEBUG(status,out).print("entering isPlannableBuilding\n");
587596
return get_num_filters(out, BuildingTypeKey(type, subtype, custom)) >= 1;
@@ -1104,6 +1113,7 @@ static void makeTopPriority(color_ostream &out, df::building *bld) {
11041113
DFHACK_PLUGIN_LUA_FUNCTIONS {
11051114
DFHACK_LUA_FUNCTION(printStatus),
11061115
DFHACK_LUA_FUNCTION(setSetting),
1116+
DFHACK_LUA_FUNCTION(resetFilters),
11071117
DFHACK_LUA_FUNCTION(isPlannableBuilding),
11081118
DFHACK_LUA_FUNCTION(isPlannedBuilding),
11091119
DFHACK_LUA_FUNCTION(addPlannedBuilding),

plugins/lua/buildingplan.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ function parse_commandline(...)
4242
printStatus()
4343
elseif command == 'set' and positionals then
4444
setSetting(positionals[1], positionals[2] == 'true')
45+
elseif command == 'reset' then
46+
resetFilters()
4547
else
4648
return false
4749
end

0 commit comments

Comments
 (0)