Finish fixing imports

This commit is contained in:
Bill 2021-08-03 11:54:33 -04:00
parent b46fe6fcd6
commit 6f04f28261
4 changed files with 44 additions and 19 deletions

View File

@ -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",

View File

@ -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;

30
src/nitro/Plugins.ts Normal file
View File

@ -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);

View File

@ -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);
}
}