2024-01-17 19:55:35 +11:00
|
|
|
import { waitFor } from '../../';
|
2024-01-17 17:39:16 +11:00
|
|
|
|
2024-03-31 16:15:44 +11:00
|
|
|
function streamingRequest<T extends string | number>(
|
2022-11-21 21:39:01 +11:00
|
|
|
request: Function,
|
|
|
|
|
hasLoaded: Function,
|
|
|
|
|
assetType: string,
|
2024-03-31 16:15:44 +11:00
|
|
|
asset: T,
|
2024-10-06 03:25:17 +11:00
|
|
|
timeout: number = 30000,
|
2023-04-17 05:21:40 +01:00
|
|
|
...args: any
|
2024-03-31 16:15:44 +11:00
|
|
|
) {
|
2024-01-17 17:39:16 +11:00
|
|
|
if (hasLoaded(asset)) return asset;
|
2022-09-15 00:22:25 +02:00
|
|
|
|
2024-01-17 17:39:16 +11:00
|
|
|
request(asset, ...args);
|
2022-09-15 00:22:25 +02:00
|
|
|
|
2024-03-27 14:27:33 +11:00
|
|
|
return waitFor(
|
2024-01-17 17:39:16 +11:00
|
|
|
() => {
|
|
|
|
|
if (hasLoaded(asset)) return asset;
|
|
|
|
|
},
|
2024-10-06 03:25:17 +11:00
|
|
|
`failed to load ${assetType} '${asset}' - this may be caused by\n- too many loaded assets\n- oversized, invalid, or corrupted assets`,
|
2024-03-31 16:15:44 +11:00
|
|
|
timeout
|
2024-01-17 17:39:16 +11:00
|
|
|
);
|
2022-11-21 21:39:01 +11:00
|
|
|
}
|
|
|
|
|
|
2024-03-31 16:15:44 +11:00
|
|
|
export const requestAnimDict = (animDict: string, timeout?: number) => {
|
2022-11-21 21:39:01 +11:00
|
|
|
if (!DoesAnimDictExist(animDict)) throw new Error(`attempted to load invalid animDict '${animDict}'`);
|
|
|
|
|
|
|
|
|
|
return streamingRequest(RequestAnimDict, HasAnimDictLoaded, 'animDict', animDict, timeout);
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-31 16:15:44 +11:00
|
|
|
export const requestAnimSet = (animSet: string, timeout?: number) =>
|
2022-11-21 21:39:01 +11:00
|
|
|
streamingRequest(RequestAnimSet, HasAnimSetLoaded, 'animSet', animSet, timeout);
|
|
|
|
|
|
2024-03-31 16:15:44 +11:00
|
|
|
export const requestModel = (model: string | number, timeout?: number) => {
|
2022-11-21 21:39:01 +11:00
|
|
|
if (typeof model !== 'number') model = GetHashKey(model);
|
|
|
|
|
if (!IsModelValid(model)) throw new Error(`attempted to load invalid model '${model}'`);
|
|
|
|
|
|
|
|
|
|
return streamingRequest(RequestModel, HasModelLoaded, 'model', model, timeout);
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-31 16:15:44 +11:00
|
|
|
export const requestNamedPtfxAsset = (ptFxName: string, timeout?: number) =>
|
2022-11-21 21:39:01 +11:00
|
|
|
streamingRequest(RequestNamedPtfxAsset, HasNamedPtfxAssetLoaded, 'ptFxName', ptFxName, timeout);
|
2023-04-17 05:21:40 +01:00
|
|
|
|
2024-03-31 16:15:44 +11:00
|
|
|
export const requestScaleformMovie = (scaleformName: string, timeout?: number) =>
|
2023-07-21 04:54:29 -07:00
|
|
|
streamingRequest(RequestScaleformMovie, HasScaleformMovieLoaded, 'scaleformMovie', scaleformName, timeout);
|
|
|
|
|
|
2024-03-31 16:15:44 +11:00
|
|
|
export const requestStreamedTextureDict = (textureDict: string, timeout?: number) =>
|
2023-07-21 04:54:29 -07:00
|
|
|
streamingRequest(RequestStreamedTextureDict, HasStreamedTextureDictLoaded, 'textureDict', textureDict, timeout);
|
|
|
|
|
|
2024-01-17 17:39:16 +11:00
|
|
|
export const requestWeaponAsset = (
|
|
|
|
|
weaponHash: string | number,
|
|
|
|
|
timeout?: number,
|
|
|
|
|
weaponResourceFlags: number = 31,
|
|
|
|
|
extraWeaponComponentFlags: number = 0
|
2024-03-31 16:15:44 +11:00
|
|
|
) =>
|
2024-01-17 17:39:16 +11:00
|
|
|
streamingRequest(
|
|
|
|
|
RequestWeaponAsset,
|
|
|
|
|
HasWeaponAssetLoaded,
|
|
|
|
|
'weaponHash',
|
|
|
|
|
weaponHash,
|
|
|
|
|
timeout,
|
|
|
|
|
weaponResourceFlags,
|
|
|
|
|
extraWeaponComponentFlags
|
|
|
|
|
);
|