forked from Benjamin-Dobell/ge_tts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebug.ttslua
49 lines (38 loc) · 1.21 KB
/
Debug.ttslua
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
local ChatCommands = require('ge_tts.ChatCommands')
---@class tts__Debug
local Debug = {}
---@overload fun(): void
---@param prefix nil | string
function Debug.createGlobals(prefix)
Wait.frames(function()
prefix = prefix or ''
-- First directory is the "scripts", which we don't want.
for packageName, package in pairs(_LOADED) do
if packageName:sub(1, 7) == 'ge_tts.' then
local identifier = prefix .. packageName:sub(8):gsub('/', '__')
_G[identifier] = package
end
end
print('Initialized Debug globals with "' .. prefix .. '" prefix.')
end, 1)
end
---@param value string
---@param player tts__Player
local onChatCommand = function(value, player)
if player.host then
---@type string[]
local components = {}
for component in string.gmatch(value, "([^ ]+)") do
table.insert(components, component)
end
if #components == 0 then
return
end
local subcommand = components[1]
if subcommand == 'globals' then
Debug.createGlobals(components[2])
end
end
end
ChatCommands.addCommand('debug', onChatCommand)
return Debug