1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 03:32:36 +00:00
OpenMW/apps/openmw/mwscript/locals.hpp

73 lines
2.3 KiB
C++
Raw Normal View History

2010-07-02 14:31:29 +02:00
#ifndef GAME_SCRIPT_LOCALS_H
#define GAME_SCRIPT_LOCALS_H
2022-05-21 12:41:56 +02:00
#include <string>
#include <string_view>
2010-07-02 14:31:29 +02:00
#include <vector>
#include <components/interpreter/types.hpp>
namespace ESM
{
class Script;
struct Locals;
}
2010-07-02 14:31:29 +02:00
namespace MWScript
{
2013-02-03 13:27:27 +00:00
class Locals
2010-07-02 14:31:29 +02:00
{
bool mInitialised;
2022-08-11 22:51:55 +02:00
void ensure(std::string_view scriptName);
2013-02-03 13:27:27 +00:00
public:
std::vector<Interpreter::Type_Short> mShorts;
std::vector<Interpreter::Type_Integer> mLongs;
std::vector<Interpreter::Type_Float> mFloats;
Locals();
/// Are there any locals?
///
/// \note Will return false, if locals have not been configured yet.
bool isEmpty() const;
/// \return Did the state of *this change from uninitialised to initialised?
bool configure (const ESM::Script& script);
/// @note var needs to be in lowercase
///
/// \note Locals will be automatically configured first, if necessary
2022-08-11 22:51:55 +02:00
bool setVarByInt(std::string_view script, std::string_view var, int val);
/// \note Locals will be automatically configured first, if necessary
//
// \note If it can not be determined if the variable exists, the error will be
// ignored and false will be returned.
2022-08-11 22:51:55 +02:00
bool hasVar(std::string_view script, std::string_view var);
/// if var does not exist, returns 0
/// @note var needs to be in lowercase
///
/// \note Locals will be automatically configured first, if necessary
2022-08-11 22:51:55 +02:00
int getIntVar(std::string_view script, std::string_view var);
2016-02-27 13:40:53 +01:00
/// if var does not exist, returns 0
/// @note var needs to be in lowercase
///
/// \note Locals will be automatically configured first, if necessary
2022-08-11 22:51:55 +02:00
float getFloatVar(std::string_view script, std::string_view var);
2016-02-27 13:40:53 +01:00
/// \note If locals have not been configured yet, no data is written.
///
/// \return Locals written?
2022-08-11 22:51:55 +02:00
bool write(ESM::Locals& locals, std::string_view script) const;
/// \note Locals will be automatically configured first, if necessary
2022-08-11 22:51:55 +02:00
void read(const ESM::Locals& locals, std::string_view script);
2010-07-02 14:31:29 +02:00
};
}
#endif