2021-07-29 20:47:30 +00:00
|
|
|
export let last_update = Date.now();
|
|
|
|
|
2022-01-15 02:18:00 +00:00
|
|
|
export function calc_delta_time() {
|
2021-07-29 20:47:30 +00:00
|
|
|
let now = Date.now();
|
|
|
|
let dt = (now - last_update) / 1e3;
|
|
|
|
dt = Math.min(dt, 0.016);
|
|
|
|
last_update = now;
|
|
|
|
return dt;
|
|
|
|
}
|
|
|
|
|
2022-01-15 02:18:00 +00:00
|
|
|
export function event_listener_array(whos, event_names, callback, options = null) {
|
|
|
|
if (!Array.isArray(whos)) {
|
2021-07-29 20:47:30 +00:00
|
|
|
whos = [whos];
|
|
|
|
}
|
2022-01-15 02:18:00 +00:00
|
|
|
for (const name of event_names) {
|
|
|
|
for (const who of whos) {
|
2021-07-29 20:47:30 +00:00
|
|
|
who.addEventListener(name, callback, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-15 02:18:00 +00:00
|
|
|
export async function import_js_as_module(url) {
|
|
|
|
return new Promise((resole, reject) => {
|
2021-07-29 20:47:30 +00:00
|
|
|
const body = document.getElementsByTagName('body')[0];
|
|
|
|
const script = document.createElement('script');
|
|
|
|
script.type = 'module';
|
|
|
|
script.src = url;
|
|
|
|
script.onload = resole;
|
|
|
|
body.appendChild(script);
|
|
|
|
});
|
|
|
|
}
|