-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
170 lines (157 loc) · 6.77 KB
/
client.lua
File metadata and controls
170 lines (157 loc) · 6.77 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
-- ShadowForge DevTools — Client orchestrator
-- Detects framework, registers commands & keybind, opens the main panel.
SFD = SFD or {}
SFD.State = SFD.State or {}
SFD.State.spawnedProps = SFD.State.spawnedProps or {}
SFD.State.spawnedPeds = SFD.State.spawnedPeds or {}
SFD.State.savedLocations = SFD.State.savedLocations or {}
-- ───────────────────────────────────────────────
-- Framework & dependency detection
-- ───────────────────────────────────────────────
local function detect()
SFD.Detected = {
ox_lib = GetResourceState('ox_lib') == 'started',
ox_target = GetResourceState('ox_target') == 'started',
ox_inventory = GetResourceState('ox_inventory') == 'started',
qbx_core = GetResourceState('qbx_core') == 'started',
qb_core = GetResourceState('qb-core') == 'started',
es_extended = GetResourceState('es_extended') == 'started',
}
if SFD.Detected.qbx_core then
SFD.Framework = 'qbox'
elseif SFD.Detected.qb_core then
SFD.Framework = 'qbcore'
elseif SFD.Detected.es_extended then
SFD.Framework = 'esx'
else
SFD.Framework = 'standalone'
end
end
CreateThread(function()
Wait(500)
detect()
end)
-- ───────────────────────────────────────────────
-- Main panel
-- ───────────────────────────────────────────────
local MAIN = 'sfd_main_menu'
local ABOUT = 'sfd_about'
local function buildMainMenu()
local options = {}
for _, mod in ipairs(SFD.Modules) do
if Config.Modules[mod.id] ~= false then
options[#options + 1] = {
title = mod.label,
description = mod.description or '',
icon = mod.icon or 'wrench',
iconColor = mod.iconColor,
arrow = true,
onSelect = function() mod.open() end,
}
end
end
if Config.Modules.settings ~= false then
options[#options + 1] = {
title = 'About & Status',
description = 'Framework, dependencies, version',
icon = 'circle-info',
arrow = true,
onSelect = function() SFD.OpenAbout() end,
}
end
lib.registerContext({
id = MAIN,
title = Config.UI.panelTitle,
menu = nil,
canClose = true,
options = options,
})
end
function SFD.OpenPanel()
if Config.Permissions.require and not SFD.HasPermission('base') then
SFD.Notify.error('You do not have permission to use ShadowForge DevTools.')
return
end
buildMainMenu()
lib.showContext(MAIN)
SFD.LogServer('open', {})
end
function SFD.OpenMain()
SFD.OpenPanel()
end
function SFD.OpenAbout()
detect()
local fwLabel = ({
qbox = 'Qbox (qbx_core)',
qbcore = 'QBCore (qb-core)',
esx = 'ESX (es_extended)',
standalone = 'Standalone',
})[SFD.Framework] or SFD.Framework
local function dep(name, ok)
return ('%s — %s'):format(name, ok and '✓ started' or '✗ not started')
end
lib.registerContext({
id = ABOUT,
title = 'About & Status',
menu = MAIN,
canClose = true,
options = {
{ title = 'Version', description = '1.0.0', icon = 'tag' },
{ title = 'Resource', description = SFD.ResourceName, icon = 'box' },
{ title = 'Framework', description = fwLabel, icon = 'sitemap' },
{ title = 'Game build', description = tostring(GetGameBuildNumber and GetGameBuildNumber() or 'n/a'), icon = 'gamepad' },
{ title = dep('ox_lib', SFD.Detected.ox_lib), icon = 'puzzle-piece' },
{ title = dep('ox_target', SFD.Detected.ox_target), icon = 'crosshairs' },
{ title = dep('ox_inventory', SFD.Detected.ox_inventory), icon = 'boxes-stacked' },
{ title = dep('qbx_core', SFD.Detected.qbx_core), icon = 'cube' },
{ title = dep('qb-core', SFD.Detected.qb_core), icon = 'cube' },
{ title = dep('es_extended', SFD.Detected.es_extended), icon = 'cube' },
{
title = 'GitHub & Issues',
description = 'Open the project repository',
icon = 'fab fa-github',
onSelect = function()
SFD.SetClipboard('https://github.com/shadowforge/shadowforge-devtools')
SFD.Notify.info('Repository URL copied to clipboard.')
end,
},
{
title = 'Back',
icon = 'arrow-left',
onSelect = function() SFD.OpenPanel() end,
},
},
})
lib.showContext(ABOUT)
end
-- ───────────────────────────────────────────────
-- Commands & keybind
-- ───────────────────────────────────────────────
for _, cmd in ipairs(Config.Commands) do
RegisterCommand(cmd, function() SFD.OpenPanel() end, false)
TriggerEvent('chat:addSuggestion', '/' .. cmd, 'Open ShadowForge DevTools')
end
if Config.Keybind.enabled and lib and lib.addKeybind then
lib.addKeybind({
name = Config.Keybind.name,
description = Config.Keybind.description,
defaultKey = Config.Keybind.defaultKey,
onPressed = function() SFD.OpenPanel() end,
})
end
-- ───────────────────────────────────────────────
-- Cleanup on resource stop
-- ───────────────────────────────────────────────
AddEventHandler('onResourceStop', function(resource)
if resource ~= GetCurrentResourceName() then return end
for _, ent in pairs(SFD.State.spawnedProps or {}) do
if DoesEntityExist(ent) then DeleteEntity(ent) end
end
for _, ent in pairs(SFD.State.spawnedPeds or {}) do
if DoesEntityExist(ent) then DeleteEntity(ent) end
end
if lib and lib.hideTextUI then lib.hideTextUI() end
if SFD.State.noclipActive and SFD.PlayerTools and SFD.PlayerTools.disableNoclip then
SFD.PlayerTools.disableNoclip()
end
end)