|
|
|
@ -393,6 +393,26 @@ static bool try_autocomplete(color_ostream &con, const std::string &first, std::
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string findScript(string path, string name) {
|
|
|
|
|
//first try the save folder if it exists
|
|
|
|
|
string save = World::ReadWorldFolder();
|
|
|
|
|
if ( save != "" ) {
|
|
|
|
|
string file = path + "/data/save/" + save + "/raw/scripts/" + name;
|
|
|
|
|
if (fileExists(file)) {
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string file = path + "/raw/scripts/" + name;
|
|
|
|
|
if (fileExists(file)) {
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
file = path + "/hack/scripts/" + name;
|
|
|
|
|
if (fileExists(file)) {
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command_result Core::runCommand(color_ostream &con, const std::string &first, vector<string> &parts)
|
|
|
|
|
{
|
|
|
|
|
if (!first.empty())
|
|
|
|
@ -446,19 +466,21 @@ command_result Core::runCommand(color_ostream &con, const std::string &first, ve
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
auto filename = getHackPath() + "scripts/" + parts[0];
|
|
|
|
|
if (fileExists(filename + ".lua"))
|
|
|
|
|
{
|
|
|
|
|
string help = getScriptHelp(filename + ".lua", "-- ");
|
|
|
|
|
string path = this->p->getPath();
|
|
|
|
|
string file = findScript(path, parts[0] + ".lua");
|
|
|
|
|
if ( file != "" ) {
|
|
|
|
|
string help = getScriptHelp(file, "-- ");
|
|
|
|
|
con.print("%s: %s\n", parts[0].c_str(), help.c_str());
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
if (plug_mgr->ruby && plug_mgr->ruby->is_enabled() && fileExists(filename + ".rb"))
|
|
|
|
|
{
|
|
|
|
|
string help = getScriptHelp(filename + ".rb", "# ");
|
|
|
|
|
if (plug_mgr->ruby && plug_mgr->ruby->is_enabled() ) {
|
|
|
|
|
file = findScript(path, parts[0] + ".rb");
|
|
|
|
|
if ( file != "" ) {
|
|
|
|
|
string help = getScriptHelp(file, "# ");
|
|
|
|
|
con.print("%s: %s\n", parts[0].c_str(), help.c_str());
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
con.printerr("Unknown command: %s\n", parts[0].c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -765,15 +787,19 @@ command_result Core::runCommand(color_ostream &con, const std::string &first, ve
|
|
|
|
|
command_result res = plug_mgr->InvokeCommand(con, first, parts);
|
|
|
|
|
if(res == CR_NOT_IMPLEMENTED)
|
|
|
|
|
{
|
|
|
|
|
auto filename = getHackPath() + "scripts/" + first;
|
|
|
|
|
std::string completed;
|
|
|
|
|
|
|
|
|
|
if (fileExists(filename + ".lua"))
|
|
|
|
|
string completed;
|
|
|
|
|
string path = this->p->getPath();
|
|
|
|
|
string filename = findScript(path, first + ".lua");
|
|
|
|
|
bool lua = filename != "";
|
|
|
|
|
if ( !lua ) {
|
|
|
|
|
filename = findScript(path, first + ".rb");
|
|
|
|
|
}
|
|
|
|
|
if ( lua )
|
|
|
|
|
res = runLuaScript(con, first, parts);
|
|
|
|
|
else if (plug_mgr->ruby && plug_mgr->ruby->is_enabled() && fileExists(filename + ".rb"))
|
|
|
|
|
else if ( filename != "" && plug_mgr->ruby && plug_mgr->ruby->is_enabled() )
|
|
|
|
|
res = runRubyScript(con, plug_mgr, first, parts);
|
|
|
|
|
else if ( try_autocomplete(con, first, completed) )
|
|
|
|
|
return CR_NOT_IMPLEMENTED;// runCommand(con, completed, parts);
|
|
|
|
|
return CR_NOT_IMPLEMENTED;
|
|
|
|
|
else
|
|
|
|
|
con.printerr("%s is not a recognized command.\n", first.c_str());
|
|
|
|
|
}
|
|
|
|
|