Skip to content

Commit

Permalink
refactor(client/api): formatted TypeError for addTarget
Browse files Browse the repository at this point in the history
Because people use the api wrong.
  • Loading branch information
thelindat committed Oct 18, 2022
1 parent b4fe9d8 commit 0904966
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 12 additions & 5 deletions client/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@ function target.removeZone(id)
end

---@param target table
---@param add table
---@param options table
---@param resource string
local function addTarget(target, add, resource)
local function addTarget(target, options, resource)
local optionsType = type(options)

if optionsType ~= 'table' then
TypeError('options', 'table', optionsType)
end

local num = #target
for i = 1, #add do

for i = 1, #options do
num += 1
add[i].resource = resource or 'ox_target'
target[num] = add[i]
options[i].resource = resource or 'ox_target'
target[num] = options[i]
end
end

Expand Down
8 changes: 8 additions & 0 deletions client/utils.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
---Throws a formatted type error
---@param variable string
---@param expected string
---@param received string
function TypeError(variable, expected, received)
error(("expected %s to have type '%s' (received %s)"):format(variable, expected, received))
end

local GetWorldCoordFromScreenCoord = GetWorldCoordFromScreenCoord
local StartShapeTestLosProbe = StartShapeTestLosProbe
local GetShapeTestResultIncludingMaterial = GetShapeTestResultIncludingMaterial
Expand Down

0 comments on commit 0904966

Please sign in to comment.