address review comments

develop
John Cosker 2023-05-01 14:20:53 -04:00
parent 6b7c90b676
commit 528dc466e2
3 changed files with 6 additions and 130 deletions

@ -77,8 +77,8 @@ set_source_files_properties( Brushes.h PROPERTIES HEADER_FILE_ONLY TRUE )
#dfhack_plugin(add-spatter add-spatter.cpp)
dfhack_plugin(autobutcher autobutcher.cpp LINK_LIBRARIES lua)
dfhack_plugin(autochop autochop.cpp LINK_LIBRARIES lua)
dfhack_plugin(autoclothing autoclothing.cpp LINK_LIBRARIES lua)
dfhack_plugin(design design.cpp LINK_LIBRARIES lua)
dfhack_plugin(autoclothing autoclothing.cpp)
dfhack_plugin(autodump autodump.cpp)
dfhack_plugin(autofarm autofarm.cpp)
#dfhack_plugin(autogems autogems.cpp LINK_LIBRARIES jsoncpp_static)

@ -30,131 +30,19 @@ using namespace df::enums;
enum ConfigValues {
CONFIG_IS_ENABLED = 0,
};
namespace DFHack {
// // for configuration-related logging
DBG_DECLARE(design, status, DebugCategory::LDEBUG);
// for logging during the periodic scan
DBG_DECLARE(design, cycle, DebugCategory::LDEBUG);
} // namespace DFHack
static const std::string CONFIG_KEY = std::string(plugin_name) + "/config";
static PersistentDataItem config;
static const int32_t CYCLE_TICKS = 1200;
static int32_t cycle_timestamp = 0; // world->frame_counter at last cycle
static command_result do_command(color_ostream &out,
std::vector<std::string> &parameters);
static int32_t do_cycle(color_ostream &out, bool force_designate = false);
DFhackCExport command_result plugin_init(color_ostream &out,
std::vector<PluginCommand> &commands) {
DEBUG(status, out).print("initializing %s\n", plugin_name);
// provide a configuration interface for the plugin
commands.push_back(PluginCommand(
plugin_name,
"Plugin to handle performance sensitive functions of gui/design",
do_command));
return CR_OK;
}
static int get_config_val(PersistentDataItem &c, int index) {
if (!c.isValid()) return -1;
return c.ival(index);
}
static bool get_config_bool(PersistentDataItem &c, int index) {
return get_config_val(c, index) == 1;
}
static void set_config_val(PersistentDataItem &c, int index, int value) {
if (c.isValid()) c.ival(index) = value;
}
static void set_config_bool(PersistentDataItem &c, int index, bool value) {
set_config_val(c, index, value ? 1 : 0);
}
DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) {
if (!Core::getInstance().isWorldLoaded()) {
out.printerr("Cannot enable %s without a loaded world.\n", plugin_name);
return CR_FAILURE;
namespace DFHack {
DBG_DECLARE(pathable, log, DebugCategory::LINFO);
}
if (enable != is_enabled) {
is_enabled = enable;
DEBUG(status, out)
.print("%s from the API; persisting\n",
is_enabled ? "enabled" : "disabled");
set_config_bool(config, CONFIG_IS_ENABLED, is_enabled);
if (enable) do_cycle(out, true);
} else {
DEBUG(status, out)
.print("%s from the API, but already %s; no action\n",
is_enabled ? "enabled" : "disabled",
is_enabled ? "enabled" : "disabled");
}
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands) {
return CR_OK;
}
DFhackCExport command_result plugin_shutdown(color_ostream &out) {
DEBUG(status, out).print("shutting down %s\n", plugin_name);
return CR_OK;
}
DFhackCExport command_result plugin_load_data(color_ostream &out) {
cycle_timestamp = 0;
config = World::GetPersistentData(CONFIG_KEY);
if (!config.isValid()) {
DEBUG(status, out).print("no config found in this save; initializing\n");
config = World::AddPersistentData(CONFIG_KEY);
set_config_bool(config, CONFIG_IS_ENABLED, is_enabled);
}
// we have to copy our enabled flag into the global plugin variable, but
// all the other state we can directly read/modify from the persistent
// data structure.
is_enabled = get_config_bool(config, CONFIG_IS_ENABLED);
DEBUG(status, out)
.print("loading persisted enabled state: %s\n",
is_enabled ? "true" : "false");
return CR_OK;
}
DFhackCExport command_result plugin_onstatechange(color_ostream &out,
state_change_event event) {
if (event == DFHack::SC_WORLD_UNLOADED) {
if (is_enabled) {
DEBUG(status, out).print("world unloaded; disabling %s\n", plugin_name);
is_enabled = false;
}
}
return CR_OK;
}
DFhackCExport command_result plugin_onupdate(color_ostream &out) {
if (is_enabled && world->frame_counter - cycle_timestamp >= CYCLE_TICKS) {
int32_t ret = do_cycle(out);
}
return CR_OK;
}
int selected_tile_texpos = 0;
const static bool hi =
Screen::findGraphicsTile("CURSORS", 4, 3, &selected_tile_texpos);
static command_result do_command(color_ostream &out,
std::vector<std::string> &parameters) {
return CR_OK;
}
static int32_t do_cycle(color_ostream &out, bool force_designate) { return 0; }
std::map<uint32_t, Screen::Pen> PENS;
struct DrawingPoint {

@ -1,15 +1,3 @@
local _ENV = mkmodule('plugins.design')
function draw_shape(arr)
design_draw_shape(arr)
end
function draw_points(points_obj)
design_draw_points(points_obj)
end
function clear_shape(arr)
design_clear_shape(arr)
end
return _ENV