Skip to content

Commit

Permalink
feat: accessor functions in lieu of exposing tables
Browse files Browse the repository at this point in the history
  • Loading branch information
mafewtm committed May 25, 2024
1 parent 83616f4 commit 1b1ff6e
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 24 deletions.
28 changes: 22 additions & 6 deletions client/groups.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
local jobs = require 'shared.jobs'
local gangs = require 'shared.gangs'

---@return table<string, Job>
function GetJobs()
return jobs
---@param name string?
---@return table?
function GetJobs(name)
if not name then return jobs end

if type(name) ~= 'string' then return end

name = name:lower()

return jobs[name]
end

exports('GetJobs', GetJobs)

---@return table<string, Gang>
function GetGangs()
return gangs
---@param name string?
---@return table?
function GetGangs(name)
if not name then return gangs end

if type(name) ~= 'string' then return end

name = name:lower()

return gangs[name]
end

exports('GetGangs', GetGangs)

---@deprecated use the GetJobs function instead
---@param name string
---@return Job?
function GetJob(name)
Expand All @@ -23,6 +38,7 @@ end

exports('GetJob', GetJob)

---@deprecated use the GetGangs function instead
---@param name string
---@return Gang?
function GetGang(name)
Expand Down
41 changes: 35 additions & 6 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ QBX.PlayerData = {}
QBX.Shared = require 'shared.main'
QBX.IsLoggedIn = false

---@param name string?
---@return table?
function GetVehicles(name)
if not name then return QBX.Shared.Vehicles end

if type(name) ~= 'string' then return end

name = name:lower()

return QBX.Shared.Vehicles[name]
end

exports('GetVehicles', GetVehicles)

---@deprecated use the GetVehicles function instead
---@return table<string, Vehicle>
function GetVehiclesByName()
return QBX.Shared.Vehicles
Expand All @@ -24,16 +39,30 @@ end

exports('GetVehiclesByCategory', GetVehiclesByCategory)

---@return table<number, Weapon>
function GetWeapons()
return QBX.Shared.Weapons
---@param name string?
---@return table?
function GetWeapons(name)
if not name then return QBX.Shared.Weapons end

if type(name) ~= 'string' then return end

name = name:lower()

return QBX.Shared.Weapons[name]
end

exports('GetWeapons', GetWeapons)

---@return table<string, vector4>
function GetLocations()
return QBX.Shared.Locations
---@param name string?
---@return table?
function GetLocations(name)
if not name then return QBX.Shared.Locations end

if type(name) ~= 'string' then return end

name = name:lower()

return QBX.Shared.Locations[name]
end

exports('GetLocations', GetLocations)
Expand Down
28 changes: 22 additions & 6 deletions server/groups.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,35 @@ end

exports('RemoveGang', RemoveGang)

---@return table<string, Job>
function GetJobs()
return jobs
---@param name string?
---@return table?
function GetJobs(name)
if not name then return jobs end

if type(name) ~= 'string' then return end

name = name:lower()

return jobs[name]
end

exports('GetJobs', GetJobs)

---@return table<string, Gang>
function GetGangs()
return gangs
---@param name string?
---@return table?
function GetGangs(name)
if not name then return gangs end

if type(name) ~= 'string' then return end

name = name:lower()

return gangs[name]
end

exports('GetGangs', GetGangs)

---@deprecated use the GetJobs function instead
---@param name string
---@return Job?
function GetJob(name)
Expand All @@ -125,6 +140,7 @@ end

exports('GetJob', GetJob)

---@deprecated use the GetGangs function instead
---@param name string
---@return Gang?
function GetGang(name)
Expand Down
41 changes: 35 additions & 6 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ QBX.Player_Buckets = {}
QBX.Entity_Buckets = {}
QBX.UsableItems = {}

---@param name string?
---@return table?
function GetVehicles(name)
if not name then return QBX.Shared.Vehicles end

if type(name) ~= 'string' then return end

name = name:lower()

return QBX.Shared.Vehicles[name]
end

exports('GetVehicles', GetVehicles)

---@deprecated use the GetVehicles function instead
---@return table<string, Vehicle>
function GetVehiclesByName()
return QBX.Shared.Vehicles
Expand All @@ -39,16 +54,30 @@ end

exports('GetVehiclesByCategory', GetVehiclesByCategory)

---@return table<number, Weapon>
function GetWeapons()
return QBX.Shared.Weapons
---@param name string?
---@return table?
function GetWeapons(name)
if not name then return QBX.Shared.Weapons end

if type(name) ~= 'string' then return end

name = name:lower()

return QBX.Shared.Weapons[name]
end

exports('GetWeapons', GetWeapons)

---@return table<string, vector4>
function GetLocations()
return QBX.Shared.Locations
---@param name string?
---@return table?
function GetLocations(name)
if not name then return QBX.Shared.Locations end

if type(name) ~= 'string' then return end

name = name:lower()

return QBX.Shared.Locations[name]
end

exports('GetLocations', GetLocations)

0 comments on commit 1b1ff6e

Please sign in to comment.