refactor(streaming): convert to modules

Import methods rather than call via exports.
This commit is contained in:
Linden
2022-11-21 21:39:01 +11:00
parent 6825103dd5
commit 00c2086072
9 changed files with 213 additions and 86 deletions

View File

@@ -0,0 +1,35 @@
---Load an animation dictionary. When called from a thread, it will yield until it has loaded.
---@param animDict string
---@param timeout number? Number of ticks to wait for the dictionary to load. Default is 500.
---@return string? animDict
function lib.requestAnimDict(animDict, timeout)
if HasAnimDictLoaded(animDict) then return animDict end
if type(animDict) ~= 'string' then
error(("expected animDict to have type 'string' (received %s)"):format(type(animDict)))
end
if not DoesAnimDictExist(animDict) then
return error(("attempted to load invalid animDict '%s'"):format(animDict))
end
RequestAnimDict(animDict)
if coroutine.running() then
timeout = tonumber(timeout) or 500
for _ = 1, timeout do
if HasAnimDictLoaded(animDict) then
return animDict
end
Wait(0)
end
print(("failed to load animDict '%s' after %s ticks"):format(animDict, timeout))
end
return animDict
end
return lib.requestAnimDict

View File

@@ -0,0 +1,31 @@
---Load an animation clipset. When called from a thread, it will yield until it has loaded.
---@param animSet string
---@param timeout number? Number of ticks to wait for the clipset to load. Default is 500.
---@return string? animSet
function lib.requestAnimSet(animSet, timeout)
if HasAnimSetLoaded(animSet) then return animSet end
if type(animSet) ~= 'string' then
error(("expected animSet to have type 'string' (received %s)"):format(type(animSet)))
end
RequestAnimSet(animSet)
if coroutine.running() then
timeout = tonumber(timeout) or 500
for _ = 1, timeout do
if HasAnimSetLoaded(animSet) then
return animSet
end
Wait(0)
end
print(("failed to load animSet '%s' after %s ticks"):format(animSet, timeout))
end
return animSet
end
return lib.requestAnimSet

View File

@@ -0,0 +1,33 @@
---Load a model. When called from a thread, it will yield until it has loaded.
---@param model number | string
---@param timeout number? Number of ticks to wait for the model to load. Default is 500.
---@return number? model
function lib.requestModel(model, timeout)
if not tonumber(model) then model = joaat(model) end
---@cast model -string
if HasModelLoaded(model) then return model end
if not IsModelValid(model) then
return error(("attempted to load invalid model '%s'"):format(model))
end
RequestModel(model)
if coroutine.running() then
timeout = tonumber(timeout) or 500
for _ = 1, timeout do
if HasModelLoaded(model) then
return model
end
Wait(0)
end
print(("failed to load model '%s' after %s ticks"):format(model, timeout))
end
return model
end
return lib.requestModel

View File

@@ -0,0 +1,31 @@
---Load a named particle effect. When called from a thread, it will yield until it has loaded.
---@param ptFxName string
---@param timeout number? Number of ticks to wait for the particle effect to load. Default is 500.
---@return string? ptFxName
function lib.requestNamedPtfxAsset(ptFxName, timeout)
if HasNamedPtfxAssetLoaded(ptFxName) then return ptFxName end
if type(ptFxName) ~= 'string' then
error(("expected ptFxName to have type 'string' (received %s)"):format(type(ptFxName)))
end
RequestNamedPtfxAsset(ptFxName)
if coroutine.running() then
timeout = tonumber(timeout) or 500
for _ = 1, timeout do
if HasNamedPtfxAssetLoaded(ptFxName) then
return ptFxName
end
Wait(0)
end
print(("failed to load ptFxName '%s' after %s ticks"):format(ptFxName, timeout))
end
return ptFxName
end
return lib.requestNamedPtfxAsset

View File

@@ -0,0 +1,31 @@
---Load a texture dictionary. When called from a thread, it will yield until it has loaded.
---@param textureDict string
---@param timeout number? Number of ticks to wait for the dictionary to load. Default is 500.
---@return string? textureDict
function lib.requestStreamedTextureDict(textureDict, timeout)
if HasStreamedTextureDictLoaded(textureDict) then return textureDict end
if type(textureDict) ~= 'string' then
error(("expected textureDict to have type 'string' (received %s)"):format(type(textureDict)))
end
RequestStreamedTextureDict(textureDict)
if coroutine.running() then
timeout = tonumber(timeout) or 500
for _ = 1, timeout do
if HasStreamedTextureDictLoaded(textureDict) then
return textureDict
end
Wait(0)
end
print(("failed to load textureDict '%s' after %s ticks"):format(textureDict, timeout))
end
return textureDict
end
return lib.requestStreamedTextureDict