-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIGE_Utils.lua
More file actions
216 lines (191 loc) · 6.18 KB
/
Copy pathIGE_Utils.lua
File metadata and controls
216 lines (191 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
-- Released under GPL v3
--------------------------------------------------------------
-------------------------------------------------------------------------------------------------
local function IsModActive(iModID)
for i, mod in pairs(Modding.GetActivatedMods()) do
if (mod.ID == iModID) then
return true
end
end
return false
end
if Map.GetPlot(0,0).GetCulture then --Check if you have Gods & Kings DLC
IGE_HasGodsAndKings = false;
else
IGE_HasGodsAndKings = true;
end
if Map.GetPlot(0,0).GetArchaeologyArtifactEra then --Check if you have Brave New World DLC
IGE_HasBraveNewWorld = true;
else
IGE_HasBraveNewWorld = false;
end
if (PreGame.IsVictory(GameInfo.Victories["VICTORY_SPACE_RACE"].ID)) then --Check if Science Victory is enabled
IGE_ScienceVictory = true;
else
IGE_ScienceVictory = false;
end
IGE_EUI = false;
for row in DB.Query("SELECT * FROM Language_en_US WHERE Tag = 'TXT_KEY_EUI_UNIT_FOUND'") do
IGE_EUI = true; --Check if you use Enhance User Interface
end
--add check for Community Patch or Various Mod Components
local sDLLID = "d1b6328c-ff44-4b0d-aad7-c657f83610cd";
if IsModActive(sDLLID) and Game.GetCustomModOption('COMMUNITY_PATCH') ~= nil then --Check if Community Patch is enabled
IGE_HasCommunityPatch = true;
else
IGE_HasCommunityPatch = false;
end
if IsModActive(sDLLID) and Game.GetCustomModOption('COMMUNITY_PATCH') == nil then --Check if VMC is enabled
IGE_HasVMC = true;
else
IGE_HasVMC = false;
end
--add check for Vox Populi
local sVoxPopuliID = "8411a7a8-dad3-4622-a18e-fcc18324c799";
if IsModActive(sVoxPopuliID) then --Check if Vox Populi is enabled
IGE_HasVoxPopuli = true;
else
IGE_HasVoxPopuli = false;
end
--add check for More Wonders for VP mod
local sMoreWondersVPID = "3e151552-1683-4881-b736-8ee89226f599";
if IsModActive(sMoreWondersVPID) then --Check if More Wonders for VP is enabled
IGE_HasMoreWondersVP = true;
else
IGE_HasMoreWondersVP = false;
end
-------------------------------------------------------------------------------------------------
function L(str, ...)
if str == nil then return "???" end
if type(str) ~= "string" then return tostring(str) end
return Locale.ConvertTextKey(str, ...);
end
-------------------------------------------------------------------------------------------------
function clone(x)
local y = {};
for k, v in pairs(x) do
y[k] = v;
end
return y;
end
-------------------------------------------------------------------------------------------------
function getstr(x)
if x == nil then
return "nil";
elseif type(x) == "boolean" then
return (x and "true" or "false");
elseif type(x) == "string" then
return '"'..x..'"';
elseif type(x) == "number" then
return tostring(x);
else
return "...";
end
end
-------------------------------------------------------------------------------------------------
function dump(x)
if x == nil then
print("nil");
elseif type(x) == "table" then
for k, v in pairs(x) do
print(k.." = "..getstr(v));
end
else
print(getstr(x));
end
end
-------------------------------------------------------------------------------------------------
function dumpMembers(x)
for k in pairs(x) do
dump(k);
end
end
-------------------------------------------------------------------------------------------------
function dumpMetaIndex(x)
for k in pairs(getmetatable(x).__index) do
dump(k);
end
end
-------------------------------------------------------------------------------------------------
function implode(items, keyName, separator)
separator = separator or ", ";
local str = "";
local first = true;
for _, v in ipairs(items) do
if not first then str = str..separator end
str = str..v[keyName];
first = false;
end
return str;
end
-------------------------------------------------------------------------------------------------
function lastIndexOf(str, c)
str = string.reverse(str);
local index = string.find(str, c);
if not index then return 0 end
return string.len(str) + 1 - index;
end
-------------------------------------------------------------------------------------------------
function getFileName(path)
local index = lastIndexOf(path, "\\") or lastIndexOf(path, "/");
return string.sub(path, index + 1);
end
-------------------------------------------------------------------------------------------------
function getStackTrace()
local trace = {};
local level = 2
while true do
local info = debug.getinfo(level, "nSl")
if not info then break end
if info.what == "C" then -- is a C function?
table.insert(trace, "C function");
else
-- a Lua function
local userStr = getFileName(info.source)..": "..info.currentline;
if (info.name and string.len(info.name)) then
userStr = userStr.." ("..info.name..")";
end
table.insert(trace, userStr);
end
level = level + 1
end
return trace;
end
-------------------------------------------------------------------------------------------------
function FormatError(err, levelsToIgnoreBelow)
levelsToIgnoreBelow = levelsToIgnoreBelow or 0;
levelsToIgnoreBelow = levelsToIgnoreBelow + 1;
print(err);
-- Slice error to make it change its formatting later
local index = string.find(err, "...", 1, true); -- Path truncated with '...'
if not index then index = -5 end
local index2 = index + 6; -- Line error starts here
local index3 = string.find(err, ":", index2, true) + 1; -- Error message starts here
-- Fix error message, prints it, appends the trace when available
if debug and debug.getinfo then
err = string.sub(err, index3);
-- Stack trace: 1 is this function, 2 is the error handler, 3 is the C function calling the handler, 4 is the error location, 5 and greater are LUA calls
local trace = getStackTrace();
for i, v in ipairs(trace) do
print(v);
if (i > levelsToIgnoreBelow) then
err = err.."[NEWLINE]"..v;
end
end
else
err = "line "..string.sub(err, index2);
end
return err;
end
-------------------------------------------------------------------------------------------------
function DefaultSort(a, b)
local leftPriority = a.priority or 0;
local rightPriority = b.priority or 0;
if leftPriority > rightPriority then
return true;
elseif leftPriority < rightPriority then
return false;
else
return Locale.Compare(a.name, b.name) == -1;
end
end