Skip to content

Commit

Permalink
refactor: deprecate data function for lib.load
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Dec 10, 2023
1 parent 1453ad8 commit 52e90d3
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ local function closeTrunk()
end

local CraftingBenches = require 'modules.crafting.client'
local Vehicles = data 'vehicles'
local Vehicles = lib.load('data.vehicles')
local Inventory = require 'modules.inventory.client'

---@param inv string?
Expand Down Expand Up @@ -331,7 +331,7 @@ RegisterNetEvent('ox_inventory:forceOpenInventory', function(left, right)
})
end)

local Animations = data 'animations'
local Animations = lib.load('data.animations')
local Items = require 'modules.items.client'
local usingItem = false

Expand Down Expand Up @@ -1236,7 +1236,7 @@ RegisterNetEvent('ox_inventory:setPlayerInventory', function(currentDrops, inven
end
end

for id, data in pairs(data('licenses')) do
for id, data in pairs(lib.load('data.licenses')) do
lib.points.new({
coords = data.coords,
distance = 16,
Expand Down
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ end)

---@param name string
---@return table
---@deprecated
function data(name)
if shared.server and shared.ready == nil then return {} end
local file = ('data/%s.lua'):format(name)
Expand Down
2 changes: 1 addition & 1 deletion modules/crafting/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ local function createCraftingBench(id, data)
end
end

for id, data in pairs(data('crafting')) do createCraftingBench(id, data) end
for id, data in pairs(lib.load('data.crafting')) do createCraftingBench(id, data) end

return CraftingBenches
2 changes: 1 addition & 1 deletion modules/crafting/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ local function createCraftingBench(id, data)
end
end

for id, data in pairs(data('crafting')) do createCraftingBench(id, data) end
for id, data in pairs(lib.load('data.crafting')) do createCraftingBench(id, data) end

---falls back to player coords if zones and points are both nil
---@param source number
Expand Down
6 changes: 3 additions & 3 deletions modules/inventory/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Inventory.OpenDumpster(entity)
end

local Utils = require 'modules.utils.client'
local Vehicles = data 'vehicles'
local Vehicles = lib.load('data.vehicles')
local backDoorIds = { 2, 3 }

function Inventory.CanAccessTrunk(entity)
Expand Down Expand Up @@ -297,7 +297,7 @@ local function nearbyEvidence(point)
end
end

Inventory.Evidence = setmetatable(data('evidence'), {
Inventory.Evidence = setmetatable(lib.load('data.evidence'), {
__call = function(self)
for _, evidence in pairs(self) do
if evidence.point then
Expand Down Expand Up @@ -339,7 +339,7 @@ local function nearbyStash(self)
DrawMarker(2, self.coords.x, self.coords.y, self.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.15, 30, 30, 150, 222, false, false, 0, true, false, false, false)
end

Inventory.Stashes = setmetatable(data('stashes'), {
Inventory.Stashes = setmetatable(lib.load('data.stashes'), {
__call = function(self)
for id, stash in pairs(self) do
if stash.jobs then stash.groups = stash.jobs end
Expand Down
4 changes: 2 additions & 2 deletions modules/inventory/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ function OxInventory:syncSlotsWithClients(slots, syncOwner)
end
end

local Vehicles = data 'vehicles'
local Vehicles = lib.load('data.vehicles')
local RegisteredStashes = {}

for _, stash in pairs(data 'stashes') do
for _, stash in pairs(lib.load('data.stashes')) do
RegisteredStashes[stash.name] = {
name = stash.name,
label = stash.label,
Expand Down
4 changes: 2 additions & 2 deletions modules/items/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ local function newItem(data)
ItemList[data.name] = data
end

for type, data in pairs(data('weapons')) do
for type, data in pairs(lib.load('data.weapons')) do
for k, v in pairs(data) do
v.name = k
v.close = type == 'Ammo' and true or false
Expand Down Expand Up @@ -88,7 +88,7 @@ for type, data in pairs(data('weapons')) do
end
end

for k, v in pairs(data 'items') do
for k, v in pairs(lib.load('data.items')) do
v.name = k
local success, response = pcall(newItem, v)

Expand Down
2 changes: 1 addition & 1 deletion modules/shops/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local shopTypes = {}
local shops = {}
local createBlip = require 'modules.utils.client'.CreateBlip

for shopType, shopData in pairs(data('shops') --[[@as table<string, OxShop>]]) do
for shopType, shopData in pairs(lib.load('data.shops') --[[@as table<string, OxShop>]]) do
local shop = {
name = shopData.name,
groups = shopData.groups or shopData.jobs,
Expand Down
2 changes: 1 addition & 1 deletion modules/shops/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ local function createShop(shopType, id)
return shop[id]
end

for shopType, shopDetails in pairs(data('shops')) do
for shopType, shopDetails in pairs(lib.load('data.shops')) do
registerShopType(shopType, shopDetails)
end

Expand Down
2 changes: 1 addition & 1 deletion server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ exports('forceOpenInventory', function(playerId, invType, data)
end
end)

local Licenses = data 'licenses'
local Licenses = lib.load('data.licenses')

lib.callback.register('ox_inventory:buyLicense', function(source, id)
local license = Licenses[id]
Expand Down

0 comments on commit 52e90d3

Please sign in to comment.