UNPKG

@tomorrowevening/hermes

Version:

An extendable set of Web Tools controlled via a separate window for non-intereference with content.

2 lines (1 loc) 1.16 kB
"use strict";const s=require("../utils/detectSettings.cjs");class i{assets={audio:new Map,image:new Map,json:new Map,model:new Map,video:new Map};components=new Map;settings={dpr:1,width:0,height:0,mobile:!1,supportOffScreenCanvas:!1,supportWebGPU:!1,quality:"Low",dev:!1,editor:!1};onUpdateCallback;playing=!1;rafID=-1;constructor(t,e=!1){this.settings.dev=t,this.settings.editor=e}dispose(){this.pause(),this.components.forEach(t=>t.dispose()),this.components.clear()}detectSettings(){return new Promise(t=>{s.detectSettings(this.settings.dev,this.settings.editor).then(e=>{this.settings=e,t()})})}update(){}draw(){}play=()=>{this.playing||(this.playing=!0,this.onUpdate())};pause=()=>{this.playing&&(this.playing=!1,cancelAnimationFrame(this.rafID),this.rafID=-1)};onUpdate=()=>{this.update(),this.isApp&&this.draw(),this.onUpdateCallback&&this.onUpdateCallback(),this.rafID=requestAnimationFrame(this.onUpdate)};addComponent(t,e){this.components.set(t,e)}get debugEnabled(){return this.settings.dev}get isApp(){return!this.editor}set isApp(t){this.editor=!t}get editor(){return this.settings.editor}set editor(t){this.settings.editor=t}}module.exports=i;