From 8909315e2103fe2a48d41985fffaa8c936612b8b Mon Sep 17 00:00:00 2001 From: Sergio <89666307+feelfreetofee@users.noreply.github.com> Date: Mon, 29 Jan 2024 23:37:20 +0100 Subject: [PATCH] refactor(es_extended/client/modules/streaming.lua) If no callback provided, functions will return the first argument synchronously. if not, first argument will be passed to the callback. --- .../es_extended/client/modules/streaming.lua | 88 +++++-------------- 1 file changed, 20 insertions(+), 68 deletions(-) diff --git a/[core]/es_extended/client/modules/streaming.lua b/[core]/es_extended/client/modules/streaming.lua index 958509783..46cf16bd9 100644 --- a/[core]/es_extended/client/modules/streaming.lua +++ b/[core]/es_extended/client/modules/streaming.lua @@ -1,85 +1,37 @@ function ESX.Streaming.RequestModel(modelHash, cb) - modelHash = (type(modelHash) == "number" and modelHash or joaat(modelHash)) - - if not HasModelLoaded(modelHash) and IsModelInCdimage(modelHash) then - RequestModel(modelHash) - - while not HasModelLoaded(modelHash) do - Wait(0) - end - end - - if cb ~= nil then - cb() - end + modelHash = type(modelHash) == "number" and modelHash or joaat(modelHash) + if not IsModelInCdimage(modelHash) then return end + RequestModel(modelHash) + while not HasModelLoaded(modelHash) do Wait() end + return cb and cb(modelHash) or modelHash end function ESX.Streaming.RequestStreamedTextureDict(textureDict, cb) - if not HasStreamedTextureDictLoaded(textureDict) then - RequestStreamedTextureDict(textureDict) - - while not HasStreamedTextureDictLoaded(textureDict) do - Wait(0) - end - end - - if cb ~= nil then - cb() - end + RequestStreamedTextureDict(textureDict) + while not HasStreamedTextureDictLoaded(textureDict) do Wait() end + return cb and cb(textureDict) or textureDict end function ESX.Streaming.RequestNamedPtfxAsset(assetName, cb) - if not HasNamedPtfxAssetLoaded(assetName) then - RequestNamedPtfxAsset(assetName) - - while not HasNamedPtfxAssetLoaded(assetName) do - Wait(0) - end - end - - if cb ~= nil then - cb() - end + RequestNamedPtfxAsset(assetName) + while not HasNamedPtfxAssetLoaded(assetName) do Wait() end + return cb and cb(assetName) or assetName end function ESX.Streaming.RequestAnimSet(animSet, cb) - if not HasAnimSetLoaded(animSet) then - RequestAnimSet(animSet) - - while not HasAnimSetLoaded(animSet) do - Wait(0) - end - end - - if cb ~= nil then - cb() - end + RequestAnimSet(animSet) + while not HasAnimSetLoaded(animSet) do Wait() end + return cb and cb(animSet) or animSet end function ESX.Streaming.RequestAnimDict(animDict, cb) - if not HasAnimDictLoaded(animDict) then - RequestAnimDict(animDict) - - while not HasAnimDictLoaded(animDict) do - Wait(0) - end - end - - if cb ~= nil then - cb() - end + RequestAnimDict(animDict) + while not HasAnimDictLoaded(animDict) do Wait() end + return cb and cb(animDict) or animDict end function ESX.Streaming.RequestWeaponAsset(weaponHash, cb) - if not HasWeaponAssetLoaded(weaponHash) then - RequestWeaponAsset(weaponHash) - - while not HasWeaponAssetLoaded(weaponHash) do - Wait(0) - end - end - - if cb ~= nil then - cb() - end + RequestWeaponAsset(weaponHash) + while not HasWeaponAssetLoaded(weaponHash) do Wait() end + return cb and cb(weaponHash) or weaponHash end