forked from teamnwah/openmw-tes3coop
implemented local script execution
parent
8e2732c60e
commit
474b412b47
@ -0,0 +1,72 @@
|
||||
|
||||
#include "interpretercontext.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include "locals.hpp"
|
||||
|
||||
namespace MWScript
|
||||
{
|
||||
InterpreterContext::InterpreterContext (OMW::World& world, MWScript::Locals *locals)
|
||||
: mWorld (world), mLocals (locals)
|
||||
{}
|
||||
|
||||
int InterpreterContext::getLocalShort (int index) const
|
||||
{
|
||||
if (!mLocals)
|
||||
throw std::runtime_error ("local variables not available in this context");
|
||||
|
||||
return mLocals->mShorts.at (index);
|
||||
}
|
||||
|
||||
int InterpreterContext::getLocalLong (int index) const
|
||||
{
|
||||
if (!mLocals)
|
||||
throw std::runtime_error ("local variables not available in this context");
|
||||
|
||||
return mLocals->mLongs.at (index);
|
||||
}
|
||||
|
||||
float InterpreterContext::getLocalFloat (int index) const
|
||||
{
|
||||
if (!mLocals)
|
||||
throw std::runtime_error ("local variables not available in this context");
|
||||
|
||||
return mLocals->mFloats.at (index);
|
||||
}
|
||||
|
||||
void InterpreterContext::setLocalShort (int index, int value)
|
||||
{
|
||||
if (!mLocals)
|
||||
throw std::runtime_error ("local variables not available in this context");
|
||||
|
||||
mLocals->mShorts.at (index) = value;
|
||||
}
|
||||
|
||||
void InterpreterContext::setLocalLong (int index, int value)
|
||||
{
|
||||
if (!mLocals)
|
||||
throw std::runtime_error ("local variables not available in this context");
|
||||
|
||||
mLocals->mLongs.at (index) = value;
|
||||
}
|
||||
|
||||
void InterpreterContext::setLocalFloat (int index, float value)
|
||||
{
|
||||
if (!mLocals)
|
||||
throw std::runtime_error ("local variables not available in this context");
|
||||
|
||||
mLocals->mFloats.at (index) = value;
|
||||
}
|
||||
|
||||
void InterpreterContext::messageBox (const std::string& message,
|
||||
const std::vector<std::string>& buttons)
|
||||
{
|
||||
std::cout << "message box: " << message << std::endl;
|
||||
|
||||
if (!buttons.empty())
|
||||
std::cerr << "error: message box buttons not supported" << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
#ifndef GAME_SCRIPT_INTERPRETERCONTEXT_H
|
||||
#define GAME_SCRIPT_INTERPRETERCONTEXT_H
|
||||
|
||||
#include <components/interpreter/context.hpp>
|
||||
|
||||
namespace OMW
|
||||
{
|
||||
class World;
|
||||
}
|
||||
|
||||
namespace MWScript
|
||||
{
|
||||
struct Locals;
|
||||
|
||||
class InterpreterContext : public Interpreter::Context
|
||||
{
|
||||
OMW::World& mWorld;
|
||||
Locals *mLocals;
|
||||
|
||||
public:
|
||||
|
||||
InterpreterContext (OMW::World& world, MWScript::Locals *locals);
|
||||
///< The ownership of \a locals is not transferred. 0-pointer allowed.
|
||||
|
||||
virtual int getLocalShort (int index) const;
|
||||
|
||||
virtual int getLocalLong (int index) const;
|
||||
|
||||
virtual float getLocalFloat (int index) const;
|
||||
|
||||
virtual void setLocalShort (int index, int value);
|
||||
|
||||
virtual void setLocalLong (int index, int value);
|
||||
|
||||
virtual void setLocalFloat (int index, float value);
|
||||
|
||||
virtual void messageBox (const std::string& message,
|
||||
const std::vector<std::string>& buttons);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue