Improve the range function of tiletypes a bit and add the functionality to liquids.

develop
Jared Adams 2012-04-19 21:13:07 -06:00
parent f97e2bf410
commit 52138d8998
3 changed files with 86 additions and 57 deletions

@ -196,12 +196,60 @@ private:
Core *c_;
};
inline std::ostream &operator<<(std::ostream &stream, const Brush& brush) {
command_result parseRectangle(color_ostream & out,
int & width, int & height, int & zLevels,
int oldWidth, int oldHeight, int oldZLevels,
bool hasConsole = true)
{
out << "Parse:" << endl
<< "\tW:" << width << " - " << oldWidth << endl
<< "\tW:" << height << " - " << oldHeight << endl
<< "\tW:" << zLevels << " - " << oldZLevels << endl
<< "Console: " << hasConsole << endl;
if (width < 1 || height < 1) {
if (hasConsole) {
string command = "";
std::stringstream str;
Console &con = static_cast<Console&>(out);
CommandHistory hist;
str.str("");
str << "Set range width <" << oldWidth << "> ";
con.lineedit(str.str(), command, hist);
hist.add(command);
width = command == "" ? oldWidth : atoi(command.c_str());
str.str("");
str << "Set range height <" << oldHeight << "> ";
con.lineedit(str.str(), command, hist);
hist.add(command);
height = command == "" ? oldHeight : atoi(command.c_str());
str.str("");
str << "Set range z-levels <" << oldZLevels << "> ";
con.lineedit(str.str(), command, hist);
hist.add(command);
zLevels = command == "" ? oldZLevels : atoi(command.c_str());
} else {
return CR_WRONG_USAGE;
}
}
width = width < 1? 1 : width;
height = height < 1? 1 : height;
zLevels = zLevels < 1? 1 : zLevels;
return CR_OK;
}
inline std::ostream &operator<<(std::ostream &stream, const Brush& brush)
{
stream << brush.str();
return stream;
}
inline std::ostream &operator<<(std::ostream &stream, const Brush* brush) {
inline std::ostream &operator<<(std::ostream &stream, const Brush* brush)
{
stream << brush->str();
return stream;
}

@ -107,22 +107,27 @@ command_result df_liquids (color_ostream &out_, vector <string> & parameters)
return CR_FAILURE;
}
std::vector<std::string> commands;
bool end = false;
out << "Welcome to the liquid spawner.\nType 'help' or '?' for a list of available commands, 'q' to quit.\nPress return after a command to confirm." << std::endl;
while(!end)
{
string command = "";
string input = "";
std::stringstream str;
str <<"[" << mode << ":" << brushname;
if (brushname == "range")
str << "(w" << width << ":h" << height << ":z" << z_levels << ")";
str << ":" << amount << ":" << flowmode << ":" << setmode << "]#";
if(out.lineedit(str.str(),command,liquids_hist) == -1)
if(out.lineedit(str.str(),input,liquids_hist) == -1)
return CR_FAILURE;
liquids_hist.add(command);
liquids_hist.add(input);
commands.clear();
Core::cheap_tokenise(input, commands);
string command = commands.empty() ? "" : commands[0];
if(command=="help" || command == "?")
{
@ -195,27 +200,27 @@ command_result df_liquids (color_ostream &out_, vector <string> & parameters)
}
else if(command == "range" || command == "r")
{
std::stringstream str;
CommandHistory range_hist;
str << " :set range width<" << width << "># ";
out.lineedit(str.str(),command,range_hist);
range_hist.add(command);
width = command == "" ? width : atoi (command.c_str());
if(width < 1) width = 1;
str.str("");
str << " :set range height<" << height << "># ";
out.lineedit(str.str(),command,range_hist);
range_hist.add(command);
height = command == "" ? height : atoi (command.c_str());
if(height < 1) height = 1;
str.str("");
str << " :set range z-levels<" << z_levels << "># ";
out.lineedit(str.str(),command,range_hist);
range_hist.add(command);
z_levels = command == "" ? z_levels : atoi (command.c_str());
if(z_levels < 1) z_levels = 1;
int oldWidth = width, oldHeight = height, oldZLevels = z_levels;
width = height = z_levels = 0;
if (commands.size() >= 3)
{
width = atoi(commands[1].c_str());
height = atoi(commands[2].c_str());
if (commands.size() >= 4) {
z_levels = atoi(commands[3].c_str());
}
}
command_result res = parseRectangle(out, width, height, z_levels,
oldWidth, oldHeight, oldZLevels);
if (res != CR_OK)
{
return res;
}
if (width == 1 && height == 1 && z_levels == 1)
{
brushname = "point";

@ -819,46 +819,22 @@ command_result processCommand(color_ostream &out, std::vector<std::string> &comm
{
int width = 0, height = 0, z_levels = 0;
if (commands.size() > loc + 1)
if (commands.size() >= loc)
{
width = toint(commands[loc++]);
height = toint(commands[loc++]);
if (commands.size() > loc) {
if (commands.size() >= loc) {
z_levels = toint(commands[loc++]);
}
}
if (width < 1 || height < 1) {
width = width < 1? 1 : width;
height = height < 1? 1 : height;
z_levels = z_levels < 1? 1 : z_levels;
if (hasConsole) {
Console &con = static_cast<Console&>(out);
CommandHistory hist;
ss_o << "Set range width <" << width << "> ";
con.lineedit(ss_o.str(),command,hist);
width = command == "" ? width : toint(command);
ss_o.str("");
ss_o << "Set range height <" << height << "> ";
con.lineedit(ss_o.str(),command,hist);
height = command == "" ? height : toint(command);
ss_o.str("");
ss_o << "Set range z-levels <" << z_levels << "> ";
con.lineedit(ss_o.str(),command,hist);
z_levels = command == "" ? z_levels : toint(command);
} else {
return CR_WRONG_USAGE;
}
command_result res = parseRectangle(out, width, height, z_levels, width, height, z_levels, hasConsole);
if (res != CR_OK)
{
return res;
}
width = width < 1? 1 : width;
height = height < 1? 1 : height;
z_levels = z_levels < 1? 1 : z_levels;
delete brush;
brush = new RectangleBrush(width, height, z_levels, 0, 0, 0);
}