diff --git a/package.json b/package.json index 81abcb81..de47cbbe 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "private": true, "dependencies": { "@pixi/canvas-renderer": "^6.1.0", + "@pixi/extract": "^6.1.0", "@pixi/filter-adjustment": "^4.1.3", "events": "^3.3.0", "pako": "^2.0.4", diff --git a/src/nitro/Nitro.ts b/src/nitro/Nitro.ts index 250a8dae..7ad626be 100644 --- a/src/nitro/Nitro.ts +++ b/src/nitro/Nitro.ts @@ -25,6 +25,7 @@ import { GameMessageHandler } from './game/GameMessageHandler'; import { INitro } from './INitro'; import { INitroLocalizationManager } from './localization/INitroLocalizationManager'; import { NitroLocalizationManager } from './localization/NitroLocalizationManager'; +import './Plugins'; import { RoomEngineEvent } from './room/events/RoomEngineEvent'; import { IRoomEngine } from './room/IRoomEngine'; import { RoomEngine } from './room/RoomEngine'; @@ -45,7 +46,7 @@ export class Nitro extends Application implements INitro public static WEBGL_CONTEXT_LOST: string = 'NE_WEBGL_CONTEXT_LOST'; public static WEBGL_UNAVAILABLE: string = 'NE_WEBGL_UNAVAILABLE'; public static RELEASE_VERSION: string = 'NITRO-2-0-0'; - public static READY: string = 'NE_READY'; + public static READY: string = 'NE_READY!'; private static INSTANCE: INitro = null; diff --git a/src/nitro/Plugins.ts b/src/nitro/Plugins.ts new file mode 100644 index 00000000..ef2a7efd --- /dev/null +++ b/src/nitro/Plugins.ts @@ -0,0 +1,30 @@ +import { AccessibilityManager } from '@pixi/accessibility'; +import { Application } from '@pixi/app'; +import { CompressedTextureLoader, DDSLoader, KTXLoader } from '@pixi/compressed-textures'; +import { BatchRenderer, Renderer } from '@pixi/core'; +import { Extract } from '@pixi/extract'; +import { InteractionManager } from '@pixi/interaction'; +import { AppLoaderPlugin, Loader } from '@pixi/loaders'; +import { ParticleRenderer } from '@pixi/particle-container'; +import { Prepare } from '@pixi/prepare'; +import { TilingSpriteRenderer } from '@pixi/sprite-tiling'; +import { SpritesheetLoader } from '@pixi/spritesheet'; +import { BitmapFontLoader } from '@pixi/text-bitmap'; +import { TickerPlugin } from '@pixi/ticker'; + +Renderer.registerPlugin('accessibility', AccessibilityManager); +Renderer.registerPlugin('extract', Extract); +Renderer.registerPlugin('interaction', InteractionManager); +Renderer.registerPlugin('particle', ParticleRenderer); +Renderer.registerPlugin('prepare', Prepare); +Renderer.registerPlugin('batch', BatchRenderer); +Renderer.registerPlugin('tilingSprite', TilingSpriteRenderer); + +Loader.registerPlugin(BitmapFontLoader); +Loader.registerPlugin(CompressedTextureLoader); +Loader.registerPlugin(DDSLoader); +Loader.registerPlugin(KTXLoader); +Loader.registerPlugin(SpritesheetLoader); + +Application.registerPlugin(TickerPlugin); +Application.registerPlugin(AppLoaderPlugin); diff --git a/src/room/utils/TextureUtils.ts b/src/room/utils/TextureUtils.ts index 51c37747..e6f4ed2d 100644 --- a/src/room/utils/TextureUtils.ts +++ b/src/room/utils/TextureUtils.ts @@ -1,16 +1,17 @@ +import { SCALE_MODES } from '@pixi/constants'; +import { AbstractRenderer, Renderer, RenderTexture, Resource, Texture } from '@pixi/core'; +import { DisplayObject } from '@pixi/display'; import { Extract } from '@pixi/extract'; -import { AbstractRenderer, DisplayObject, Rectangle, Renderer, RenderTexture, Resource, SCALE_MODES, Texture } from 'pixi.js'; +import { Rectangle } from '@pixi/math'; import { Nitro } from '../../nitro/Nitro'; export class TextureUtils { - private static _renderer: Renderer = null; - public static generateTexture(displayObject: DisplayObject, region: Rectangle = null, scaleMode: number = SCALE_MODES.NEAREST, resolution: number = 1): RenderTexture { if(!displayObject) return null; - return TextureUtils.getRenderer().generateTexture(displayObject, { + return this.getRenderer().generateTexture(displayObject, { scaleMode, resolution, region @@ -28,38 +29,30 @@ export class TextureUtils { if(!target) return null; - const extract = (TextureUtils.getRenderer().plugins.extract as Extract); - - return extract.image(target); + return this.getExtractor().image(target); } public static generateImageUrl(target: DisplayObject | RenderTexture): string { if(!target) return null; - const extract = (TextureUtils.getRenderer().plugins.extract as Extract); - - return extract.base64(target); + return this.getExtractor().base64(target); } public static generateCanvas(target: DisplayObject | RenderTexture): HTMLCanvasElement { if(!target) return null; - const extract = (TextureUtils.getRenderer().plugins.extract as Extract); - - return extract.canvas(target); + return this.getExtractor().canvas(target); } public static getRenderer(): Renderer | AbstractRenderer { - if(!TextureUtils._renderer) return Nitro.instance.renderer; - - return TextureUtils._renderer; + return Nitro.instance.renderer; } - public static setRenderer(renderer: Renderer): void + public static getExtractor(): Extract { - TextureUtils._renderer = renderer; + return (this.getRenderer().plugins.extract as Extract); } }