forked from teamnwah/openmw-tes3coop
implemented script compiler for console
This commit is contained in:
parent
5ff9344a87
commit
d72ed19460
5 changed files with 90 additions and 18 deletions
|
@ -206,12 +206,13 @@ void OMW::Engine::go()
|
|||
mOgre.getScene());
|
||||
|
||||
// Create window manager - this manages all the MW-specific GUI windows
|
||||
mEnvironment.mWindowManager = new MWGui::WindowManager(mGuiManager->getGui());
|
||||
MWScript::registerExtensions (mExtensions);
|
||||
|
||||
mEnvironment.mWindowManager = new MWGui::WindowManager(mGuiManager->getGui(), mEnvironment,
|
||||
mExtensions);
|
||||
|
||||
mEnvironment.mSoundManager = new MWSound::SoundManager;
|
||||
|
||||
MWScript::registerExtensions (mExtensions);
|
||||
|
||||
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full,
|
||||
mEnvironment);
|
||||
mScriptContext->setExtensions (&mExtensions);
|
||||
|
|
|
@ -4,11 +4,70 @@
|
|||
#include <openengine/gui/layout.hpp>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <components/compiler/errorhandler.hpp>
|
||||
#include <components/compiler/lineparser.hpp>
|
||||
#include <components/compiler/scanner.hpp>
|
||||
#include <components/compiler/locals.hpp>
|
||||
#include <components/compiler/literals.hpp>
|
||||
#include <components/compiler/exception.hpp>
|
||||
|
||||
#include "../mwscript/compilercontext.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
class Console : private OEngine::GUI::Layout
|
||||
class Console : private OEngine::GUI::Layout, private Compiler::ErrorHandler
|
||||
{
|
||||
private:
|
||||
|
||||
MWScript::CompilerContext mCompilerContext;
|
||||
|
||||
bool compile (const std::string& cmd)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::istringstream input (cmd + '\n');
|
||||
|
||||
Compiler::Scanner scanner (*this, input, mCompilerContext.getExtensions());
|
||||
|
||||
Compiler::Locals locals;
|
||||
Compiler::Literals literals;
|
||||
std::vector<Interpreter::Type_Code> code;
|
||||
Compiler::LineParser parser (*this, mCompilerContext, locals, literals, code);
|
||||
|
||||
scanner.scan (parser);
|
||||
|
||||
return isGood();
|
||||
}
|
||||
catch (const Compiler::SourceException&)
|
||||
{
|
||||
// error has already been reported via error handler
|
||||
}
|
||||
catch (const std::exception& error)
|
||||
{
|
||||
printError (std::string ("An exception has been thrown: ") + error.what());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Report error to the user.
|
||||
virtual void report (const std::string& message, const Compiler::TokenLoc& loc, Type type)
|
||||
{
|
||||
std::ostringstream error;
|
||||
error << "column " << loc.mColumn << " (" << loc.mLiteral << "):";
|
||||
|
||||
printError (error.str());
|
||||
printError ((type==ErrorMessage ? "error: " : "warning: ") + message);
|
||||
}
|
||||
|
||||
/// Report a file related error
|
||||
virtual void report (const std::string& message, Type type)
|
||||
{
|
||||
printError ((type==ErrorMessage ? "error: " : "warning: ") + message);
|
||||
}
|
||||
|
||||
public:
|
||||
MyGUI::EditPtr command;
|
||||
MyGUI::EditPtr history;
|
||||
|
@ -20,8 +79,9 @@ namespace MWGui
|
|||
StringList::iterator current;
|
||||
std::string editString;
|
||||
|
||||
Console(int w, int h)
|
||||
: Layout("openmw_console_layout.xml")
|
||||
Console(int w, int h, MWWorld::Environment& environment, const Compiler::Extensions& extensions)
|
||||
: Layout("openmw_console_layout.xml"),
|
||||
mCompilerContext (MWScript::CompilerContext::Type_Console, environment)
|
||||
{
|
||||
setCoord(10,10, w-10, h/2);
|
||||
|
||||
|
@ -38,6 +98,9 @@ namespace MWGui
|
|||
history->setOverflowToTheLeft(true);
|
||||
history->setEditStatic(true);
|
||||
history->setVisibleVScroll(true);
|
||||
|
||||
// compiler
|
||||
mCompilerContext.setExtensions (&extensions);
|
||||
}
|
||||
|
||||
void enable()
|
||||
|
@ -130,14 +193,10 @@ namespace MWGui
|
|||
// Log the command
|
||||
print("#FFFFFF> " + cm + "\n");
|
||||
|
||||
/* NOTE: This is where the console command should be
|
||||
handled.
|
||||
|
||||
The console command is in the string 'cm'. Output from the
|
||||
command should be put back into the console with the
|
||||
printOK() or printError() functions.
|
||||
*/
|
||||
printOK("OK - echoing line " + cm);
|
||||
if (compile (cm))
|
||||
{
|
||||
// TODO execute command
|
||||
}
|
||||
|
||||
command->setCaption("");
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
using namespace MWGui;
|
||||
|
||||
WindowManager::WindowManager(MyGUI::Gui *_gui)
|
||||
WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment,
|
||||
const Compiler::Extensions& extensions)
|
||||
: gui(_gui), mode(GM_Game), shown(GW_ALL), allowed(GW_ALL)
|
||||
{
|
||||
// Get size info from the Gui object
|
||||
|
@ -19,7 +20,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui)
|
|||
menu = new MainMenu(w,h);
|
||||
map = new MapWindow();
|
||||
stats = new StatsWindow();
|
||||
console = new Console(w,h);
|
||||
console = new Console(w,h, environment, extensions);
|
||||
|
||||
// The HUD is always on
|
||||
hud->setVisible(true);
|
||||
|
|
|
@ -15,6 +15,16 @@ namespace MyGUI
|
|||
class Gui;
|
||||
}
|
||||
|
||||
namespace Compiler
|
||||
{
|
||||
class Extensions;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class Environment;
|
||||
}
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
class HUD;
|
||||
|
@ -91,7 +101,8 @@ namespace MWGui
|
|||
|
||||
public:
|
||||
/// The constructor needs the main Gui object
|
||||
WindowManager(MyGUI::Gui *_gui);
|
||||
WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment,
|
||||
const Compiler::Extensions& extensions);
|
||||
virtual ~WindowManager();
|
||||
|
||||
void setMode(GuiMode newMode)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit c04d72cbe380217c2d1d60f8a2c6e4810fe4c050
|
||||
Subproject commit 82a3c071e56f2df451618e1371424c39aa299690
|
Loading…
Reference in a new issue