|
|
|
#ifndef OPENMW_ESM_LUASCRIPTS_H
|
|
|
|
#define OPENMW_ESM_LUASCRIPTS_H
|
|
|
|
|
|
|
|
#include <components/esm/refid.hpp>
|
|
|
|
#include <components/vfs/pathutil.hpp>
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
class ESMReader;
|
|
|
|
class ESMWriter;
|
|
|
|
|
|
|
|
// LuaScriptCfg, LuaScriptsCfg are used in content files.
|
|
|
|
|
|
|
|
struct LuaScriptCfg
|
|
|
|
{
|
|
|
|
using Flags = uint32_t;
|
|
|
|
static constexpr Flags sGlobal = 1ull << 0; // start as a global script
|
|
|
|
static constexpr Flags sCustom = 1ull << 1; // local; can be attached/detached by a global script
|
|
|
|
static constexpr Flags sPlayer = 1ull << 2; // auto attach to players
|
|
|
|
|
|
|
|
// merge with configuration for this script from previous content files.
|
|
|
|
static constexpr Flags sMerge = 1ull << 3;
|
|
|
|
|
|
|
|
static constexpr Flags sMenu = 1ull << 4; // start as a menu script
|
|
|
|
|
|
|
|
VFS::Path::Normalized mScriptPath;
|
|
|
|
std::string mInitializationData; // Serialized Lua table. It is a binary data. Can contain '\0'.
|
|
|
|
Flags mFlags; // bitwise OR of Flags.
|
|
|
|
|
|
|
|
// Auto attach as a local script to objects of specific types (i.e. Container, Door, Activator, etc.)
|
|
|
|
std::vector<uint32_t> mTypes; // values are ESM::RecNameInts
|
|
|
|
|
|
|
|
// Auto attach as a local script to objects with specific recordIds (i.e. specific door type, or an unique NPC)
|
|
|
|
struct PerRecordCfg
|
|
|
|
{
|
|
|
|
bool mAttach; // true - attach, false - don't attach (overrides previous attach)
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2 years ago
|
|
|
ESM::RefId mRecordId;
|
|
|
|
// Initialization data for this specific record. If empty than LuaScriptCfg::mInitializationData is used.
|
|
|
|
std::string mInitializationData;
|
|
|
|
};
|
|
|
|
std::vector<PerRecordCfg> mRecords;
|
|
|
|
|
|
|
|
// Auto attach as a local script to specific objects by their Refnums. The reference must be defined in the same
|
|
|
|
// content file as this LuaScriptCfg or in one of its deps.
|
|
|
|
struct PerRefCfg
|
|
|
|
{
|
|
|
|
bool mAttach; // true - attach, false - don't attach (overrides previous attach)
|
|
|
|
uint32_t mRefnumIndex;
|
|
|
|
int32_t mRefnumContentFile;
|
|
|
|
// Initialization data for this specific refnum. If empty than LuaScriptCfg::mInitializationData is used.
|
|
|
|
std::string mInitializationData;
|
|
|
|
};
|
|
|
|
std::vector<PerRefCfg> mRefs;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LuaScriptsCfg
|
|
|
|
{
|
|
|
|
std::vector<LuaScriptCfg> mScripts;
|
|
|
|
|
|
|
|
void load(ESMReader& esm);
|
|
|
|
void adjustRefNums(const ESMReader& esm);
|
|
|
|
|
|
|
|
void save(ESMWriter& esm) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
// LuaTimer, LuaScript, LuaScripts are used in saved game files.
|
|
|
|
// Storage structure for LuaUtil::ScriptsContainer. These are not top-level records.
|
|
|
|
// Used either for global scripts or for local scripts on a specific object.
|
|
|
|
|
|
|
|
struct LuaTimer
|
|
|
|
{
|
|
|
|
enum class Type : bool
|
|
|
|
{
|
|
|
|
SIMULATION_TIME = 0,
|
|
|
|
GAME_TIME = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
Type mType;
|
|
|
|
double mTime;
|
|
|
|
std::string mCallbackName;
|
|
|
|
std::string mCallbackArgument; // Serialized Lua table. It is a binary data. Can contain '\0'.
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LuaScript
|
|
|
|
{
|
|
|
|
VFS::Path::Normalized mScriptPath;
|
|
|
|
std::string mData; // Serialized Lua table. It is a binary data. Can contain '\0'.
|
|
|
|
std::vector<LuaTimer> mTimers;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LuaScripts
|
|
|
|
{
|
|
|
|
std::vector<LuaScript> mScripts;
|
|
|
|
|
|
|
|
void load(ESMReader& esm);
|
|
|
|
void save(ESMWriter& esm) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Saves binary string `data` (can contain '\0') as LUAD record.
|
|
|
|
void saveLuaBinaryData(ESM::ESMWriter& esm, const std::string& data);
|
|
|
|
|
|
|
|
// Loads LUAD as binary string. If next subrecord is not LUAD, then returns an empty string.
|
|
|
|
std::string loadLuaBinaryData(ESM::ESMReader& esm);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|