Skip to content

Commit cbfb6ff

Browse files
vaderkosazum4roll
authored andcommitted
Add CPK.Misc.CustomModOptionEnabled
1 parent 930001d commit cbfb6ff

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

(1) Community Patch/Community Patch.civ5proj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,6 +3552,10 @@
35523552
<SubType>Lua</SubType>
35533553
<ImportIntoVFS>True</ImportIntoVFS>
35543554
</Content>
3555+
<Content Include="Kit\Misc\CPK.Misc.CustomModOptionEnabled.lua">
3556+
<SubType>Lua</SubType>
3557+
<ImportIntoVFS>True</ImportIntoVFS>
3558+
</Content>
35553559
<Content Include="Kit\String\CPK.String.Distance.lua">
35563560
<SubType>Lua</SubType>
35573561
<ImportIntoVFS>True</ImportIntoVFS>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
local IsFunction = CPK.Type.IsFunction
2+
3+
local civ_db_create_query = DB.CreateQuery
4+
5+
local query = civ_db_create_query([[
6+
SELECT NULL
7+
FROM CustomModOptions
8+
WHERE Name = ? AND Value = 1
9+
LIMIT 1
10+
]])
11+
12+
--- Checks if a custom mod option exists and is enabled by the given name.
13+
--- Uses `Game.IsCustomModOption` if available, otherwise falls back to an SQL query.
14+
--- @param name string # The option name, e.g., "BALANCE_VP".
15+
--- @return boolean # True if the option exists in the database and has value 1, false otherwise.
16+
local function CustomModOptionEnabled(name)
17+
if Game and IsFunction(Game.IsCustomModOption) then
18+
return Game.IsCustomModOption(name)
19+
end
20+
21+
-- Using a direct SQL query should be faster
22+
-- than querying via GameInfo({ Name = name })().Value == 1,
23+
-- The GameInfo call creates more intermediate tables for both
24+
-- the query and the results and do not leverage cache
25+
-- because of the table structure.
26+
return query(name)() ~= nil
27+
end
28+
29+
CPK.Misc.CustomModOptionEnabled = CustomModOptionEnabled

0 commit comments

Comments
 (0)