Enforce proper convention for the few Lua table constants that didn't use it yet

This commit is contained in:
Sezz 2025-02-06 18:46:16 +11:00
parent 89d5b74298
commit acb1bb1518
3 changed files with 85 additions and 63 deletions

View file

@ -180,29 +180,29 @@ designer to add calls to <code>OnStart</code>, <code>OnLoad</code>, etc. in thei
<p>Possible values for <code>point</code>:</p> <p>Possible values for <code>point</code>:</p>
<pre class="example"><span class="comment">-- These take functions which accept no arguments <pre class="example"><span class="comment">-- These take functions which accept no arguments
</span>PRESTART <span class="comment">-- will be called immediately before OnStart </span>PRE_START <span class="comment">-- will be called immediately before OnStart
</span>POSTSTART <span class="comment">-- will be called immediately after OnStart </span>POST_START <span class="comment">-- will be called immediately after OnStart
</span> </span>
PRESAVE <span class="comment">-- will be called immediately before OnSave PRE_SAVE <span class="comment">-- will be called immediately before OnSave
</span>POSTSAVE <span class="comment">-- will be called immediately after OnSave </span>POST_SAVE <span class="comment">-- will be called immediately after OnSave
</span> </span>
PRELOAD <span class="comment">-- will be called immediately before OnLoad PRE_LOAD <span class="comment">-- will be called immediately before OnLoad
</span>POSTLOAD <span class="comment">-- will be called immediately after OnLoad </span>POST_LOAD <span class="comment">-- will be called immediately after OnLoad
</span> </span>
PREFREEZE <span class="comment">-- will be called before entering freeze mode PRE_FREEZE <span class="comment">-- will be called before entering freeze mode
</span>POSTFREEZE <span class="comment">-- will be called immediately after exiting freeze mode </span>POST_FREEZE <span class="comment">-- will be called immediately after exiting freeze mode
</span> </span>
<span class="comment">-- These take a LevelEndReason arg, like OnEnd <span class="comment">-- These take a LevelEndReason arg, like OnEnd
</span>PREEND <span class="comment">-- will be called immediately before OnEnd </span>PRE_END <span class="comment">-- will be called immediately before OnEnd
</span>POSTEND <span class="comment">-- will be called immediately after OnEnd </span>POST_END <span class="comment">-- will be called immediately after OnEnd
</span> </span>
<span class="comment">-- These take functions which accepts a deltaTime argument <span class="comment">-- These take functions which accepts a deltaTime argument
</span>PRELOOP <span class="comment">-- will be called in the beginning of game loop </span>PRE_LOOP <span class="comment">-- will be called in the beginning of game loop
</span>POSTLOOP <span class="comment">-- will be called at the end of game loop </span>POST_LOOP <span class="comment">-- will be called at the end of game loop
</span> </span>
<span class="comment">-- These take functions which accepts an objectNumber argument, like OnUseItem <span class="comment">-- These take functions which accepts an objectNumber argument, like OnUseItem
</span>PREUSEITEM <span class="comment">-- will be called immediately before OnUseItem </span>PRE_USE_ITEM <span class="comment">-- will be called immediately before OnUseItem
</span>POSTUSEITEM <span class="comment">-- will be called immediately after OnUseItem </span>POST_USE_ITEM <span class="comment">-- will be called immediately after OnUseItem
</span></pre> </span></pre>
<p>The order in which two functions with the same CallbackPoint are called is undefined. <p>The order in which two functions with the same CallbackPoint are called is undefined.
i.e. if you register <code>MyFunc</code> and <code>MyFunc2</code> with <code>PRELOOP</code>, both will be called in the beginning of game loop, but there is no guarantee that <code>MyFunc</code> will be called before <code>MyFunc2</code>, or vice-versa.</p> i.e. if you register <code>MyFunc</code> and <code>MyFunc2</code> with <code>PRELOOP</code>, both will be called in the beginning of game loop, but there is no guarantee that <code>MyFunc</code> will be called before <code>MyFunc2</code>, or vice-versa.</p>
@ -279,7 +279,7 @@ SAVE
START START
END END
LOOP LOOP
USEITEM USE_ITEM
MENU</pre> MENU</pre>
@ -509,9 +509,9 @@ and provides the delta time (a float representing game time since last call) via
<p>(EndReason) Will be called when leaving a level. This includes finishing it, exiting to the menu, or loading a save in a different level. It can take an <code>EndReason</code> arg:</p> <p>(EndReason) Will be called when leaving a level. This includes finishing it, exiting to the menu, or loading a save in a different level. It can take an <code>EndReason</code> arg:</p>
<pre><code>EXITTOTITLE <pre><code>EXIT_TO_TITLE
LEVELCOMPLETE LEVEL_COMPLETE
LOADGAME LOAD_GAME
DEATH DEATH
OTHER OTHER
</code></pre> </code></pre>

View file

@ -60,35 +60,32 @@ static constexpr char ScriptReserved_DisplayStringSetScale[] = "SetScale";
static constexpr char ScriptReserved_DisplayStringSetColor[] = "SetColor"; static constexpr char ScriptReserved_DisplayStringSetColor[] = "SetColor";
static constexpr char ScriptReserved_DisplaySpriteDraw[] = "Draw"; static constexpr char ScriptReserved_DisplaySpriteDraw[] = "Draw";
static constexpr char ScriptReserved_EndReasonExitToTitle[] = "EXITTOTITLE";
static constexpr char ScriptReserved_EndReasonLevelComplete[] = "LEVELCOMPLETE";
static constexpr char ScriptReserved_EndReasonLoadGame[] = "LOADGAME";
static constexpr char ScriptReserved_EndReasonDeath[] = "DEATH"; static constexpr char ScriptReserved_EndReasonDeath[] = "DEATH";
static constexpr char ScriptReserved_EndReasonExitToTitle[] = "EXIT_TO_TITLE";
static constexpr char ScriptReserved_EndReasonLevelComplete[] = "LEVEL_COMPLETE";
static constexpr char ScriptReserved_EndReasonLoadGame[] = "LOAD_GAME";
static constexpr char ScriptReserved_EndReasonOther[] = "OTHER"; static constexpr char ScriptReserved_EndReasonOther[] = "OTHER";
// Callback points // Callback points
static constexpr char ScriptReserved_PreStart[] = "PRESTART"; static constexpr char ScriptReserved_PreStart[] = "PRE_START";
static constexpr char ScriptReserved_PostStart[] = "POSTSTART"; static constexpr char ScriptReserved_PostStart[] = "POST_START";
static constexpr char ScriptReserved_PreEnd[] = "PREEND"; static constexpr char ScriptReserved_PreEnd[] = "PRE_END";
static constexpr char ScriptReserved_PostEnd[] = "POSTEND"; static constexpr char ScriptReserved_PostEnd[] = "POST_END";
static constexpr char ScriptReserved_PreSave[] = "PRESAVE"; static constexpr char ScriptReserved_PreSave[] = "PRE_SAVE";
static constexpr char ScriptReserved_PostSave[] = "POSTSAVE"; static constexpr char ScriptReserved_PostSave[] = "POST_SAVE";
static constexpr char ScriptReserved_PreLoad[] = "PRELOAD"; static constexpr char ScriptReserved_PreLoad[] = "PRE_LOAD";
static constexpr char ScriptReserved_PostLoad[] = "POSTLOAD"; static constexpr char ScriptReserved_PostLoad[] = "POST_LOAD";
static constexpr char ScriptReserved_PreControlPhase[] = "PRECONTROLPHASE"; // DEPRECATED static constexpr char ScriptReserved_PreLoop[] = "PRE_LOOP";
static constexpr char ScriptReserved_PostControlPhase[] = "POSTCONTROLPHASE"; // DEPRECATED static constexpr char ScriptReserved_PostLoop[] = "POST_LOOP";
static constexpr char ScriptReserved_PreLoop[] = "PRELOOP"; static constexpr char ScriptReserved_PreUseItem[] = "PRE_USE_ITEM";
static constexpr char ScriptReserved_PostLoop[] = "POSTLOOP"; static constexpr char ScriptReserved_PostUseItem[] = "POST_USE_ITEM";
static constexpr char ScriptReserved_PreUseItem[] = "PREUSEITEM"; static constexpr char ScriptReserved_PreFreeze[] = "PRE_FREEZE";
static constexpr char ScriptReserved_PostUseItem[] = "POSTUSEITEM"; static constexpr char ScriptReserved_PostFreeze[] = "POST_FREEZE";
static constexpr char ScriptReserved_PreFreeze[] = "PREFREEZE";
static constexpr char ScriptReserved_PostFreeze[] = "POSTFREEZE";
// Built-in LevelFuncs // Built-in LevelFuncs
static constexpr char ScriptReserved_OnStart[] = "OnStart"; static constexpr char ScriptReserved_OnStart[] = "OnStart";
static constexpr char ScriptReserved_OnLoad[] = "OnLoad"; static constexpr char ScriptReserved_OnLoad[] = "OnLoad";
static constexpr char ScriptReserved_OnLoop[] = "OnLoop"; static constexpr char ScriptReserved_OnLoop[] = "OnLoop";
static constexpr char ScriptReserved_OnControlPhase[] = "OnControlPhase"; // DEPRECATED
static constexpr char ScriptReserved_OnSave[] = "OnSave"; static constexpr char ScriptReserved_OnSave[] = "OnSave";
static constexpr char ScriptReserved_OnEnd[] = "OnEnd"; static constexpr char ScriptReserved_OnEnd[] = "OnEnd";
static constexpr char ScriptReserved_OnUseItem[] = "OnUseItem"; static constexpr char ScriptReserved_OnUseItem[] = "OnUseItem";
@ -103,7 +100,7 @@ static constexpr char ScriptReserved_EventOnLoad[] = "LOAD";
static constexpr char ScriptReserved_EventOnLoop[] = "LOOP"; static constexpr char ScriptReserved_EventOnLoop[] = "LOOP";
static constexpr char ScriptReserved_EventOnSave[] = "SAVE"; static constexpr char ScriptReserved_EventOnSave[] = "SAVE";
static constexpr char ScriptReserved_EventOnEnd[] = "END"; static constexpr char ScriptReserved_EventOnEnd[] = "END";
static constexpr char ScriptReserved_EventOnUseItem[] = "USEITEM"; static constexpr char ScriptReserved_EventOnUseItem[] = "USE_ITEM";
static constexpr char ScriptReserved_EventOnFreeze[] = "FREEZE"; static constexpr char ScriptReserved_EventOnFreeze[] = "FREEZE";
// Member functions // Member functions

View file

@ -60,8 +60,6 @@ static const auto CALLBACK_POINTS = std::unordered_map<std::string, CallbackPoin
{ ScriptReserved_PostLoad, CallbackPoint::PostLoad }, { ScriptReserved_PostLoad, CallbackPoint::PostLoad },
{ ScriptReserved_PreLoop, CallbackPoint::PreLoop }, { ScriptReserved_PreLoop, CallbackPoint::PreLoop },
{ ScriptReserved_PostLoop, CallbackPoint::PostLoop }, { ScriptReserved_PostLoop, CallbackPoint::PostLoop },
{ ScriptReserved_PreControlPhase, CallbackPoint::PreLoop }, // DEPRECATED
{ ScriptReserved_PostControlPhase, CallbackPoint::PostLoop }, // DEPRECATED
{ ScriptReserved_PreSave, CallbackPoint::PreSave }, { ScriptReserved_PreSave, CallbackPoint::PreSave },
{ ScriptReserved_PostSave, CallbackPoint::PostSave }, { ScriptReserved_PostSave, CallbackPoint::PostSave },
{ ScriptReserved_PreEnd, CallbackPoint::PreEnd }, { ScriptReserved_PreEnd, CallbackPoint::PreEnd },
@ -69,7 +67,24 @@ static const auto CALLBACK_POINTS = std::unordered_map<std::string, CallbackPoin
{ ScriptReserved_PreUseItem, CallbackPoint::PreUseItem }, { ScriptReserved_PreUseItem, CallbackPoint::PreUseItem },
{ ScriptReserved_PostUseItem, CallbackPoint::PostUseItem }, { ScriptReserved_PostUseItem, CallbackPoint::PostUseItem },
{ ScriptReserved_PreFreeze, CallbackPoint::PreFreeze }, { ScriptReserved_PreFreeze, CallbackPoint::PreFreeze },
{ ScriptReserved_PostFreeze, CallbackPoint::PostFreeze } { ScriptReserved_PostFreeze, CallbackPoint::PostFreeze },
// COMPATIBILITY
{ "POSTSTART", CallbackPoint::PostStart },
{ "PRELOAD", CallbackPoint::PreLoad },
{ "POSTLOAD", CallbackPoint::PostLoad },
{ "PRELOOP", CallbackPoint::PreLoop },
{ "POSTLOOP", CallbackPoint::PostLoop },
{ "PRESAVE", CallbackPoint::PreSave },
{ "POSTSAVE", CallbackPoint::PostSave },
{ "PREEND", CallbackPoint::PreEnd },
{ "POSTEND", CallbackPoint::PostEnd },
{ "PREUSEITEM", CallbackPoint::PreUseItem },
{ "POSTUSEITEM", CallbackPoint::PostUseItem },
{ "PREFREEZE", CallbackPoint::PreFreeze },
{ "POSTFREEZE", CallbackPoint::PostFreeze },
{ "PRECONTROLPHASE", CallbackPoint::PreLoop },
{ "POSTCONTROLPHASE", CallbackPoint::PostLoop }
}; };
static const auto EVENT_TYPES = std::unordered_map<std::string, EventType> static const auto EVENT_TYPES = std::unordered_map<std::string, EventType>
@ -83,7 +98,10 @@ static const auto EVENT_TYPES = std::unordered_map<std::string, EventType>
{ ScriptReserved_EventOnStart, EventType::Start }, { ScriptReserved_EventOnStart, EventType::Start },
{ ScriptReserved_EventOnEnd, EventType::End }, { ScriptReserved_EventOnEnd, EventType::End },
{ ScriptReserved_EventOnUseItem, EventType::UseItem }, { ScriptReserved_EventOnUseItem, EventType::UseItem },
{ ScriptReserved_EventOnFreeze, EventType::Freeze } { ScriptReserved_EventOnFreeze, EventType::Freeze },
// COMPATIBILITY
{ "USEITEM", EventType::UseItem }
}; };
static const auto LEVEL_END_REASONS = std::unordered_map<std::string, LevelEndReason> static const auto LEVEL_END_REASONS = std::unordered_map<std::string, LevelEndReason>
@ -92,7 +110,12 @@ static const auto LEVEL_END_REASONS = std::unordered_map<std::string, LevelEndRe
{ ScriptReserved_EndReasonLoadGame, LevelEndReason::LoadGame }, { ScriptReserved_EndReasonLoadGame, LevelEndReason::LoadGame },
{ ScriptReserved_EndReasonExitToTitle, LevelEndReason::ExitToTitle }, { ScriptReserved_EndReasonExitToTitle, LevelEndReason::ExitToTitle },
{ ScriptReserved_EndReasonDeath, LevelEndReason::Death }, { ScriptReserved_EndReasonDeath, LevelEndReason::Death },
{ ScriptReserved_EndReasonOther, LevelEndReason::Other } { ScriptReserved_EndReasonOther, LevelEndReason::Other },
// COMPATIBILITY
{ "LEVELCOMPLETE", LevelEndReason::LevelComplete },
{ "LOADGAME", LevelEndReason::LoadGame },
{ "LEVELCOMPLETE", LevelEndReason::ExitToTitle }
}; };
static constexpr char const* strKey = "__internal_name"; static constexpr char const* strKey = "__internal_name";
@ -225,29 +248,29 @@ designer to add calls to `OnStart`, `OnLoad`, etc. in their level script.
Possible values for `point`: Possible values for `point`:
-- These take functions which accept no arguments -- These take functions which accept no arguments
PRESTART -- will be called immediately before OnStart PRE_START -- will be called immediately before OnStart
POSTSTART -- will be called immediately after OnStart POST_START -- will be called immediately after OnStart
PRESAVE -- will be called immediately before OnSave PRE_SAVE -- will be called immediately before OnSave
POSTSAVE -- will be called immediately after OnSave POST_SAVE -- will be called immediately after OnSave
PRELOAD -- will be called immediately before OnLoad PRE_LOAD -- will be called immediately before OnLoad
POSTLOAD -- will be called immediately after OnLoad POST_LOAD -- will be called immediately after OnLoad
PREFREEZE -- will be called before entering freeze mode PRE_FREEZE -- will be called before entering freeze mode
POSTFREEZE -- will be called immediately after exiting freeze mode POST_FREEZE -- will be called immediately after exiting freeze mode
-- These take a LevelEndReason arg, like OnEnd -- These take a LevelEndReason arg, like OnEnd
PREEND -- will be called immediately before OnEnd PRE_END -- will be called immediately before OnEnd
POSTEND -- will be called immediately after OnEnd POST_END -- will be called immediately after OnEnd
-- These take functions which accepts a deltaTime argument -- These take functions which accepts a deltaTime argument
PRELOOP -- will be called in the beginning of game loop PRE_LOOP -- will be called in the beginning of game loop
POSTLOOP -- will be called at the end of game loop POST_LOOP -- will be called at the end of game loop
-- These take functions which accepts an objectNumber argument, like OnUseItem -- These take functions which accepts an objectNumber argument, like OnUseItem
PREUSEITEM -- will be called immediately before OnUseItem PRE_USE_ITEM -- will be called immediately before OnUseItem
POSTUSEITEM -- will be called immediately after OnUseItem POST_USE_ITEM -- will be called immediately after OnUseItem
The order in which two functions with the same CallbackPoint are called is undefined. The order in which two functions with the same CallbackPoint are called is undefined.
i.e. if you register `MyFunc` and `MyFunc2` with `PRELOOP`, both will be called in the beginning of game loop, but there is no guarantee that `MyFunc` will be called before `MyFunc2`, or vice-versa. i.e. if you register `MyFunc` and `MyFunc2` with `PRELOOP`, both will be called in the beginning of game loop, but there is no guarantee that `MyFunc` will be called before `MyFunc2`, or vice-versa.
@ -314,7 +337,7 @@ Possible event type values:
START START
END END
LOOP LOOP
USEITEM USE_ITEM
MENU MENU
@function HandleEvent @function HandleEvent
@ -1182,9 +1205,9 @@ and provides the delta time (a float representing game time since last call) via
@tfield function OnSave Will be called when the player saves the game, just *before* data is saved @tfield function OnSave Will be called when the player saves the game, just *before* data is saved
@tfield function OnEnd(EndReason) Will be called when leaving a level. This includes finishing it, exiting to the menu, or loading a save in a different level. It can take an `EndReason` arg: @tfield function OnEnd(EndReason) Will be called when leaving a level. This includes finishing it, exiting to the menu, or loading a save in a different level. It can take an `EndReason` arg:
EXITTOTITLE EXIT_TO_TITLE
LEVELCOMPLETE LEVEL_COMPLETE
LOADGAME LOAD_GAME
DEATH DEATH
OTHER OTHER
@ -1221,10 +1244,12 @@ void LogicHandler::InitCallbacks()
assignCB(m_onStart, ScriptReserved_OnStart); assignCB(m_onStart, ScriptReserved_OnStart);
assignCB(m_onLoad, ScriptReserved_OnLoad); assignCB(m_onLoad, ScriptReserved_OnLoad);
assignCB(m_onLoop, ScriptReserved_OnControlPhase);
assignCB(m_onLoop, ScriptReserved_OnLoop); assignCB(m_onLoop, ScriptReserved_OnLoop);
assignCB(m_onSave, ScriptReserved_OnSave); assignCB(m_onSave, ScriptReserved_OnSave);
assignCB(m_onEnd, ScriptReserved_OnEnd); assignCB(m_onEnd, ScriptReserved_OnEnd);
assignCB(m_onUseItem, ScriptReserved_OnUseItem); assignCB(m_onUseItem, ScriptReserved_OnUseItem);
assignCB(m_onBreak, ScriptReserved_OnFreeze); assignCB(m_onBreak, ScriptReserved_OnFreeze);
// COMPATIBILITY
assignCB(m_onLoop, "OnControlPhase");
} }