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>
|
|
|
|
|
2013-04-04 12:27:57 +02:00
|
|
|
namespace ESM
|
|
|
|
{
|
2015-03-06 21:36:42 +13:00
|
|
|
class Script;
|
2013-12-15 16:16:50 +01:00
|
|
|
struct Locals;
|
2013-04-04 12:27:57 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-09-15 13:58:07 +02:00
|
|
|
bool mInitialised;
|
|
|
|
|
2022-08-11 22:51:55 +02:00
|
|
|
void ensure(std::string_view scriptName);
|
2015-09-15 13:58:07 +02:00
|
|
|
|
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;
|
2013-04-04 12:27:57 +02:00
|
|
|
|
2015-09-15 13:58:07 +02:00
|
|
|
Locals();
|
|
|
|
|
2014-06-26 01:21:15 +02:00
|
|
|
/// Are there any locals?
|
2015-09-15 13:58:07 +02:00
|
|
|
///
|
|
|
|
/// \note Will return false, if locals have not been configured yet.
|
2014-06-26 01:21:15 +02:00
|
|
|
bool isEmpty() const;
|
|
|
|
|
2015-09-15 13:58:07 +02:00
|
|
|
/// \return Did the state of *this change from uninitialised to initialised?
|
|
|
|
bool configure (const ESM::Script& script);
|
2015-01-31 02:08:37 +01:00
|
|
|
|
2014-09-11 19:20:04 +02:00
|
|
|
/// @note var needs to be in lowercase
|
2015-09-15 13:58:07 +02:00
|
|
|
///
|
|
|
|
/// \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);
|
2015-01-31 02:08:37 +01:00
|
|
|
|
2015-09-15 13:58:07 +02:00
|
|
|
/// \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);
|
2015-01-31 02:08:37 +01:00
|
|
|
|
|
|
|
/// if var does not exist, returns 0
|
2014-09-11 19:20:04 +02:00
|
|
|
/// @note var needs to be in lowercase
|
2015-09-15 13:58:07 +02:00
|
|
|
///
|
|
|
|
/// \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);
|
2013-04-04 12:27:57 +02:00
|
|
|
|
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
|
|
|
|
2015-09-15 13:58:07 +02: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;
|
2013-12-15 16:16:50 +01:00
|
|
|
|
2015-09-15 13:58:07 +02:00
|
|
|
/// \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
|