diginext-pixi
Version:
README.md
1 lines • 2.14 kB
JavaScript
;var __awaiter=this&&this.__awaiter||function(o,t,e,n){return new(e||(e=Promise))((function(i,r){function u(o){try{d(n.next(o))}catch(o){r(o)}}function a(o){try{d(n.throw(o))}catch(o){r(o)}}function d(o){var t;o.done?i(o.value):(t=o.value,t instanceof e?t:new e((function(o){o(t)}))).then(u,a)}d((n=n.apply(o,t||[])).next())}))},__importDefault=this&&this.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(exports,"__esModule",{value:!0});const Timer_1=__importDefault(require("diginext-utils/dist/Timer")),howler_1=require("howler");class SoundController{static load(o){return __awaiter(this,void 0,void 0,(function*(){"undefined"!=typeof window&&(yield Promise.all(o.map((o=>new Promise(((t,e)=>{var n=new howler_1.Howl({src:[o]});n.once("load",(function(){n.stop(),t(!0)}))}))))))}))}static play(o,t){if("undefined"!=typeof window)return new Promise(((e,n)=>{t=Object.assign({autoplay:!1,loop:!1,volume:.5},t);const i=new howler_1.Howl(Object.assign({src:[o]},t));i.play(),i.on("end",(function(){e(!0)}))}))}static playBackground(o,t){return __awaiter(this,void 0,void 0,(function*(){if("undefined"==typeof window)return;if(this.__background==o)return;this.__background=o;const e=(t=t||{}).hasOwnProperty("volume")?t.volume:.3,n=t.hasOwnProperty("timeFade")?t.timeFade:500;return this.backgroundSound&&(this.backgroundSound.fade(this.backgroundSound.volume(),0,n),yield Timer_1.default.wait(n),this.backgroundSound.stop()),this.backgroundSound=new howler_1.Howl(Object.assign({src:[o],loop:!0,volume:0},t)),this.backgroundSound.play(),this.backgroundSound.fade(0,e,n),this.backgroundSound}))}static fadeOutBackground(){var o;return __awaiter(this,void 0,void 0,(function*(){if("undefined"==typeof window)return;if(!this.backgroundSound)return;const t=null===(o=this.backgroundSound)||void 0===o?void 0:o.volume();t&&this.backgroundSound.fade(t,0,500),yield Timer_1.default.wait(500),this.__background=""}))}static off(){howler_1.Howler.volume(0)}static on(){howler_1.Howler.volume(1)}static stop(){howler_1.Howler.stop()}}exports.default=SoundController,SoundController.__background="";