File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments