Deferring the holoplay import until it's determined that it's needed. Changing the holoplay effect version a little.

This commit is contained in:
Rezmason
2022-09-18 22:30:10 -07:00
parent b0406978d7
commit 5f544091a9
2 changed files with 28 additions and 22 deletions

View File

@@ -1,5 +1,3 @@
import * as HoloPlayCore from "../../lib/holoplaycore.module.js";
const recordedDevice = {
buttons: [0, 0, 0, 0],
calibration: {
@@ -34,14 +32,6 @@ const recordedDevice = {
windowCoords: [1440, 900],
};
const getDetectedDevice = new Promise(
(resolve, reject) =>
new HoloPlayCore.Client(
(data) => resolve(data.devices?.[0]),
(error) => resolve(null)
)
);
const interpretDevice = (device) => {
if (device == null) {
return { enabled: false, tileX: 1, tileY: 1 };
@@ -84,9 +74,16 @@ export default async (useHoloplay = false, useRecordedDevice = false) => {
if (!useHoloplay) {
return interpretDevice(null);
}
const detectedDevice = await getDetectedDevice;
if (detectedDevice == null && useRecordedDevice) {
const HoloPlayCore = await import("../../lib/holoplaycore.module.js");
const device = await new Promise(
(resolve, reject) =>
new HoloPlayCore.Client(
(data) => resolve(data.devices?.[0]),
(error) => resolve(null)
)
);
if (device == null && useRecordedDevice) {
return interpretDevice(recordedDevice);
}
return interpretDevice(detectedDevice);
return interpretDevice(device);
};