import { debugContainer } from "./containers" ; import { Scene } from "./scene" ; import { settings } from "./settings" ; /**
 * Represents a utility module to view debug information inside the DOM.
 * This is disabled by default and needs to manually be enabled by setting
 * the '.enabled' field to true.
 *
 * While disabled, the utility will not fetch stats and update itself.
 */ export class Debug { /**
     * The rate at which the debug interface should refresh itself (per second).
     */ private readonly refreshRate = 8 ; /**
     * The timer counting down to refreshes.
     */ private refreshTimer = 1 / this . refreshRate ; param scene constructor ( private scene ) { } param delta public tick ( delta ) { const container = debugContainer . current ; const displayStyle = settings . debug ? "block" : "none" ; if ( container . style . display !== displayStyle ) { container . style . display = displayStyle ; } if ( ! settings . debug ) { return ; } this . refreshTimer += delta ; if ( this . refreshTimer > 1 / this . refreshRate ) { this . refreshTimer = 0 ; container . innerHTML = this . getDebugInformation ( delta ) . join ( "<br>" ) ; } } returns private getDebugInformation ( delta ) { const emitters = this . scene . emitters . length ; const particles = this . scene . emitters . reduce ( ( acc , cur ) => acc + cur . particles . length , 0 ) ; const infos = [ `<b>party.js Debug</b>` , `--------------` , `FPS: ${ Math . round ( 1 / delta ) }` , `Emitters: ${ emitters }` , `Particles: ${ particles }` , ] ; const emitterInfos = this . scene . emitters . map ( function ( emitter ) { return [ `⭯: ${ emitter [ "currentLoop" ] + 1 }/${ emitter . options . loops >= 0 ? emitter . options . loops : "∞" }` , `Σp: ${ emitter . particles . length }` , ! emitter . isExpired ? `Σt: ${ emitter [ "durationTimer" ] . toFixed ( 3 ) }s` : "<i>expired</i>" , ] . join ( ", " ) ; } ) ; infos . push ( "--------------" , ... emitterInfos ) ; return infos ; } }