-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodmain.lua
336 lines (277 loc) · 8.68 KB
/
modmain.lua
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
----
-- Modmain.
--
-- **Source Code:** [https://github.com/dstmodders/mod-dev-tools](https://github.com/dstmodders/mod-dev-tools)
--
-- @author [Depressed DST Modders](https://github.com/dstmodders)
-- @copyright 2020
-- @license MIT
-- @release 0.8.0-alpha
----
local _G = GLOBAL
local require = _G.require
_G.MOD_DEV_TOOLS_TEST = false
--- Globals
-- @section globals
local CONTROL_ACCEPT = _G.CONTROL_ACCEPT
local KEY_SHIFT = _G.KEY_SHIFT
local TheInput = _G.TheInput
--- SDK
-- @section sdk
local SDK
SDK = require("devtools/sdk/sdk/sdk")
SDK.Load(env, "devtools/sdk")
--- Debugging
-- @section debugging
SDK.Debug.SetIsEnabled(GetModConfigData("debug") and true or false)
SDK.Debug.ModConfigs()
--- Initialization
-- @section initialization
require("devtools/console")
local devtools
devtools = require("devtools")()
_G.DevTools = devtools
_G.DevToolsAPI = devtools:GetAPI()
-- config
devtools:SetConfig("key_select", SDK.Config.GetModKeyConfigData("key_select"))
devtools:SetConfig("key_switch_data", SDK.Config.GetModKeyConfigData("key_switch_data"))
local DevToolsScreen -- not an instance
DevToolsScreen = require("screens/devtoolsscreen")
DevToolsScreen:DoInit(devtools)
--- Mod warning override
-- @section mod-warning-override
_G.DISABLE_MOD_WARNING = GetModConfigData("default_mod_warning")
--- Player
-- @section player
SDK.OnEnterCharacterSelect(function(world)
devtools:DoTermPlayer()
devtools:DoTermWorld()
devtools:DoInitWorld(world)
end)
SDK.OnPlayerActivated(function(world, player)
devtools.inst = player
devtools:DoInitWorld(world)
devtools:DoInitPlayer(player)
if devtools then
local playertools = devtools.player
if playertools then
local crafting = playertools.crafting
local vision = playertools.vision
if SDK.Player.IsAdmin() and GetModConfigData("default_god_mode") then
if GetModConfigData("default_god_mode") then
playertools:ToggleGodMode()
end
end
if crafting and SDK.Player.IsAdmin() then
if GetModConfigData("default_free_crafting") then
SDK.Player.Craft.ToggleFreeCrafting(player)
end
end
if vision then
if GetModConfigData("default_forced_hud_visibility") then
vision:ToggleForcedHUDVisibility()
end
if GetModConfigData("default_forced_unfading") then
SDK.Vision.ToggleUnfading()
end
end
end
if devtools.labels then
devtools.labels:SetFont(_G[GetModConfigData("default_labels_font")])
devtools.labels:SetFontSize(GetModConfigData("default_labels_font_size"))
devtools.labels:SetIsSelectedEnabled(GetModConfigData("default_selected_labels"))
devtools.labels:SetIsUsernameEnabled(GetModConfigData("default_username_labels"))
devtools.labels:SetUsernameMode(GetModConfigData("default_username_labels_mode"))
end
end
end)
SDK.OnPlayerDeactivated(function()
devtools.inst = nil
end)
--- Console
-- @section console
SDK.Console.AddWordPredictionDictionaries({
{ delim = "De", num_chars = 0, words = { "vTools" } },
{ delim = "du", num_chars = 2, words = { "mptable" } },
{
delim = "d_",
num_chars = 0,
words = {
-- general
"decodefile",
"decodesavedata",
"doaction",
"emote",
"emotepose",
"emotestop",
"findinventoryitem",
"findinventoryitems",
"gettags",
"say",
"says",
-- animstate
"getanim",
"getanimbank",
"getanimbuild",
-- dump
"dumpcomponents",
"dumpeventlisteners",
"dumpfields",
"dumpfunctions",
"dumpreplicas",
"getcomponents",
"geteventlisteners",
"getfields",
"getfunctions",
"getreplicas",
-- stategraph
"getsgname",
"getsgstate",
-- table
"tablecompare",
"tablecount",
"tablehasvalue",
"tablekeybyvalue",
"tablemerge",
},
},
function()
local words = SDK.Dump.GetFunctions(devtools, true)
for k, word in pairs(words) do
if word == "is_a" or word ~= "_ctor" or not string.match(word, "^Debug") then
table.remove(words, k)
end
end
return { delim = "DevTools:", num_chars = 0, words = words }
end,
})
--- Player Controller
-- @section player-controller
SDK.OnLoadComponent("playercontroller", function(self)
devtools:GetDebug():DoInitPlayerController(self)
end)
SDK.OverrideComponentMethod("playercontroller", "OnControl", function(old, self, control, down)
if not devtools then
old(self, control, down)
return
end
if not devtools.player.controller then
devtools.player.controller = self
end
if devtools then
-- screen
if
DevToolsScreen
and not DevToolsScreen:IsOpen()
and control == CONTROL_ACCEPT
and SDK.Time.IsPaused()
then
SDK.Time.Resume()
end
-- player
if devtools.player then
devtools.player:SetIsMoveButtonDown(down and SDK.Input.IsControlMove(control))
end
end
end)
--- Prefabs
-- @section prefabs
env.AddPlayerPostInit(function(inst)
if not inst.Label then
inst.entity:AddLabel()
end
inst:ListenForEvent("changearea", function()
if devtools and devtools.labels then
devtools.labels:AddUsername(inst)
end
end)
end)
env.AddPrefabPostInitAny(function(inst)
if devtools and devtools.IsSpawnersVisibility then
if devtools:IsSpawnersVisibility() and devtools:IsSpawner(inst) then
inst:DoTaskInTime(0.1, function()
devtools:ShowSpawner(inst)
end)
end
end
end)
--- Keybinds
-- @section keybinds
local key_options = {
ignore_has_input_focus = { "ModDevToolsScreen" },
ignore_screens = { "ConsoleScreen", "MapScreen" },
}
SDK.Input.AddConfigKeyUpHandler("key_toggle_tools", function()
if DevToolsScreen and DevToolsScreen:CanToggle() then
DevToolsScreen:Toggle()
end
end, key_options)
SDK.Input.AddConfigKeyUpHandler("key_movement_prediction", function()
if _G.ThePlayer and not SDK.World.IsMasterSim() then
SDK.Player.ToggleMovementPrediction()
end
end, key_options)
SDK.Input.AddConfigKeyUpHandler("key_pause", function()
SDK.Time.TogglePause()
end, key_options)
SDK.Input.AddConfigKeyUpHandler("key_god_mode", function()
local playertools = SDK.Utils.Chain.Get(devtools, "player")
if playertools then
playertools:ToggleGodMode()
end
end, key_options)
local _KEY_TELEPORT = SDK.Config.GetModKeyConfigData("key_teleport")
SDK.Input.AddConfigKeyDownHandler("key_teleport", function()
local playertools = SDK.Utils.Chain.Get(devtools, "player")
if playertools then
playertools:Teleport(_KEY_TELEPORT)
end
end, {
ignore_has_input_focus = { "MapScreen", "ModDevToolsScreen" },
ignore_screens = { "ConsoleScreen" },
})
SDK.Input.AddConfigKeyUpHandler("key_select_entity", function()
local worldtools = SDK.Utils.Chain.Get(devtools, "world")
if worldtools then
worldtools:SelectEntityUnderMouse()
end
end, key_options)
SDK.Input.AddConfigKeyDownHandler("key_time_scale_increase", function()
if TheInput:IsKeyDown(KEY_SHIFT) then
SDK.Time.SetTimeScale(4)
else
SDK.Time.SetDeltaTimeScale(0.1)
end
end, key_options)
SDK.Input.AddConfigKeyDownHandler("key_time_scale_decrease", function()
if TheInput:IsKeyDown(KEY_SHIFT) then
SDK.Time.SetTimeScale(0)
else
SDK.Time.SetDeltaTimeScale(-0.1)
end
end, key_options)
SDK.Input.AddConfigKeyUpHandler("key_time_scale_default", function()
SDK.Time.SetTimeScale(1)
end, key_options)
--- Reset
-- @section reset
local KEY_R = _G.KEY_R
local function Reset(key)
if TheInput:IsKeyDown(key) then
SDK.Reload()
end
end
local _RESET_COMBINATION = GetModConfigData("reset_combination")
if _RESET_COMBINATION == "ctrl_r" then
TheInput:AddKeyUpHandler(KEY_R, function()
return Reset(_G.KEY_CTRL)
end)
elseif _RESET_COMBINATION == "alt_r" then
TheInput:AddKeyUpHandler(KEY_R, function()
return Reset(_G.KEY_ALT)
end)
elseif _RESET_COMBINATION == "shift_r" then
TheInput:AddKeyUpHandler(KEY_R, function()
return Reset(KEY_SHIFT)
end)
end