-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd.lua
More file actions
265 lines (208 loc) · 5.44 KB
/
std.lua
File metadata and controls
265 lines (208 loc) · 5.44 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
GS_IS_EDITOR = getSelection ~= nil
GS_INPUT_HELP_MODE_AUTO = 1
GS_INPUT_HELP_MODE_KEYBOARD = 2
GS_INPUT_HELP_MODE_GAMEPAD = 3
GS_INPUT_HELP_MODE_TOUCH = 4
GS_PRIO_VERY_HIGH = 1
GS_PRIO_HIGH = 2
GS_PRIO_NORMAL = 3
GS_PRIO_LOW = 4
GS_PRIO_VERY_LOW = 5
GS_MONEY_EURO = 1
GS_MONEY_DOLLAR = 2
GS_MONEY_POUND = 3
function string.dump()
return ""
end
function loadfile()
end
function load()
return nil, "invalid function"
end
if setFileLogPrefixTimestamp == nil then
function setFileLogPrefixTimestamp(addTimestamp)
end
end
local registeredConsoleCommands = {}
if addConsoleCommand ~= nil then
local oldAddConsoleCommand = addConsoleCommand
function addConsoleCommand(name, description, ...)
if registeredConsoleCommands[name] == nil then
oldAddConsoleCommand(name, description, ...)
registeredConsoleCommands[name] = description
else
print(string.format("Error: Failed to register console command '%s. Command was already registered!", name))
end
end
end
if removeConsoleCommand ~= nil then
local oldRemoveConsoleCommand = removeConsoleCommand
function removeConsoleCommand(name, ...)
oldRemoveConsoleCommand(name, ...)
registeredConsoleCommands[name] = nil
end
end
function consoleCommandListCommands()
local sortedNames = {}
local maxNameLength = 0
for name in pairs(registeredConsoleCommands) do
sortedNames[#sortedNames + 1] = name
maxNameLength = math.max(maxNameLength, name:len())
end
table.sort(sortedNames)
setFileLogPrefixTimestamp(false)
for _, name in ipairs(sortedNames) do
local paddedName = name .. string.rep(" ", maxNameLength - name:len())
print(string.format("%s %s", paddedName, registeredConsoleCommands[name]))
end
print(string.format("# Listed %d script-based console commands. Use 'help' to get all commands", #sortedNames))
setFileLogPrefixTimestamp(g_logFilePrefixTimestamp)
end
if addConsoleCommand ~= nil then
addConsoleCommand("gsScriptCommandsList", "Lists script-based console commands. Use 'help' to get all commands", "consoleCommandListCommands", nil)
end
function string.posixFormat(fmt, ...)
local args = {
...
}
local order = {}
fmt = fmt:gsub("([%%]?)%%(%d+)%$", function (first, i)
if first == "%" then
return "%%" .. i .. "$"
end
table.insert(order, args[tonumber(i)])
return "%"
end)
if #order == 0 then
return string.format(fmt, ...)
end
return string.format(fmt, unpack(order))
end
function log(...)
local str = ""
for i = 1, select("#", ...) do
str = str .. " " .. tostring(select(i, ...))
end
print(str)
end
local function printTableRecursively(inputTable, inputIndent, depth, maxDepth)
inputIndent = inputIndent or " "
depth = depth or 0
maxDepth = maxDepth or 3
if depth > maxDepth then
return
end
local debugString = ""
for i, j in pairs(inputTable) do
print(inputIndent .. tostring(i) .. " :: " .. tostring(j))
if type(j) == "table" then
printTableRecursively(j, inputIndent .. " ", depth + 1, maxDepth)
end
end
return debugString
end
function print_r(tbl, depth)
if tbl == nil then
print("table: nil")
elseif type(tbl) ~= "table" then
print("table: no such table")
elseif next(tbl) == nil then
print("table: empty")
else
setFileLogPrefixTimestamp(false)
printTableRecursively(tbl, " ", 0, depth or 5)
setFileLogPrefixTimestamp(g_logFilePrefixTimestamp)
end
end
function printf(formatText, ...)
print(string.format(formatText, ...))
end
function assertWithCallstack(f, message)
if not f then
if message ~= nil and type(message) == "string" then
print("Error: assertion failed: " .. message)
else
print("Error: assertion failed!")
end
printCallstack()
error("Assertion failed")
end
end
function registerObjectClassName(object, className)
if g_currentMission ~= nil then
g_currentMission.objectsToClassName[object] = className
end
end
function unregisterObjectClassName(object)
if g_currentMission ~= nil then
g_currentMission.objectsToClassName[object] = nil
end
end
function getNormalizedScreenValues(x, y)
local values = GuiUtils.getNormalizedValues({
x,
y
}, {
g_referenceScreenWidth,
g_referenceScreenHeight
})
if values[1] == nil or values[2] == nil then
printCallstack()
end
local newX = values[1] * g_aspectScaleX
local newY = values[2] * g_aspectScaleY
return newX, newY
end
function getCorrectTextSize(size)
if g_aspectScaleY == nil then
return size
else
return size * g_aspectScaleY
end
end
function calculateFovY(cameraNode)
local fovY = getFovY(cameraNode)
if GS_IS_EDITOR then
return fovY
end
local maxAngle = fovY * g_fovYMax / g_fovYDefault
local maxDelta = g_fovYMax - g_fovYDefault
if g_fovYMax < maxAngle then
maxDelta = g_fovYMax - fovY
end
local loadedFovY = g_gameSettings:getValue("fovY")
if g_fovYDefault < loadedFovY then
return fovY + maxDelta * (1 - (g_fovYMax - loadedFovY) / (g_fovYMax - g_fovYDefault))
elseif loadedFovY < g_fovYDefault then
return fovY - maxDelta * (1 - (loadedFovY - g_fovYMin) / (g_fovYDefault - g_fovYMin))
else
return fovY
end
end
if GS_IS_EDITOR then
function getUserName()
return ""
end
function addConsoleCommand()
end
function removeConsoleCommand()
end
function getAppBasePath()
return ""
end
function getUserProfileAppPath()
return ""
end
function isHeadTrackingAvailable()
return false
end
end
if getHasGamepadAxisForceFeedback == nil then
function getHasGamepadAxisForceFeedback()
return false
end
end
if setGamepadAxisForceFeedback == nil then
function setGamepadAxisForceFeedback()
end
end