Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: toggle bridge on/off via convar #251

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bridge/qb/client/drawtext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ RegisterNetEvent('qb-core:client:KeyPressed', function()
keyPressed()
end)

require 'bridge.qb.client.main'
local createQbExport = require 'bridge.qb.shared.export-function'

---@deprecated use ox_lib showTextUI calls directly
CreateQbExport('DrawText', drawText)
createQbExport('DrawText', drawText)
---@deprecated use ox_lib showTextUI calls directly
CreateQbExport('ChangeText', changeText)
createQbExport('ChangeText', changeText)
---@deprecated use ox_lib showTextUI calls directly
CreateQbExport('HideText', hideText)
createQbExport('HideText', hideText)
---@deprecated use ox_lib showTextUI calls directly
CreateQbExport('KeyPressed', keyPressed)
createQbExport('KeyPressed', keyPressed)
13 changes: 7 additions & 6 deletions bridge/qb/client/main.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
if GetConvar('qbx:enablebridge', 'true') == 'false' then return end

require 'bridge.qb.client.drawtext'
require 'bridge.qb.client.events'

local qbCoreCompat = {}
qbCoreCompat.PlayerData = QBX.PlayerData
qbCoreCompat.Config = lib.table.merge(require 'config.client', require 'config.shared')
Expand Down Expand Up @@ -56,12 +61,8 @@ function qbCoreCompat.Debug(_, obj)
lib.print.debug(obj)
end

function CreateQbExport(name, cb)
AddEventHandler(string.format('__cfx_export_qb-core_%s', name), function(setCB)
setCB(cb)
end)
end
local createQbExport = require 'bridge.qb.shared.export-function'

CreateQbExport('GetCoreObject', function()
createQbExport('GetCoreObject', function()
return qbCoreCompat
end)
32 changes: 14 additions & 18 deletions bridge/qb/server/functions.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
require 'server.functions'
local functions = {}

function CreateQbExport(name, cb)
AddEventHandler(string.format('__cfx_export_qb-core_%s', name), function(setCB)
setCB(cb)
end)
end
local createQbExport = require 'bridge.qb.shared.export-function'

function AddDeprecatedFunctions(player)
if not player then return end
Expand Down Expand Up @@ -112,7 +108,7 @@ local function AddItem(itemName, item)
end

functions.AddItem = AddItem
CreateQbExport('AddItem', AddItem)
createQbExport('AddItem', AddItem)

-- Single update item
---@deprecated incompatible with ox_inventory. Update ox_inventory item config instead.
Expand All @@ -131,7 +127,7 @@ local function UpdateItem(itemName, item)
end

functions.UpdateItem = UpdateItem
CreateQbExport('UpdateItem', UpdateItem)
createQbExport('UpdateItem', UpdateItem)

-- Multiple Add Items
---@deprecated incompatible with ox_inventory. Update ox_inventory item config instead.
Expand Down Expand Up @@ -166,7 +162,7 @@ local function AddItems(items)
end

functions.AddItems = AddItems
CreateQbExport('AddItems', AddItems)
createQbExport('AddItems', AddItems)

-- Single Remove Item
---@deprecated incompatible with ox_inventory. Update ox_inventory item config instead.
Expand All @@ -188,7 +184,7 @@ local function RemoveItem(itemName)
end

functions.RemoveItem = RemoveItem
CreateQbExport('RemoveItem', RemoveItem)
createQbExport('RemoveItem', RemoveItem)

-- Single add job function which should only be used if you planning on adding a single job
---@deprecated use export CreateJobs
Expand All @@ -213,7 +209,7 @@ local function AddJob(jobName, job)
end

functions.AddJob = AddJob
CreateQbExport('AddJob', AddJob)
createQbExport('AddJob', AddJob)

-- Multiple Add Jobs
---@deprecated call export CreateJobs
Expand Down Expand Up @@ -241,7 +237,7 @@ local function AddJobs(jobs)
end

functions.AddJobs = AddJobs
CreateQbExport('AddJobs', AddJobs)
createQbExport('AddJobs', AddJobs)

-- Single Update Job
---@deprecated call CreateJobs
Expand All @@ -266,7 +262,7 @@ local function UpdateJob(jobName, job)
end

functions.UpdateJob = UpdateJob
CreateQbExport('UpdateJob', UpdateJob)
createQbExport('UpdateJob', UpdateJob)

-- Single Add Gang
---@deprecated call export CreateGangs
Expand All @@ -291,7 +287,7 @@ local function AddGang(gangName, gang)
end

functions.AddGang = AddGang
CreateQbExport('AddGang', AddGang)
createQbExport('AddGang', AddGang)

-- Single Update Gang
---@deprecated call export CreateGangs
Expand All @@ -316,7 +312,7 @@ local function UpdateGang(gangName, gang)
end

functions.UpdateGang = UpdateGang
CreateQbExport('UpdateGang', UpdateGang)
createQbExport('UpdateGang', UpdateGang)

-- Multiple Add Gangs
---@deprecated call export CreateGangs
Expand All @@ -343,13 +339,13 @@ local function AddGangs(gangs)
end

functions.AddGangs = AddGangs
CreateQbExport('AddGangs', AddGangs)
createQbExport('AddGangs', AddGangs)

functions.RemoveJob = RemoveJob
CreateQbExport('RemoveJob', RemoveJob)
createQbExport('RemoveJob', RemoveJob)

functions.RemoveGang = RemoveGang
CreateQbExport('RemoveGang', RemoveGang)
createQbExport('RemoveGang', RemoveGang)

---Add a new function to the Functions table of the player class
---Use-case:
Expand Down Expand Up @@ -432,7 +428,7 @@ local function SetMethod(methodName, handler)
end

functions.SetMethod = SetMethod
CreateQbExport("SetMethod", SetMethod)
createQbExport("SetMethod", SetMethod)

-- Add or change (a) field(s) in the QBCore table
---@deprecated
Expand Down
9 changes: 8 additions & 1 deletion bridge/qb/server/main.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
if GetConvar('qbx:enablebridge', 'true') == 'false' then return end

require 'bridge.qb.server.debug'
require 'bridge.qb.server.events'

local qbCoreCompat = {}

qbCoreCompat.Config = lib.table.merge(require 'config.server', require 'config.shared')
Expand Down Expand Up @@ -93,6 +98,8 @@ qbCoreCompat.Functions.CreateCallback('QBCore:Server:CreateVehicle', function(so
if netId then cb(netId) end
end)

CreateQbExport('GetCoreObject', function()
local createQbExport = require 'bridge.qb.shared.export-function'

createQbExport('GetCoreObject', function()
return qbCoreCompat
end)
5 changes: 5 additions & 0 deletions bridge/qb/shared/export-function.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return function (name, cb)
AddEventHandler(string.format('__cfx_export_qb-core_%s', name), function(setCB)
setCB(cb)
end)
end
14 changes: 7 additions & 7 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ client_scripts {
'client/events.lua',
'client/character.lua',
'client/discord.lua',
'bridge/qb/client/drawtext.lua',
'bridge/qb/client/events.lua',
'bridge/qb/client/main.lua',
}

server_scripts {
Expand All @@ -34,10 +33,7 @@ server_scripts {
'server/loops.lua',
'server/storage.lua',
'server/character.lua',
'bridge/qb/server/commands.lua',
'bridge/qb/server/debug.lua',
'bridge/qb/server/main.lua',
'bridge/qb/server/events.lua',
}

modules {
Expand All @@ -53,12 +49,16 @@ files {
'shared/main.lua',
'shared/vehicles.lua',
'shared/weapons.lua',
'bridge/qb/client/main.lua',
'bridge/qb/client/functions.lua',
'bridge/qb/client/drawtext.lua',
'bridge/qb/client/events.lua',
'bridge/qb/shared/main.lua',
'bridge/qb/shared/export-function.lua',
'bridge/qb/server/functions.lua',
'bridge/qb/server/main.lua',
'bridge/qb/server/player.lua',
'bridge/qb/server/commands.lua',
'bridge/qb/server/debug.lua',
'bridge/qb/server/events.lua',
'config/client.lua',
'config/shared.lua'
}
Expand Down
Loading