Skip to content

Commit 02f3f8b

Browse files
committed
Add PostFX Lua functions
1 parent 3455837 commit 02f3f8b

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

Client/mods/deathmatch/logic/lua/CLuaManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "../luadefs/CLuaFireDefs.h"
1414
#include "../luadefs/CLuaClientDefs.h"
1515
#include "../luadefs/CLuaVectorGraphicDefs.h"
16+
#include "../luadefs/CLuaPostfxDefs.h"
1617

1718
using std::list;
1819

@@ -283,4 +284,5 @@ void CLuaManager::LoadCFunctions()
283284
CLuaClientDefs::LoadFunctions();
284285
CLuaDiscordDefs::LoadFunctions();
285286
CLuaBuildingDefs::LoadFunctions();
287+
CLuaPostfxDefs::LoadFunctions();
286288
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: mods/shared_logic/luadefs/CLuaPostfxDefs.cpp
6+
* PURPOSE: Lua definitions class
7+
*
8+
* Multi Theft Auto is available from https://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#include "StdInc.h"
13+
#include "CLuaPostfxDefs.h"
14+
#include <lua/CLuaFunctionParser.h>
15+
16+
void CLuaPostfxDefs::LoadFunctions()
17+
{
18+
constexpr static const std::pair<const char*, lua_CFunction> functions[]{
19+
{"getPostFXValue", ArgumentParser<GetPostFXValue>},
20+
{"getPostFXMode", ArgumentParser<GetPostFXMode>},
21+
{"isPostFXEnabled", ArgumentParser<IsPostFXEnabled>},
22+
};
23+
24+
// Add functions
25+
for (const auto& [name, func] : functions)
26+
CLuaCFunctions::AddFunction(name, func);
27+
}
28+
29+
std::variant<float, bool> CLuaPostfxDefs::GetPostFXValue(int type)
30+
{
31+
switch (static_cast<int>(type))
32+
{
33+
case 0: // Gamma
34+
return g_pCore->GetCVars()->GetValue<float>("borderless_gamma_power", 0.0f);
35+
case 1: // Brightness
36+
return g_pCore->GetCVars()->GetValue<float>("borderless_brightness_scale", 0.0f);
37+
case 2: // Contrast
38+
return g_pCore->GetCVars()->GetValue<float>("borderless_contrast_scale", 0.0f);
39+
case 3: // Saturation
40+
return g_pCore->GetCVars()->GetValue<float>("borderless_saturation_scale", 0.0f);
41+
default:
42+
return false;
43+
}
44+
}
45+
46+
int CLuaPostfxDefs::GetPostFXMode()
47+
{
48+
return g_pCore->GetCVars()->GetValue<bool>("borderless_apply_fullscreen", false) ? 1
49+
: g_pCore->GetCVars()->GetValue<bool>("borderless_apply_windowed", false) ? 2
50+
: 0;
51+
}
52+
53+
bool CLuaPostfxDefs::IsPostFXEnabled(int type)
54+
{
55+
switch (static_cast<int>(type))
56+
{
57+
case 0: // Gamma
58+
return g_pCore->GetCVars()->GetValue<bool>("borderless_gamma_enabled", false);
59+
case 1: // Brightness
60+
return g_pCore->GetCVars()->GetValue<bool>("borderless_brightness_enabled", false);
61+
case 2: // Contrast
62+
return g_pCore->GetCVars()->GetValue<bool>("borderless_contrast_enabled", false);
63+
case 3: // Saturation
64+
return g_pCore->GetCVars()->GetValue<bool>("borderless_saturation_enabled", false);
65+
default:
66+
return false;
67+
}
68+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: mods/shared_logic/luadefs/CLuaPostfxDefs.h
6+
* PURPOSE: Lua definitions class
7+
*
8+
* Multi Theft Auto is available from https://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#include "luadefs/CLuaDefs.h"
13+
14+
class CLuaPostfxDefs : public CLuaDefs
15+
{
16+
public:
17+
static void LoadFunctions();
18+
19+
private:
20+
static std::variant<float, bool> GetPostFXValue(int type);
21+
static int GetPostFXMode();
22+
static bool IsPostFXEnabled(int type);
23+
};

0 commit comments

Comments
 (0)