pinball/assets/_Game/Scripts/Utilities/index.ts

30 lines
642 B
TypeScript
Raw Normal View History

2024-06-09 05:12:08 -07:00
export default class Utils {
2024-03-03 00:23:29 -08:00
/**
*
2024-03-12 01:50:54 -07:00
* @param time (s)
2024-03-03 00:23:29 -08:00
* @returns
*/
2024-02-28 03:25:11 -08:00
public static delay(time: number): Promise<any> {
2024-03-12 01:50:54 -07:00
return new Promise((resolve) => setTimeout(resolve, time * 1000));
2024-02-28 03:25:11 -08:00
}
2024-03-07 09:45:13 -08:00
/**
*@param predicate
2024-03-12 01:50:54 -07:00
* @param time (s)
2024-03-07 09:45:13 -08:00
* @returns
*/
2024-03-12 01:50:54 -07:00
public static async waitUntil(predicate: () => boolean, timeCheck = 0.01) {
2024-03-07 09:45:13 -08:00
while (!predicate()) {
await this.delay(timeCheck);
}
}
2024-02-28 03:25:11 -08:00
public static getJson(json: string): any {
try {
return JSON.parse(json);
} catch (error) {
return false;
}
}
}