Skip to content

Commit

Permalink
refactor(client): move debugWarning to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Sep 17, 2023
1 parent c7212d0 commit 5245217
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
21 changes: 8 additions & 13 deletions client/api.lua
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
---@class OxTargetOption
---@field resource? string

local utils = require 'client.utils'

local api = setmetatable({}, {
__newindex = function(self, index, value)
rawset(self, index, value)
exports(index, value)
end
})

local function debugWarning(msg)
local trace = Citizen.InvokeNative(`FORMAT_STACK_TRACE` & 0xFFFFFFFF, nil, 0, Citizen.ResultAsString())
local _, _, src = string.strsplit('\n', trace, 4)

warn(('%s ^0%s\n'):format(msg, src:gsub(".-%(", '(')))
end

---@param data OxTargetPolyZone
---@param data OxTargetPolyZone | table
---@return number
function api.addPolyZone(data)
if data.debug then debugWarning('Creating new PolyZone with debug enabled.') end
if data.debug then utils.warn('Creating new PolyZone with debug enabled.') end

data.resource = GetInvokingResource()
return lib.zones.poly(data).id
end

---@param data OxTargetBoxZone
---@param data OxTargetBoxZone | table
---@return number
function api.addBoxZone(data)
if data.debug then debugWarning('Creating new BoxZone with debug enabled.') end
if data.debug then utils.warn('Creating new BoxZone with debug enabled.') end

data.resource = GetInvokingResource()
return lib.zones.box(data).id
end

---@param data OxTargetSphereZone
---@param data OxTargetSphereZone | table
---@return number
function api.addSphereZone(data)
if data.debug then debugWarning('Creating new SphereZone with debug enabled.') end
if data.debug then utils.warn('Creating new SphereZone with debug enabled.') end

data.resource = GetInvokingResource()
return lib.zones.sphere(data).id
Expand Down
7 changes: 7 additions & 0 deletions client/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,11 @@ SetTimeout(0, function()
end
end)

function utils.warn(msg)
local trace = Citizen.InvokeNative(`FORMAT_STACK_TRACE` & 0xFFFFFFFF, nil, 0, Citizen.ResultAsString())
local _, _, src = string.strsplit('\n', trace, 4)

warn(('%s ^0%s\n'):format(msg, src:gsub(".-%(", '(')))
end

return utils

0 comments on commit 5245217

Please sign in to comment.