Commit graph

5 commits

Author SHA1 Message Date
hispidence
a75b43b7c5 Implement ScriptAssertF and ScriptAssertTerminateF.
These are like ScriptAssert, but make use of the fmt library (atm hijacking the version that comes with spdlog). This allows us to pass in a format string and some args, and then only create the format string if there's an actual error. This means we won't waste time doing a ton of std::string concatenations if the assert succeeds.

As these are variadic templates, we can't use a std::optional as the last argument to check if we're forcing a different error mode (we possibly could by assuming the last arg is a std::optional, but that seems unclean), so instead I've just separated them out into two functions.
2021-08-21 00:23:14 +01:00
hispidence
8d84ee6f3f Rename SetErrorMode to SetScriptErrorMode to avoid VS getting confused by some MS function with the same name. Add GetScriptErrorMode. 2021-08-21 00:13:44 +01:00
hispidence
af84f318b6 Document errorMode. Make it an enum on the Lua side rather than a string. 2021-08-16 12:52:06 +01:00
hispidence
032f824870 Add ScriptWarn and SetErrorMode.
SetErrorMode is called via Lua in settings.lua to allow us or the LD to choose between the three ERROR_MODEs for script asserts.

ScriptWarn is for when we want to follow up on a failed assert in ERROR_MODE::WARN. e.g. if the player gives in an invalid HP value, we would ScriptWarn to tell them that the HP is being set to zero instead. If we added this information in ScriptAssert, we would end up displaying this message in TERMINATE mode, too - which is incorrect, since we won't have set the HP to zero, as we will have terminated the game.
2021-08-06 16:43:01 +01:00
hispidence
f71deca16e Add ScriptAssert.
This is to be used when an error is discovered in a Lua Script.

The var ScriptErrorMode refers to the error mode the user has chosen (silent, warn, terminate). At the moment this is hardcoded but will soon become editable to a LD via settings.

ScriptAssert will read this variable and take the appropriate action when an assert is failed.

IGNORE will do nothing (we should make a note in the documentation that this should almost certainly not be used by the LD if they can avoid it).
WARN will call TENLog with LogLevel::Warn.
TERMINATE will throw a TENScriptException, where it will be caught at GameMain, where TENLog will be called.

There are circumstances where we will HAVE to terminate, even if the user has opted not to (i.e. errors where there is nothing sensible that can be done, such as syntax errors that would terminate Lua anyway). For these, we can pass in ERROR_MODE::TERMINATE as the last variable.
2021-08-04 16:18:52 +01:00