WeaponScripts.h file
Namespaces
- namespace Jazz2
- Root namespace of Jazz² Resurrection.
- namespace Jazz2::Editor
Classes
- struct Jazz2::Editor::ScriptWeaponClass
- A weapon a script library of JJ2+ offers, as MLLE sets it up.
- struct Jazz2::Editor::LevelWeapons
- Weapons of a level as the editor changes them.
- struct Jazz2::Editor::ScriptParamChoice
- A named value of a parameter of a weapon of a script.
- struct Jazz2::Editor::ScriptWeaponParam
- A parameter of a weapon of a script, in the order the library reads them.
- struct Jazz2::Editor::ScriptWeaponTemplate
- Description of a weapon of a script, its library and its parameters.
- struct Jazz2::Editor::ScriptParamValue
- Value of a parameter of a weapon of a script.
Enums
-
enum class ScriptParamType : std::
uint8_t { Bool, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Float, Double, String } - Type of a parameter of a weapon of a script, as
jjSTREAMkeeps it. -
enum class ScriptWeaponTemplateSource : std::
uint8_t { Json, MlleIni, Script } - Where a description of a weapon of a script comes from.
Functions
-
auto ReadMlleWeaponTemplates(StringView text,
StringView sourcePath,
SmallVectorImpl<ScriptWeaponTemplate>& templates) -> std::
int32_t - Reads the weapons of a description of MLLE, an
.inifile with a section of each weapon. -
auto ReadWeaponTemplates(StringView text,
StringView sourcePath,
SmallVectorImpl<ScriptWeaponTemplate>& templates,
SmallVectorImpl<CustomWeaponTemplate>* customTemplates = nullptr) -> std::
int32_t - Reads the weapons of a description of the editor, a
.jsonfile. -
void FindScriptWeaponTemplates(Death::
Containers:: ArrayView<const String> directories, SmallVectorImpl<ScriptWeaponTemplate>& templates, SmallVectorImpl<CustomWeaponTemplate>* customTemplates = nullptr) - Reads all descriptions of weapons (
.jsonand.ini) in directories, custom weapons intocustomTemplatesif given. -
auto GuessScriptWeaponTemplate(StringView library,
StringView text,
StringView constructor,
ScriptWeaponTemplate& result,
Death::
Containers:: ArrayView<const StringView> includes = {}) -> bool - Guesses the parameters of a weapon from the text of its library.
-
auto GetScriptParamSize(ScriptParamType type) -> std::
int32_t - Returns the size of a value of a parameter of a type, 0 for a text.
-
void MakeDefaultScriptParams(const ScriptWeaponTemplate& weaponTemplate,
SmallVectorImpl<std::
uint8_t>& data) - Returns the parameters as the weapon has them when it's chosen.
-
auto ReadScriptParams(const ScriptWeaponTemplate& weaponTemplate,
Death::
Containers:: ArrayView<const std:: uint8_t> data, SmallVectorImpl<ScriptParamValue>& values) -> std:: size_t - Reads the values of the parameters, those missing are as the template has them.
-
void WriteScriptParams(const ScriptWeaponTemplate& weaponTemplate,
Death::
Containers:: ArrayView<const ScriptParamValue> values, Death:: Containers:: ArrayView<const std:: uint8_t> rest, SmallVectorImpl<std:: uint8_t>& data) - Writes the values of the parameters, followed by
rest. - auto IsScriptWeaponTemplateOf(const ScriptWeaponTemplate& weaponTemplate, StringView library, StringView constructor) -> bool
- Returns
trueif a template is the one of the library and the code that creates a weapon. - auto GetScriptWeaponHookCall(StringView callback) -> StringView
- Returns the call of the hook of the weapons a callback of the level script has to make, as
processMain(, empty if it's not known. - void FindScriptWeapons(StringView library, StringView text, SmallVectorImpl<ScriptWeaponClass>& weapons)
- Finds the weapons in the text of a script library.
-
void FindScriptWeapons(Death::
Containers:: ArrayView<const String> directories, SmallVectorImpl<ScriptWeaponClass>& weapons) - Finds the weapons of all script libraries (
*.asc) in directories, the libraries of MLLE itself are left out. - void FindHandWrittenScriptWeapons(StringView script, String(&setUps)[MaxScriptWeapons])
- Finds the weapons a level script sets up by itself, outside of the lines MLLE generates.
- auto UpdateScriptWeaponLines(StringView script, const LevelWeapons& weapons) -> String
- Returns the text of a level script with the lines MLLE generates for the weapons of the script made anew.
Variables
-
std::
int32_t MaxScriptWeapons constexpr - Most weapons of a script, MLLE sets up the first nine.
Enum documentation
enum class ScriptParamType : std:: uint8_t
Type of a parameter of a weapon of a script, as jjSTREAM keeps it.
| Enumerators | |
|---|---|
| Bool |
One byte, 0 or 1 |
| Int8 |
One byte |
| UInt8 |
One byte |
| Int16 |
Two bytes |
| UInt16 |
Two bytes |
| Int32 |
Four bytes |
| UInt32 |
Four bytes |
| Int64 |
Eight bytes |
| UInt64 |
Eight bytes |
| Float |
Four bytes |
| Double |
Eight bytes |
| String |
Four bytes of the length and the text |
enum class ScriptWeaponTemplateSource : std:: uint8_t
Where a description of a weapon of a script comes from.
| Enumerators | |
|---|---|
| Json |
A description of the editor ( |
| MlleIni |
A description of MLLE ( |
| Script |
Guessed from the library, see GuessScriptWeaponTemplate() |
Function documentation
std:: int32_t ReadMlleWeaponTemplates(StringView text,
StringView sourcePath,
SmallVectorImpl<ScriptWeaponTemplate>& templates)
Reads the weapons of a description of MLLE, an .ini file with a section of each weapon.
The keys are Name, ImageFilename, LibraryFilename, Initialization, Hooks and Options, the options Name:type[:default] separated by |. Returns how many were read.
std:: int32_t ReadWeaponTemplates(StringView text,
StringView sourcePath,
SmallVectorImpl<ScriptWeaponTemplate>& templates,
SmallVectorImpl<CustomWeaponTemplate>* customTemplates = nullptr)
Reads the weapons of a description of the editor, a .json file.
An object or an array of them, or an object with Weapons, each with Name, Library, Constructor, Image, Hooks and Params, each parameter with Name, Type, Default, Min, Max, Description and Options of Name and Value. An item with "Kind": "Custom" is a custom weapon, read into customTemplates if given (see ReadCustomWeaponTemplate()). Returns how many were read, -1 if the text isn't JSON.
bool GuessScriptWeaponTemplate(StringView library,
StringView text,
StringView constructor,
ScriptWeaponTemplate& result,
Death:: Containers:: ArrayView<const StringView> includes = {})
Guesses the parameters of a weapon from the text of its library.
The function of the weapon that gets a jjSTREAM@ is looked for in the namespace of the weapon, and what it pops from it, in order, by the declarations of what it pops into, in the library and then in includes (as MLLE-Weapons.asc), a weapon without such a function takes none. Returns false if the class of the weapon isn't found, a guess that stops at a value of an unknown type isn't ScriptWeaponTemplate::
std:: size_t ReadScriptParams(const ScriptWeaponTemplate& weaponTemplate,
Death:: Containers:: ArrayView<const std:: uint8_t> data,
SmallVectorImpl<ScriptParamValue>& values)
Reads the values of the parameters, those missing are as the template has them.
Returns how many bytes the parameters of the template take, the rest is beyond what it describes.
void FindScriptWeapons(StringView library, StringView text, SmallVectorImpl<ScriptWeaponClass>& weapons)
Finds the weapons in the text of a script library.
A weapon is a class that isn't abstract and derives from MLLEWeaponApply or from MLLEWeapons::WeaponInterface, in the namespaces around it. A class of the standard weapon interface alone (se::WeaponInterface) isn't one, MLLE sets it up by a wrapper. Comments and strings are skipped.
void FindHandWrittenScriptWeapons(StringView script, String(&setUps)[MaxScriptWeapons])
Finds the weapons a level script sets up by itself, outside of the lines MLLE generates.
A call such as LaserBlaster::NonBouncing().Apply(WEAPON::ICE, MLLE::WeaponHook) — setUps gets what the call is made on for each weapon, by WeaponType, empty for the weapons the script leaves alone. Comments are skipped.
String UpdateScriptWeaponLines(StringView script, const LevelWeapons& weapons)
Returns the text of a level script with the lines MLLE generates for the weapons of the script made anew.
The lines marked ///@MLLE-Generated that set the weapons up — MLLE::Setup() and the #include and #pragma require of the libraries — are written for weapons, all other lines are kept as they are, with the line endings the text has. A script without such lines gets them at its start, if it needs them. Returns the text as it is if nothing changes.