1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 20:53:50 +00:00

Issue #352: added --script-run switch

This commit is contained in:
Marc Zinnschlag 2012-07-30 12:37:46 +02:00
parent 23f8595b87
commit fd6c155118
7 changed files with 43 additions and 0 deletions

View file

@ -390,6 +390,9 @@ void OMW::Engine::go()
<< std::endl; << std::endl;
} }
if (!mStartupScript.empty())
MWBase::Environment::get().getWindowManager()->executeInConsole (mStartupScript);
// Start the main rendering loop // Start the main rendering loop
mOgre->start(); mOgre->start();
@ -497,3 +500,8 @@ void OMW::Engine::setScriptConsoleMode (bool enabled)
{ {
mScriptConsoleMode = enabled; mScriptConsoleMode = enabled;
} }
void OMW::Engine::setStartupScript (const std::string& path)
{
mStartupScript = path;
}

View file

@ -74,6 +74,7 @@ namespace OMW
std::string mFocusName; std::string mFocusName;
std::map<std::string,std::string> mFallbackMap; std::map<std::string,std::string> mFallbackMap;
bool mScriptConsoleMode; bool mScriptConsoleMode;
std::string mStartupScript;
Compiler::Extensions mExtensions; Compiler::Extensions mExtensions;
Compiler::Context *mScriptContext; Compiler::Context *mScriptContext;
@ -162,6 +163,9 @@ namespace OMW
/// Enable console-only script functionality /// Enable console-only script functionality
void setScriptConsoleMode (bool enabled); void setScriptConsoleMode (bool enabled);
/// Set path for a script that is run on startup in the console.
void setStartupScript (const std::string& path);
private: private:
Files::ConfigurationManager& mCfgMgr; Files::ConfigurationManager& mCfgMgr;
}; };

View file

@ -130,6 +130,11 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
("script-console", bpo::value<bool>()->implicit_value(true) ("script-console", bpo::value<bool>()->implicit_value(true)
->default_value(false), "enable console-only script functionality") ->default_value(false), "enable console-only script functionality")
("script-run", bpo::value<std::string>()->default_value(""),
"set a file that is execute in the console on startup\n\n"
"Note: The file contains a list of script lines, but not a complete scripts. "
"That means no begin/end and no variable declarations.")
("new-game", bpo::value<bool>()->implicit_value(true) ("new-game", bpo::value<bool>()->implicit_value(true)
->default_value(false), "activate char gen/new game mechanics") ->default_value(false), "activate char gen/new game mechanics")
@ -253,6 +258,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
engine.setAnimationVerbose(variables["anim-verbose"].as<bool>()); engine.setAnimationVerbose(variables["anim-verbose"].as<bool>());
engine.setFallbackValues(variables["fallback"].as<FallbackMap>().mMap); engine.setFallbackValues(variables["fallback"].as<FallbackMap>().mMap);
engine.setScriptConsoleMode (variables["script-console"].as<bool>()); engine.setScriptConsoleMode (variables["script-console"].as<bool>());
engine.setStartupScript (variables["script-run"].as<std::string>());
return true; return true;
} }

View file

@ -2,6 +2,7 @@
#include "console.hpp" #include "console.hpp"
#include <algorithm> #include <algorithm>
#include <fstream>
#include <components/esm_store/reclists.hpp> #include <components/esm_store/reclists.hpp>
#include <components/esm_store/store.hpp> #include <components/esm_store/store.hpp>
@ -201,6 +202,21 @@ namespace MWGui
} }
} }
void Console::executeFile (const std::string& path)
{
std::ifstream stream (path.c_str());
if (!stream.is_open())
printError ("failed to open file: " + path);
else
{
std::string line;
while (std::getline (stream, line))
execute (line);
}
}
void Console::keyPress(MyGUI::WidgetPtr _sender, void Console::keyPress(MyGUI::WidgetPtr _sender,
MyGUI::KeyCode key, MyGUI::KeyCode key,
MyGUI::Char _char) MyGUI::Char _char)

View file

@ -91,6 +91,8 @@ namespace MWGui
void execute (const std::string& command); void execute (const std::string& command);
void executeFile (const std::string& command);
private: private:
void keyPress(MyGUI::WidgetPtr _sender, void keyPress(MyGUI::WidgetPtr _sender,

View file

@ -740,3 +740,8 @@ bool WindowManager::getWorldMouseOver()
{ {
return mHud->getWorldMouseOver(); return mHud->getWorldMouseOver();
} }
void WindowManager::executeInConsole (const std::string& path)
{
mConsole->executeFile (path);
}

View file

@ -237,6 +237,8 @@ namespace MWGui
void processChangedSettings(const Settings::CategorySettingVector& changed); void processChangedSettings(const Settings::CategorySettingVector& changed);
void executeInConsole (const std::string& path);
private: private:
OEngine::GUI::MyGUIManager *mGuiManager; OEngine::GUI::MyGUIManager *mGuiManager;
HUD *mHud; HUD *mHud;