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.
This commit is contained in:
Sergio
2024-01-29 23:37:20 +01:00
committed by GitHub
parent d57780f15c
commit 8909315e21
+20 -68
View File
@@ -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