UNPKG

@isaac-platform/isaac-integration-sdk

Version:

A Typescript SDK for integrating with ISAAC

96 lines (95 loc) 3.64 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import EventEmitter from "events"; import * as util from "util"; import isaacConnection from "../../controller/isaac.js"; import objectController from "../../objects"; export class IsaacPlayable extends EventEmitter { constructor(definition) { super(); this.duration = 0; this.objects = []; this.objectIdMap = new Map(); this._createdAt = ""; this._updatedAt = ""; this.init = () => __awaiter(this, void 0, void 0, function* () { for (let objId of this.definition.objects) { const realObj = yield objectController.getObjectByIdSafe(objId); this.objectIdMap.set(objId, realObj); } }); this.definition = definition; this.externalRef = this.definition.externalRef; this.subsystemExternalId = this.definition.subsystemExternalId; this.objects = this.definition.objects; // Begin initializing Child Objects this.init(); } get() { // WARN: I know this is probably not best practice. Definitely revise later return this; } // Get/Set - command property get command() { return this.definition.command || "undefined"; } set command(value) { this.definition.command = value; this.update({ command: value }); } // Get/Set - description property get description() { return this.definition.description || "undefined"; } set description(value) { this.definition.description = value; this.update({ description: value }); } // Get/Set - displayName property get displayName() { return this.definition.displayName || "undefined"; } set displayName(value) { this.definition.displayName = value; this.update({ displayName: value }); } // Get/Set - availableInSubsystem property get availableInSubsystem() { return this.definition.availableInSubsystem || false; } set availableInSubsystem(value) { this.definition.availableInSubsystem = value; this.update({ availableInSubsystem: value }); } toggleAvailability() { this.availableInSubsystem = !this.availableInSubsystem; } // Get/Set - metadata property get metadata() { return this.definition.metadata || {}; } set metadata(value) { this.definition.metadata = value; this.update({ metadata: value }); } update(updateParameters) { try { isaacConnection.putRequest(`playables/${this.definition._id}`, updateParameters); } catch (error) { console.error('ISAAC SDK: Error updating playable.', error); throw error; } } // Override inspect behavior for logging. [util.inspect.custom](depth, opts) { return `${this.subsystemExternalId || this.subsystemId} - ${this.displayName || this.externalRef}`; } }