|
|
|
@ -9,6 +9,7 @@
|
|
|
|
|
|
|
|
|
|
#include "../uicommon.h"
|
|
|
|
|
|
|
|
|
|
#include "StockpileUtils.h"
|
|
|
|
|
#include "StockpileSerializer.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -25,11 +26,6 @@
|
|
|
|
|
#include "df/global_objects.h"
|
|
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// os
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
|
|
// stl
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <vector>
|
|
|
|
@ -98,19 +94,13 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <Plug
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::cerr << "world: " << sizeof ( df::world ) << " ui: " << sizeof ( df::ui )
|
|
|
|
|
<< " b_stock: " << sizeof ( building_stockpilest ) << endl;
|
|
|
|
|
|
|
|
|
|
if (!Filesystem::isdir("stocksettings"))
|
|
|
|
|
if ( !Filesystem::isdir ( "stocksettings" ) )
|
|
|
|
|
{
|
|
|
|
|
if (!Filesystem::mkdir("stocksettings"))
|
|
|
|
|
{
|
|
|
|
|
out.printerr("stockpiles: could not create stocksettings directory!\n");
|
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// ViewscreenStocks::reset();
|
|
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
@ -125,7 +115,6 @@ DFhackCExport command_result plugin_onstatechange ( color_ostream &out, state_ch
|
|
|
|
|
switch ( event )
|
|
|
|
|
{
|
|
|
|
|
case SC_MAP_LOADED:
|
|
|
|
|
// ViewscreenStocks::reset();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
@ -222,23 +211,6 @@ static bool loadstock_guard ( df::viewscreen *top )
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool file_exists ( const std::string& filename )
|
|
|
|
|
{
|
|
|
|
|
struct stat buf;
|
|
|
|
|
if ( stat ( filename.c_str(), &buf ) != -1 )
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool is_dfstockfile ( const std::string& filename )
|
|
|
|
|
{
|
|
|
|
|
return filename.rfind ( ".dfstock" ) != std::string::npos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// exporting
|
|
|
|
|
static command_result savestock ( color_ostream &out, vector <string> & parameters )
|
|
|
|
|
{
|
|
|
|
@ -317,7 +289,7 @@ static command_result loadstock ( color_ostream &out, vector <string> & paramete
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !is_dfstockfile ( file ) ) file += ".dfstock";
|
|
|
|
|
if ( file.empty() || !file_exists ( file ) )
|
|
|
|
|
if ( file.empty() || !Filesystem::exists ( file ) )
|
|
|
|
|
{
|
|
|
|
|
out.printerr ( "loadstock: a .dfstock file is required to import\n" );
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
@ -334,10 +306,11 @@ static command_result loadstock ( color_ostream &out, vector <string> & paramete
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* calls the lua function manage_settings() to kickoff the GUI
|
|
|
|
|
*/
|
|
|
|
|
bool manage_settings ( building_stockpilest *sp )
|
|
|
|
|
{
|
|
|
|
|
// Find strings representing the job to order, and the trigger condition.
|
|
|
|
|
// There might be a memory leak here; C++ is odd like that.
|
|
|
|
|
auto L = Lua::Core::State;
|
|
|
|
|
color_ostream_proxy out ( Core::getInstance().getConsole() );
|
|
|
|
|
|
|
|
|
@ -395,7 +368,6 @@ struct stockpiles_import_hook : public df::viewscreen_dwarfmodest
|
|
|
|
|
int left_margin = dims.menu_x1 + 1;
|
|
|
|
|
int x = left_margin;
|
|
|
|
|
int y = dims.y2 - 7;
|
|
|
|
|
int y2 = dims.y2 - 8;
|
|
|
|
|
|
|
|
|
|
int links = 0;
|
|
|
|
|
links += sp->links.give_to_pile.size();
|
|
|
|
@ -405,7 +377,6 @@ struct stockpiles_import_hook : public df::viewscreen_dwarfmodest
|
|
|
|
|
if ( links + 12 >= y )
|
|
|
|
|
{
|
|
|
|
|
y += 1;
|
|
|
|
|
y2 += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutputHotkeyString ( x, y, "Load/Save Settings", "l", true, left_margin, COLOR_WHITE, COLOR_LIGHTRED );
|
|
|
|
@ -477,6 +448,10 @@ static std::vector<std::string> list_dir ( const std::string &path, bool recursi
|
|
|
|
|
|
|
|
|
|
static std::vector<std::string> clean_dfstock_list ( const std::string &path )
|
|
|
|
|
{
|
|
|
|
|
if ( !Filesystem::exists ( path ) )
|
|
|
|
|
{
|
|
|
|
|
return std::vector<std::string>();
|
|
|
|
|
}
|
|
|
|
|
std::vector<std::string> files ( list_dir ( path, true) );
|
|
|
|
|
files.erase ( std::remove_if ( files.begin(), files.end(), [] ( const std::string &f )
|
|
|
|
|
{
|
|
|
|
@ -486,16 +461,23 @@ static std::vector<std::string> clean_dfstock_list ( const std::string &path )
|
|
|
|
|
{
|
|
|
|
|
return f.substr ( 0, f.find_last_of ( "." ) );
|
|
|
|
|
} );
|
|
|
|
|
std::sort ( files.begin(),files.end(), CompareNoCase );
|
|
|
|
|
return files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int stockpiles_list_settings ( lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
auto path = luaL_checkstring ( L, 1 );
|
|
|
|
|
if ( !Filesystem::exists ( path ) )
|
|
|
|
|
{
|
|
|
|
|
lua_pushfstring ( L, "stocksettings path invalid: %s", path );
|
|
|
|
|
lua_error ( L );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
color_ostream &out = *Lua::GetOutput ( L );
|
|
|
|
|
if ( !Filesystem::isdir(path) )
|
|
|
|
|
{
|
|
|
|
|
lua_pushfstring ( L, "invalid directory: %s", path );
|
|
|
|
|
lua_pushfstring ( L, "stocksettings path invalid: %s", path );
|
|
|
|
|
lua_error ( L );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -507,6 +489,11 @@ static int stockpiles_list_settings ( lua_State *L )
|
|
|
|
|
static void stockpiles_load ( color_ostream &out, std::string filename )
|
|
|
|
|
{
|
|
|
|
|
out << "stockpiles_load " << filename << " ";
|
|
|
|
|
if ( !Filesystem::exists ( filename ) )
|
|
|
|
|
{
|
|
|
|
|
out.printerr ( "invalid file: %s\n", filename.c_str() );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
std::vector<std::string> params;
|
|
|
|
|
params.push_back ( filename );
|
|
|
|
|
command_result r = loadstock ( out, params );
|
|
|
|
@ -524,9 +511,10 @@ static void stockpiles_save ( color_ostream &out, std::string filename )
|
|
|
|
|
out << " result = "<< r << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DFHACK_PLUGIN_LUA_FUNCTIONS {
|
|
|
|
|
DFHACK_LUA_FUNCTION(stockpiles_load),
|
|
|
|
|
DFHACK_LUA_FUNCTION(stockpiles_save),
|
|
|
|
|
DFHACK_PLUGIN_LUA_FUNCTIONS
|
|
|
|
|
{
|
|
|
|
|
DFHACK_LUA_FUNCTION ( stockpiles_load ),
|
|
|
|
|
DFHACK_LUA_FUNCTION ( stockpiles_save ),
|
|
|
|
|
DFHACK_LUA_END
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|