From 49f185c6ec0cece31bcafc3212d3bfe02f2aae2c Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 28 Mar 2017 16:45:28 -0700 Subject: [PATCH] pixi.js: Lint (#15456) --- types/pixi.js/index.d.ts | 782 ++++++++++++--------------------- types/pixi.js/pixi.js-tests.ts | 406 ++++------------- types/pixi.js/tslint.json | 101 +---- 3 files changed, 368 insertions(+), 921 deletions(-) diff --git a/types/pixi.js/index.d.ts b/types/pixi.js/index.d.ts index cccbc1fbd9..d7a71abcef 100644 --- a/types/pixi.js/index.d.ts +++ b/types/pixi.js/index.d.ts @@ -5,39 +5,38 @@ // TypeScript Version: 2.1 declare namespace PIXI { - // from CONST - export const VERSION: typeof CONST.VERSION; - export const PI_2: typeof CONST.PI_2; - export const RAD_TO_DEG: typeof CONST.RAD_TO_DEG; - export const DEG_TO_RAD: typeof CONST.DEG_TO_RAD; - export const RENDERER_TYPE: typeof CONST.RENDERER_TYPE; - export const BLEND_MODES: typeof CONST.BLEND_MODES; - export const DRAW_MODES: typeof CONST.DRAW_MODES; - export const SCALE_MODES: typeof CONST.SCALE_MODES; - export const WRAP_MODES: typeof CONST.WRAP_MODES; - export const TRANSFORM_MODE: typeof CONST.TRANSFORM_MODE; - export const PRECISION: typeof CONST.PRECISION; - export const GC_MODES: typeof CONST.GC_MODES; - export const SHAPES: typeof CONST.SHAPES; - export const TEXT_GRADIENT: typeof CONST.TEXT_GRADIENT; + const VERSION: typeof CONST.VERSION; + const PI_2: typeof CONST.PI_2; + const RAD_TO_DEG: typeof CONST.RAD_TO_DEG; + const DEG_TO_RAD: typeof CONST.DEG_TO_RAD; + const RENDERER_TYPE: typeof CONST.RENDERER_TYPE; + const BLEND_MODES: typeof CONST.BLEND_MODES; + const DRAW_MODES: typeof CONST.DRAW_MODES; + const SCALE_MODES: typeof CONST.SCALE_MODES; + const WRAP_MODES: typeof CONST.WRAP_MODES; + const TRANSFORM_MODE: typeof CONST.TRANSFORM_MODE; + const PRECISION: typeof CONST.PRECISION; + const GC_MODES: typeof CONST.GC_MODES; + const SHAPES: typeof CONST.SHAPES; + const TEXT_GRADIENT: typeof CONST.TEXT_GRADIENT; - export function autoDetectRenderer(width: number, height: number, options?: PIXI.IRendererOptions, noWebGL?: boolean): PIXI.WebGLRenderer | PIXI.CanvasRenderer; - export const loader: PIXI.loaders.Loader; + function autoDetectRenderer(width: number, height: number, options?: PIXI.IRendererOptions, noWebGL?: boolean): PIXI.WebGLRenderer | PIXI.CanvasRenderer; + const loader: PIXI.loaders.Loader; ////////////////////////////////////////////////////////////////////////////// ///////////////////////////////SETTINGS/////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - export namespace settings { - export let TARGET_FPMS: number; - export let MIPMAP_TEXTURES: boolean; - export let RESOLUTION: number; - export let FILTER_RESOLUTION: number; - export let SPRITE_MAX_TEXTURES: number; - export let SPRITE_BATCH_SIZE: number; - export let RETINA_PREFIX: RegExp; - export const RENDER_OPTIONS: { + namespace settings { + let TARGET_FPMS: number; + let MIPMAP_TEXTURES: boolean; + let RESOLUTION: number; + let FILTER_RESOLUTION: number; + let SPRITE_MAX_TEXTURES: number; + let SPRITE_BATCH_SIZE: number; + let RETINA_PREFIX: RegExp; + const RENDER_OPTIONS: { view: HTMLCanvasElement | null, antialias: boolean, forceFXAA: boolean, @@ -48,26 +47,24 @@ declare namespace PIXI { preserveDrawingBuffer: boolean, roundPixels: boolean }; - export let TRANSFORM_MODE: number; - export let GC_MODE: number; - export let GC_MAX_IDLE: number; - export let GC_MAX_CHECK_COUNT: number; - export let WRAP_MODE: number; - export let SCALE_MODE: number; - export let PRECISION: string; - export let UPLOADS_PER_FRAME: number; - export let CAN_UPLOAD_SAME_BUFFER: boolean; + let TRANSFORM_MODE: number; + let GC_MODE: number; + let GC_MAX_IDLE: number; + let GC_MAX_CHECK_COUNT: number; + let WRAP_MODE: number; + let SCALE_MODE: number; + let PRECISION: string; + let UPLOADS_PER_FRAME: number; + let CAN_UPLOAD_SAME_BUFFER: boolean; } ////////////////////////////////////////////////////////////////////////////// /////////////////////////////ACCESSIBILITY//////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - export namespace accessibility { - + namespace accessibility { // accessibility - export class AccessibilityManager { - + class AccessibilityManager { constructor(renderer: CanvasRenderer | WebGLRenderer); protected div: HTMLElement; @@ -91,17 +88,13 @@ declare namespace PIXI { protected _onMouseMove(): void; destroy(): void; - } - export interface IAccessibleTarget { - + interface IAccessibleTarget { accessible: boolean; accessibleTitle: string | null; accessibleHint: string | null; tabIndex: number; - } - } ////////////////////////////////////////////////////////////////////////////// @@ -110,18 +103,18 @@ declare namespace PIXI { // const - export namespace CONST { - export const VERSION: string; - export const PI_2: number; - export const RAD_TO_DEG: number; - export const DEG_TO_RAD: number; - export const TARGET_FPMS: number; - export const RENDERER_TYPE: { + namespace CONST { + const VERSION: string; + const PI_2: number; + const RAD_TO_DEG: number; + const DEG_TO_RAD: number; + const TARGET_FPMS: number; + const RENDERER_TYPE: { UNKNOWN: number; WEBGL: number; CANVAS: number; }; - export const BLEND_MODES: { + const BLEND_MODES: { NORMAL: number; ADD: number; MULTIPLY: number; @@ -140,7 +133,7 @@ declare namespace PIXI { COLOR: number; LUMINOSITY: number; }; - export const DRAW_MODES: { + const DRAW_MODES: { POINTS: number; LINES: number; LINE_LOOP: number; @@ -149,40 +142,40 @@ declare namespace PIXI { TRIANGLE_STRIP: number; TRIANGLE_FAN: number; }; - export const SCALE_MODES: { + const SCALE_MODES: { LINEAR: number, NEAREST: number }; - export const GC_MODES: { + const GC_MODES: { AUTO: number; MANUAL: number; }; - export const WRAP_MODES: { + const WRAP_MODES: { CLAMP: number; MIRRORED_REPEAT: number; REPEAT: number; }; - export const TRANSFORM_MODE: { + const TRANSFORM_MODE: { DEFAULT: number; DYNAMIC: number; STATIC: number; }; - export const URL_FILE_EXTENSION: RegExp | string; - export const DATA_URI: RegExp | string; - export const SVG_SIZE: RegExp | string; - export const SHAPES: { + const URL_FILE_EXTENSION: RegExp | string; + const DATA_URI: RegExp | string; + const SVG_SIZE: RegExp | string; + const SHAPES: { POLY: number; RECT: number; CIRC: number; ELIP: number; RREC: number; }; - export const PRECISION: { + const PRECISION: { LOW: string; MEDIUM: string; HIGH: string; }; - export const TEXT_GRADIENT: { + const TEXT_GRADIENT: { LINEAR_VERTICAL: number; LINEAR_HORIZONTAL: number; }; @@ -190,8 +183,7 @@ declare namespace PIXI { // display - export interface IApplicationOptions extends IRendererOptions { - + interface IApplicationOptions extends IRendererOptions { view?: HTMLCanvasElement; transparent?: boolean; autoResize?: boolean; @@ -203,11 +195,9 @@ declare namespace PIXI { context?: WebGLRenderingContext; preserveDrawingBuffer?: boolean; legacy?: boolean; - } - export class Application { - + class Application { constructor(width?: number, height?: number, options?: IApplicationOptions, noWebGL?: boolean, useSharedTicker?: boolean); private _ticker: ticker.Ticker; @@ -222,16 +212,14 @@ declare namespace PIXI { render(): void; destroy(removeView?: boolean): void; readonly view: HTMLCanvasElement; - } - export interface IDestroyOptions { + interface IDestroyOptions { children?: boolean; texture?: boolean; baseTexture?: boolean; } - export class Bounds { - + class Bounds { minX: number; minY: number; maxX: number; @@ -249,10 +237,8 @@ declare namespace PIXI { addBounds(bounds: Bounds): void; addBoundsMask(bounds: Bounds, mask: Bounds): void; addBoundsArea(bounds: Bounds, area: Rectangle): void; - } - export class Container extends DisplayObject { - + class Container extends DisplayObject { // begin extras.getChildByName getChildByName(name: string): DisplayObject; // end extras.getChildByName @@ -289,10 +275,8 @@ declare namespace PIXI { on(event: "removed", fn: (DisplayObject: DisplayObject) => void, context?: any): this; on(event: string, fn: Function, context?: any): this; off(event: string, fn: Function, context?: any): this; - } - export class DisplayObject extends utils.EventEmitter implements interaction.InteractiveTarget, accessibility.IAccessibleTarget { - + class DisplayObject extends utils.EventEmitter implements interaction.InteractiveTarget, accessibility.IAccessibleTarget { // begin extras.cacheAsBitmap protected _cacheAsBitmap: boolean; protected _cacheData: boolean; @@ -413,11 +397,9 @@ declare namespace PIXI { once(event: 'touchmove', fn: (event: interaction.InteractionEvent) => void, context?: any): this; once(event: 'touchstart', fn: (event: interaction.InteractionEvent) => void, context?: any): this; */ - } - export class TransformBase { - + class TransformBase { static IDENTITY: TransformBase; worldTransform: Matrix; @@ -426,10 +408,8 @@ declare namespace PIXI { updateLocalTransform(): void; updateTransform(parentTransform: TransformBase): void; updateWorldTransform(parentTransform: TransformBase): void; - } - export class TransformStatic extends TransformBase { - + class TransformStatic extends TransformBase { position: ObservablePoint; scale: ObservablePoint; pivot: ObservablePoint; @@ -451,10 +431,8 @@ declare namespace PIXI { setFromMatrix(matrix: Matrix): void; rotation: number; - } - export class Transform extends TransformBase { - + class Transform extends TransformBase { constructor(); position: Point; @@ -474,14 +452,20 @@ declare namespace PIXI { setFromMatrix(matrix: Matrix): void; rotation: number; - } // graphics - export class GraphicsData { - - constructor(lineWidth: number, lineColor: number, lineAlpha: number, fillColor: number, fillAlpha: number, fill: boolean, nativeLines: boolean, shape: IShape | Circle | Rectangle | RoundedRectangle | Ellipse | Polygon); + class GraphicsData { + constructor( + lineWidth: number, + lineColor: number, + lineAlpha: number, + fillColor: number, + fillAlpha: number, + fill: boolean, + nativeLines: boolean, + shape: IShape | Circle | Rectangle | RoundedRectangle | Ellipse | Polygon); lineWidth: number; nativeLines: boolean; @@ -498,10 +482,8 @@ declare namespace PIXI { clone(): GraphicsData; addHole(shape: IShape | Circle | Rectangle | RoundedRectangle | Ellipse | Polygon): void; destroy(options?: IDestroyOptions | boolean): void; - } - export class Graphics extends Container { - + class Graphics extends Container { constructor(nativeLines?: boolean); fillAlpha: number; @@ -554,19 +536,15 @@ declare namespace PIXI { protected closePath(): Graphics; protected addHole(): Graphics; destroy(options?: IDestroyOptions | boolean): void; - } - export class CanvasGraphicsRenderer { - + class CanvasGraphicsRenderer { constructor(renderer: SystemRenderer); render(graphics: Graphics): void; protected updateGraphicsTint(graphics: Graphics): void; protected renderPolygon(points: Point[], close: boolean, context: CanvasRenderingContext2D): void; destroy(): void; - } - export class GraphicsRenderer extends ObjectRenderer { - + class GraphicsRenderer extends ObjectRenderer { constructor(renderer: PIXI.CanvasRenderer); protected graphicsDataPool: GraphicsData[]; @@ -579,10 +557,8 @@ declare namespace PIXI { render(graphics: Graphics): void; protected updateGraphics(graphics: PIXI.Graphics): void; getWebGLData(webGL: WebGLRenderingContext, type: number): WebGLGraphicsData; - } - export class WebGLGraphicsData { - + class WebGLGraphicsData { constructor(gl: WebGLRenderingContext, shader: glCore.GLShader, attribsState: glCore.IAttribState); gl: WebGLRenderingContext; @@ -600,40 +576,36 @@ declare namespace PIXI { reset(): void; upload(): void; destroy(): void; - } - export class PrimitiveShader extends glCore.GLShader { } + class PrimitiveShader extends glCore.GLShader { } // math - export namespace GroupD8 { - - export const E: number; - export const SE: number; - export const S: number; - export const SW: number; - export const W: number; - export const NW: number; - export const N: number; - export const NE: number; - export const MIRROR_HORIZONTAL: number; - export const MIRROR_VERTICAL: number; - - export function uX(ind: number): number; - export function uY(ind: number): number; - export function vX(ind: number): number; - export function vY(ind: number): number; - export function inv(rotation: number): number; - export function add(rotationSecond: number, rotationFirst: number): number; - export function sub(rotationSecond: number, rotationFirst: number): number; - export function rotate180(rotation: number): number; - export function isSwapWidthHeight(rotation: number): boolean; - export function byDirection(dx: number, dy: number): number; - export function matrixAppendRotationInv(matrix: Matrix, rotation: number, tx: number, ty: number): void; + namespace GroupD8 { + const E: number; + const SE: number; + const S: number; + const SW: number; + const W: number; + const NW: number; + const N: number; + const NE: number; + const MIRROR_HORIZONTAL: number; + const MIRROR_VERTICAL: number; + function uX(ind: number): number; + function uY(ind: number): number; + function vX(ind: number): number; + function vY(ind: number): number; + function inv(rotation: number): number; + function add(rotationSecond: number, rotationFirst: number): number; + function sub(rotationSecond: number, rotationFirst: number): number; + function rotate180(rotation: number): number; + function isSwapWidthHeight(rotation: number): boolean; + function byDirection(dx: number, dy: number): number; + function matrixAppendRotationInv(matrix: Matrix, rotation: number, tx: number, ty: number): void; } - export class Matrix { - + class Matrix { constructor(a?: number, b?: number, c?: number, d?: number, tx?: number, ty?: number); a: number; @@ -662,10 +634,8 @@ declare namespace PIXI { static IDENTITY: Matrix; static TEMP_MATRIX: Matrix; - } - export class ObservablePoint { - + class ObservablePoint { constructor(cb: Function, scope?: any, x?: number, y?: number); x: number; @@ -675,10 +645,8 @@ declare namespace PIXI { set(x?: number, y?: number): void; copy(point: Point | ObservablePoint): void; - } - export class Point { - + class Point { constructor(x?: number, y?: number); x: number; @@ -688,18 +656,14 @@ declare namespace PIXI { copy(p: Point): void; equals(p: Point): boolean; set(x?: number, y?: number): void; - } - export interface IShape { + interface IShape { } - export interface IHitArea extends IShape { - + interface IHitArea extends IShape { contains(x: number, y: number): boolean; - } - export class Circle { - + class Circle { constructor(x?: number, y?: number, radius?: number); x: number; @@ -710,10 +674,8 @@ declare namespace PIXI { clone(): Circle; contains(x: number, y: number): boolean; getBounds(): Rectangle; - } - export class Ellipse { - + class Ellipse { constructor(x?: number, y?: number, width?: number, height?: number); x: number; @@ -725,10 +687,8 @@ declare namespace PIXI { clone(): Ellipse; contains(x: number, y: number): boolean; getBounds(): Rectangle; - } - export class Polygon { - + class Polygon { constructor(points: Point[] | number[]); constructor(...points: Point[]); constructor(...points: number[]); @@ -740,10 +700,8 @@ declare namespace PIXI { clone(): Polygon; contains(x: number, y: number): boolean; close(): void; - } - export class Rectangle { - + class Rectangle { constructor(x?: number, y?: number, width?: number, height?: number); x: number; @@ -764,10 +722,8 @@ declare namespace PIXI { pad(paddingX: number, paddingY: number): void; fit(rectangle: Rectangle): void; enlarge(rectangle: Rectangle): void; - } - export class RoundedRectangle { - + class RoundedRectangle { constructor(x?: number, y?: number, width?: number, height?: number, radius?: number); x: number; @@ -779,13 +735,11 @@ declare namespace PIXI { clone(): RoundedRectangle; contains(x: number, y: number): boolean; - } // renderers - export interface IRendererOptions { - + interface IRendererOptions { view?: HTMLCanvasElement; transparent?: boolean; autoResize?: boolean; @@ -795,10 +749,8 @@ declare namespace PIXI { backgroundColor?: number; roundPixels?: boolean; context?: WebGLRenderingContext; - } - export class SystemRenderer extends utils.EventEmitter { - + class SystemRenderer extends utils.EventEmitter { constructor(system: string, screenWidth?: number, screenHeight?: number, options?: IRendererOptions); type: number; @@ -824,10 +776,8 @@ declare namespace PIXI { generateTexture(displayObject: DisplayObject, scaleMode?: number, resolution?: number): RenderTexture; render(...args: any[]): void; destroy(removeView?: boolean): void; - } - export class CanvasRenderer extends SystemRenderer { - + class CanvasRenderer extends SystemRenderer { // plugintarget mixin start static __plugins: Object; static registerPlugin(pluginName: string, ctor: Function): void; @@ -862,20 +812,16 @@ declare namespace PIXI { once(event: "postrender", fn: () => void, context?: any): this; once(event: string, fn: Function, context?: any): this; off(event: string, fn: Function, context?: any): this; - } - export class CanvasMaskManager { - + class CanvasMaskManager { constructor(renderer: CanvasRenderer); pushMask(maskData: any): void; protected renderGraphicsShape(graphics: Graphics): void; popMask(renderer: WebGLRenderer | CanvasRenderer): void; destroy(): void; - } - export class CanvasRenderTarget { - + class CanvasRenderTarget { constructor(width: number, height: number, resolution: number); canvas: HTMLCanvasElement; @@ -888,11 +834,9 @@ declare namespace PIXI { clear(): void; resize(width: number, height: number): void; destroy(): void; - } - export interface IWebGLRendererOptions { - + interface IWebGLRendererOptions { view?: HTMLCanvasElement; transparent?: boolean; autoResize?: boolean; @@ -903,10 +847,8 @@ declare namespace PIXI { preserveDrawingBuffer?: boolean; roundPixels?: boolean; legacy?: boolean; - } - export class WebGLRenderer extends SystemRenderer { - + class WebGLRenderer extends SystemRenderer { // plugintarget mixin start static __plugins: Object; static registerPlugin(pluginName: string, ctor: Function): void; @@ -973,10 +915,8 @@ declare namespace PIXI { once(event: "postrender", fn: () => void, context?: any): this; once(event: string, fn: Function, context?: any): this; off(event: string, fn: Function, context?: any): this; - } - export class WebGLState { - + class WebGLState { constructor(gl: WebGLRenderingContext); activeState: number[]; @@ -998,10 +938,8 @@ declare namespace PIXI { setFrontFace(value: number): void; resetAttributes(): void; resetToDefault(): void; - } - export class TextureManager { - + class TextureManager { constructor(renderer: WebGLRenderer); renderer: WebGLRenderer; @@ -1014,10 +952,8 @@ declare namespace PIXI { destroyTexture(texture: BaseTexture, _skipRemove?: boolean): void; removeAll(): void; destroy(): void; - } - export class TextureGarbageCollector { - + class TextureGarbageCollector { constructor(renderer: WebGLRenderer); renderer: WebGLRenderer; @@ -1030,10 +966,8 @@ declare namespace PIXI { update(): void; run(): void; unload(): void; - } - export abstract class ObjectRenderer extends WebGLManager { - + abstract class ObjectRenderer extends WebGLManager { constructor(renderer: WebGLRenderer); start(): void; @@ -1041,10 +975,8 @@ declare namespace PIXI { flush(): void; render(...args: any[]): void; - } - export class Quad { - + class Quad { constructor(gl: WebGLRenderingContext); gl: WebGLRenderingContext; @@ -1058,10 +990,8 @@ declare namespace PIXI { map(targetTextureFrame: Rectangle, destinationFrame: Rectangle): Quad; upload(): Quad; destroy(): void; - } - export class RenderTarget { - + class RenderTarget { constructor(gl: WebGLRenderingContext, width: number, height: number, scaleMode: number, resolution: number, root?: boolean); gl: WebGLRenderingContext; @@ -1080,11 +1010,11 @@ declare namespace PIXI { stencilMaskStack: Graphics[]; filterData: { index: number, - stack: { + stack: Array<{ renderTarget: RenderTarget, filter: any[]; bounds: Rectangle - }[] + }> }; scaleMode: number; root: boolean; @@ -1096,32 +1026,28 @@ declare namespace PIXI { calculateProjection(destinationFrame: Rectangle, sourceFrame: Rectangle): void; resize(width: number, height: number): void; destroy(): void; - } - export class BlendModeManager extends WebGLManager { - + class BlendModeManager extends WebGLManager { constructor(renderer: WebGLRenderer); currentBlendMode: number; setBlendMode(blendMode: number): boolean; - } - export class FilterManager extends WebGLManager { - + class FilterManager extends WebGLManager { constructor(renderer: WebGLRenderer); gl: WebGLRenderingContext; quad: Quad; - stack: { + stack: Array<{ renderTarget: RenderTarget; sourceFrame: Rectangle; destinationFrame: Rectangle; filters: Filter[]; target: any; resolution: number; - }[]; + }>; stackIndex: number; shaderCache: any; filterData: any; @@ -1139,17 +1065,13 @@ declare namespace PIXI { emptyPool(): void; getPotRenderTarget(gl: WebGLRenderingContext, minWidth: number, minHeight: number, resolution: number): RenderTarget; freePotRenderTarget(renderTarget: RenderTarget): void; - } - export class StencilMaskStack { - + class StencilMaskStack { stencilStack: any[]; reverse: boolean; count: number; - } - export class MaskManager extends WebGLManager { - + class MaskManager extends WebGLManager { scissor: boolean; scissorData: any; scissorRenderTarget: RenderTarget; @@ -1164,10 +1086,8 @@ declare namespace PIXI { popStencilMask(): void; pushScissorMask(target: RenderTarget, maskData: Sprite | Graphics): void; popScissorMask(): void; - } - export class StencilManager extends WebGLManager { - + class StencilManager extends WebGLManager { constructor(renderer: WebGLRenderer); stencilMaskStack: Graphics[]; @@ -1176,28 +1096,22 @@ declare namespace PIXI { pushStencil(graphics: Graphics): void; popStencil(): void; destroy(): void; - } - export class WebGLManager { - + class WebGLManager { constructor(renderer: WebGLRenderer); renderer: SystemRenderer; onContextChange(): void; destroy(): void; - } - export interface IUniformData { - + interface IUniformData { type: string; value: any; // name is set by pixi if uniforms were automatically extracted from shader code, but not used anywhere name?: string; - } - export class Filter { - + class Filter { constructor(vertexSrc?: string, fragmentSrc?: string, uniforms?: { [name: string]: IUniformData }); vertextSrc?: string; @@ -1214,22 +1128,18 @@ declare namespace PIXI { static defaultVertexSrc: string; static defaultFragmentSrc: string; - } - export class SpriteMaskFilter extends Filter { - + class SpriteMaskFilter extends Filter { constructor(sprite: Sprite); maskSprite: Sprite; maskMatrix: Matrix; apply(filterManager: FilterManager, input: RenderTarget, output: RenderTarget): void; - } // sprites - export class Sprite extends Container { - + class Sprite extends Container { constructor(texture?: Texture); protected _anchor: ObservablePoint; @@ -1268,19 +1178,15 @@ declare namespace PIXI { static from(source: number | string | BaseTexture | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement): Sprite; static fromFrame(frameId: string): Sprite; static fromImage(imageId: string, crossorigin?: boolean, scaleMode?: number): Sprite; - } - export class BatchBuffer { - + class BatchBuffer { vertices: ArrayBuffer; float32View: number[]; uint32View: number[]; destroy(): void; - } - export class SpriteRenderer extends ObjectRenderer { - + class SpriteRenderer extends ObjectRenderer { constructor(renderer: PIXI.WebGLRenderer); vertSize: number; @@ -1305,33 +1211,28 @@ declare namespace PIXI { start(): void; stop(): void; destroy(): void; - } - export class CanvasSpriteRenderer extends ObjectRenderer { - + class CanvasSpriteRenderer extends ObjectRenderer { constructor(renderer: WebGLRenderer); render(sprite: Sprite): void; destroy(): void; - } - export namespace CanvasTinter { - - export function getTintedTexture(sprite: Sprite, color: number): HTMLCanvasElement; - export function tintWithMultiply(texture: Texture, color: number, canvas: HTMLCanvasElement): void; - export function tintWithOverlay(texture: Texture, color: number, canvas: HTMLCanvasElement): void; - export function tintWithPerPixel(texture: Texture, color: number, canvas: HTMLCanvasElement): void; - export function roundColor(color: number): number; - - export let cacheStepsPerColorChannel: number; - export let convertTintToImage: boolean; - export let canUseMultiply: boolean; - export let tintMethod: Function; + namespace CanvasTinter { + function getTintedTexture(sprite: Sprite, color: number): HTMLCanvasElement; + function tintWithMultiply(texture: Texture, color: number, canvas: HTMLCanvasElement): void; + function tintWithOverlay(texture: Texture, color: number, canvas: HTMLCanvasElement): void; + function tintWithPerPixel(texture: Texture, color: number, canvas: HTMLCanvasElement): void; + function roundColor(color: number): number; + let cacheStepsPerColorChannel: number; + let convertTintToImage: boolean; + let canUseMultiply: boolean; + let tintMethod: Function; } // text - export interface TextStyleOptions { + interface TextStyleOptions { align?: string; breakWords?: boolean; dropShadow?: boolean; @@ -1361,8 +1262,7 @@ declare namespace PIXI { wordWrapWidth?: number; } - export class TextStyle implements TextStyleOptions { - + class TextStyle implements TextStyleOptions { constructor(style: TextStyleOptions) styleID: number; @@ -1424,11 +1324,9 @@ declare namespace PIXI { wordWrap: boolean; protected _wordWrapWidth: number; wordWrapWidth: number; - } - export class Text extends Sprite { - + class Text extends Sprite { static getFontStyle(style: TextStyleOptions): string; static calculateFontProperties(style: string): any; @@ -1464,13 +1362,11 @@ declare namespace PIXI { protected _generateFillStyle(style: TextStyle, lines: string[]): string | number | CanvasGradient; destroy(options?: IDestroyOptions | boolean): void; dirty: boolean; - } // textures - export class BaseRenderTexture extends BaseTexture { - + class BaseRenderTexture extends BaseTexture { constructor(width?: number, height?: number, scaleMode?: number, resolution?: number); height: number; @@ -1492,10 +1388,8 @@ declare namespace PIXI { on(event: "update", fn: (baseRenderTexture: BaseRenderTexture) => void, context?: any): this; on(event: string, fn: Function, context?: any): this; off(event: string, fn: Function, context?: any): this; - } - export class BaseTexture extends utils.EventEmitter { - + class BaseTexture extends utils.EventEmitter { static from(source: string | HTMLImageElement | HTMLCanvasElement, scaleMode?: number, sourceScale?: number): BaseTexture; constructor(source?: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement, scaleMode?: number, resolution?: number); @@ -1551,10 +1445,8 @@ declare namespace PIXI { once(event: "dispose", fn: (baseTexture: BaseTexture) => void, context?: any): this; once(event: string, fn: Function, context?: any): this; off(event: string, fn: Function, context?: any): this; - } - export class RenderTexture extends Texture { - + class RenderTexture extends Texture { constructor(baseRenderTexture: BaseRenderTexture, frame?: Rectangle); protected legacyRenderer: any; @@ -1563,11 +1455,9 @@ declare namespace PIXI { resize(width: number, height: number, doNotResizeBaseTexture?: boolean): void; static create(width?: number, height?: number, scaleMode?: number, resolution?: number): RenderTexture; - } - export class Texture extends utils.EventEmitter { - - static from(source: number | string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | PIXI.BaseTexture): Texture; + class Texture extends utils.EventEmitter { + static from(source: number | string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | BaseTexture): Texture; constructor(baseTexture: BaseTexture, frame?: Rectangle, orig?: Rectangle, trim?: Rectangle, rotate?: number); @@ -1594,7 +1484,6 @@ declare namespace PIXI { static fromCanvas(canvas: HTMLCanvasElement, scaleMode?: number): Texture; static fromVideo(video: HTMLVideoElement | string, scaleMode?: number): Texture; static fromVideoUrl(videoUrl: string, scaleMode?: number): Texture; - static from(source: string | BaseTexture | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement): Texture; static fromLoader(source: HTMLImageElement | HTMLCanvasElement, imageUrl: string, name?: string): Texture; static addTextureToCache(texture: Texture, id: string): void; static removeTextureFromCache(id: string): Texture | undefined; @@ -1612,10 +1501,8 @@ declare namespace PIXI { once(event: "update", fn: (texture: Texture) => void, context?: any): this; once(event: string, fn: Function, context?: any): this; off(event: string, fn: Function, context?: any): this; - } - export class TextureUvs { - + class TextureUvs { x0: number; y0: number; x1: number; @@ -1628,11 +1515,9 @@ declare namespace PIXI { uvsUint32: Uint32Array; protected set(frame: Rectangle, baseFrame: Rectangle, rotate: number): void; - } - export class Spritesheet { - + class Spritesheet { static BATCH_SIZE: number; constructor(baseTexture: BaseTexture, data: any, resolutionFilename?: string); @@ -1651,11 +1536,9 @@ declare namespace PIXI { protected _parseComplete(): void; protected _nextBatch(): void; destroy(destroyBase?: boolean): void; - } - export class VideoBaseTexture extends BaseTexture { - + class VideoBaseTexture extends BaseTexture { constructor(source: HTMLVideoElement, scaleMode?: number); autoUpdate: boolean; @@ -1681,11 +1564,9 @@ declare namespace PIXI { // ticker namespace ticker { + const shared: Ticker; - export const shared: Ticker; - - export class Ticker { - + class Ticker { protected _tick(time: number): void; protected _emitter: utils.EventEmitter; protected _requestId: number | null; @@ -1711,23 +1592,19 @@ declare namespace PIXI { start(): void; stop(): void; update(): void; - } - } // shader - export class Shader extends glCore.GLShader { } + class Shader extends glCore.GLShader { } ////////////////////////////////////////////////////////////////////////////// ////////////////////////////EXTRACT/////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - export namespace extract { - - export class CanvasExtract { - + namespace extract { + class CanvasExtract { protected renderer: CanvasRenderer; constructor(renderer: CanvasRenderer); @@ -1738,9 +1615,8 @@ declare namespace PIXI { pixels(renderTexture?: DisplayObject | RenderTexture): number[]; destroy(): void; - } - export class WebGLExtract { + class WebGLExtract { protected renderer: WebGLRenderer; constructor(renderer: WebGLRenderer); @@ -1752,27 +1628,22 @@ declare namespace PIXI { destroy(): void; } - } ////////////////////////////////////////////////////////////////////////////// ////////////////////////////EXTRAS//////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - export namespace extras { - - export interface IBitmapTextStyle { - + namespace extras { + interface IBitmapTextStyle { font?: string | { name?: string; size?: number; }; align?: string; tint?: number; - } - export class BitmapText extends Container { - + class BitmapText extends Container { static registerFont(xml: XMLDocument, texture: Texture): any; constructor(text: string, style?: IBitmapTextStyle); @@ -1806,16 +1677,14 @@ declare namespace PIXI { protected validate(): void; static fonts: any; - } - export class AnimatedSprite extends Sprite { - - constructor(textures: Texture[] | { texture: Texture, time?: number }[], autoUpdate?: boolean); + class AnimatedSprite extends Sprite { + constructor(textures: Texture[] | Array<{ texture: Texture, time?: number }>, autoUpdate?: boolean); protected _autoUpdate: boolean; protected _textures: Texture[]; protected _durations: number[]; - textures: Texture[] | { texture: Texture, time?: number }[]; + textures: Texture[] | Array<{ texture: Texture, time?: number }>; animationSpeed: number; loop: boolean; onComplete: () => void; @@ -1833,10 +1702,8 @@ declare namespace PIXI { static fromFrames(frame: string[]): AnimatedSprite; static fromImages(images: string[]): AnimatedSprite; - } - export class TextureTransform { - + class TextureTransform { constructor(texture: Texture, clampMargin?: number); protected _texture: Texture; @@ -1851,10 +1718,8 @@ declare namespace PIXI { texture: Texture; update(forceUpdate?: boolean): void; - } - export class TilingSprite extends Sprite { - + class TilingSprite extends Sprite { constructor(texture: Texture, width?: number, height?: number); tileTransform: TransformStatic; @@ -1884,27 +1749,21 @@ declare namespace PIXI { width: number; height: number; - } - export class TilingSpriteRenderer extends ObjectRenderer { - + class TilingSpriteRenderer extends ObjectRenderer { constructor(renderer: WebGLRenderer); render(ts: TilingSprite): void; - } - } ////////////////////////////////////////////////////////////////////////////// ////////////////////////////FILTERS/////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - export namespace filters { - - export class FXAAFilter extends Filter { } - export class BlurFilter extends Filter { - + namespace filters { + class FXAAFilter extends Filter { } + class BlurFilter extends Filter { constructor(strength?: number, quality?: number, resolution?: number, kernelSize?: number); blurXFilter: BlurXFilter; @@ -1916,10 +1775,8 @@ declare namespace PIXI { blurX: number; blurY: number; quality: number; - } - export class BlurXFilter extends Filter { - + class BlurXFilter extends Filter { constructor(strength?: number, quality?: number, resolution?: number, kernelSize?: number); protected _quality: number; @@ -1930,10 +1787,8 @@ declare namespace PIXI { strength: number; firstRun: boolean; blur: number; - } - export class BlurYFilter extends Filter { - + class BlurYFilter extends Filter { constructor(strength?: number, quality?: number, resolution?: number, kernelSize?: number); protected _quality: number; @@ -1944,10 +1799,8 @@ declare namespace PIXI { strength: number; firstRun: boolean; blur: number; - } - export class ColorMatrixFilter extends Filter { - + class ColorMatrixFilter extends Filter { constructor(); protected _loadMatrix(matrix: number[], multiply?: boolean): void; @@ -1976,38 +1829,30 @@ declare namespace PIXI { predator(amount: number, multiply?: boolean): void; lsd(multiply?: boolean): void; reset(): void; - } - export class DisplacementFilter extends Filter { - + class DisplacementFilter extends Filter { constructor(sprite: Sprite, scale?: number); scale: Point; map: Texture; - } - export class VoidFilter extends Filter { + class VoidFilter extends Filter { glShaderKey: number; } // pixi-filters.d.ts todo // https://github.com/pixijs/pixi-filters/ - export class NoiseFilter extends Filter { - + class NoiseFilter extends Filter { noise: number; - } - } ////////////////////////////////////////////////////////////////////////////// ////////////////////////////INTERACTION/////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - export namespace interaction { - - export interface InteractiveTarget { - + namespace interaction { + interface InteractiveTarget { interactive: boolean; interactiveChildren: boolean; hitArea: PIXI.Rectangle | PIXI.Circle | PIXI.Ellipse | PIXI.Polygon | PIXI.RoundedRectangle; @@ -2017,44 +1862,36 @@ declare namespace PIXI { // depricated defaultCursor: string; - } - export interface InteractionTrackingData { - + interface InteractionTrackingData { readonly pointerId: number; flags: number; none: number; over: boolean; rightDown: boolean; leftDown: boolean; - } - export interface InteractionEvent { - + interface InteractionEvent { stopped: boolean; target: DisplayObject; currentTarget: DisplayObject; type: string; data: InteractionData; stopPropagation(): void; - } - export class InteractionData { - + class InteractionData { global: Point; target: DisplayObject; originalEvent: Event; identifier?: number; getLocalPosition(displayObject: DisplayObject, point?: Point, globalPos?: Point): Point; - } - export interface InteractionManagerOptions { + interface InteractionManagerOptions { autoPreventDefault?: boolean; interactionFrequency?: number; } - export class InteractionManager extends utils.EventEmitter { - + class InteractionManager extends utils.EventEmitter { constructor(renderer: CanvasRenderer | WebGLRenderer | SystemRenderer, options?: InteractionManagerOptions); renderer: SystemRenderer; @@ -2096,7 +1933,12 @@ declare namespace PIXI { setCursorMode(mode: string): void; protected dispatchEvent(displayObject: Container | Sprite | extras.TilingSprite, eventString: string, eventData: any): void; mapPositionToPoint(point: Point, x: number, y: number): void; - protected processInteractive(interactionEvent: InteractionEvent, displayObject: PIXI.Container | PIXI.Sprite | PIXI.extras.TilingSprite, func?: Function, hitTest?: boolean, interactive?: boolean): boolean; + protected processInteractive( + interactionEvent: InteractionEvent, + displayObject: PIXI.Container | PIXI.Sprite | PIXI.extras.TilingSprite, + func?: Function, + hitTest?: boolean, + interactive?: boolean): boolean; protected onPointerComplete(originalEvent: PointerEvent, cancelled: boolean, func: Function): void; protected getInteractionDataForPointerId(pointerId: number): InteractionData; protected releaseInteractionDataForPointerId(pointerId: number): void; @@ -2107,9 +1949,7 @@ declare namespace PIXI { // depricated defaultCursorStyle: string; currentCursorStyle: string; - } - } ////////////////////////////////////////////////////////////////////////////// @@ -2121,7 +1961,6 @@ declare namespace PIXI { // 2.0.6 class MiniSignalBinding { - constructor(fn: Function, once?: boolean, thisArg?: any); protected _fn: Function; @@ -2132,10 +1971,8 @@ declare namespace PIXI { protected _owner: MiniSignal; detach(): boolean; - } class MiniSignal { - constructor(); protected _head: MiniSignalBinding; @@ -2151,31 +1988,24 @@ declare namespace PIXI { once(fn: Function, thisArg?: any): any; detach(node: MiniSignalBinding): MiniSignal; detachAll(): MiniSignal; - } - export namespace loaders { - - export interface ILoaderOptions { - + namespace loaders { + interface ILoaderOptions { crossOrigin?: boolean | string; loadType?: number; xhrType?: string; metaData?: any; loadElement?: HTMLImageElement | HTMLAudioElement | HTMLVideoElement; skipSource?: boolean; - } - export interface IResourceDictionary { - + interface IResourceDictionary { [index: string]: PIXI.loaders.Resource; - } // As of ResourceLoader v2 we no longer require EventEmitter // However, for depreciation reasons, it remains. - export class Loader extends utils.EventEmitter { - + class Loader extends utils.EventEmitter { // pixi overrides here static addPixiMiddleware(fn: Function): void; @@ -2236,13 +2066,11 @@ declare namespace PIXI { once(event: "progress", fn: (loader: loaders.Loader, resource: Resource) => void, context?: any): this; once(event: "start", fn: (loader: loaders.Loader) => void, context?: any): this; once(event: string, fn: Function, context?: any): this; - } - export interface ITextureDictionary { + interface ITextureDictionary { [index: string]: PIXI.Texture; } - export class Resource { - + class Resource { static setExtensionLoadType(extname: string, loadType: number): void; static setExtensionXhrType(extname: string, xhrType: string): void; @@ -2351,10 +2179,8 @@ declare namespace PIXI { ///////////////////////////////MESH/////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - export namespace mesh { - - export class Mesh extends Container { - + namespace mesh { + class Mesh extends Container { constructor(texture: Texture, vertices?: Float32Array, uvs?: Float32Array, indices?: Uint16Array, drawMode?: number); protected _texture: Texture; @@ -2383,11 +2209,9 @@ declare namespace PIXI { TRIANGLE_MESH: number; TRIANGLES: number; }; - } - export class CanvasMeshRenderer { - + class CanvasMeshRenderer { constructor(renderer: CanvasRenderer); renderer: CanvasRenderer; @@ -2399,20 +2223,16 @@ declare namespace PIXI { protected renderMeshFlat(mesh: Mesh): void; destroy(): void; - } - export class MeshRenderer extends ObjectRenderer { - + class MeshRenderer extends ObjectRenderer { constructor(renderer: WebGLRenderer); shader: Shader; render(mesh: Mesh): void; - } - export class Plane extends Mesh { - + class Plane extends Mesh { constructor(texture: Texture, verticesX?: number, verticesY?: number); protected _ready: boolean; verticesX: number; @@ -2422,11 +2242,9 @@ declare namespace PIXI { refresh(): void; protected _onTexureUpdate(): void; - } - export class NineSlicePlane extends Plane { - + class NineSlicePlane extends Plane { constructor(texture: Texture, leftWidth?: number, topHeight?: number, rightWidth?: number, bottomHeight?: number); width: number; @@ -2450,11 +2268,9 @@ declare namespace PIXI { updateHorizontalVertices(): void; updateVerticalVertices(): void; protected drawSegment(context: CanvasRenderingContext2D | WebGLRenderingContext, textureSource: any, w: number, h: number, x1: number, y1: number, x2: number, y2: number): void; - } - export class Rope extends Mesh { - + class Rope extends Mesh { constructor(texture: Texture, points: Point[]); points: Point[]; @@ -2464,7 +2280,6 @@ declare namespace PIXI { protected _onTextureUpdate(): void; updateTransform(): void; - } } @@ -2472,19 +2287,15 @@ declare namespace PIXI { /////////////////////////////PARTICLES//////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - export namespace particles { - - export interface IParticleContainerProperties { - + namespace particles { + interface IParticleContainerProperties { scale?: boolean; position?: boolean; rotation?: boolean; uvs?: boolean; alpha?: boolean; - } - export class ParticleContainer extends Container { - + class ParticleContainer extends Container { constructor(size?: number, properties?: IParticleContainerProperties, batchSize?: number); protected _properties: boolean[]; @@ -2501,10 +2312,8 @@ declare namespace PIXI { protected onChildrenChange: (smallestChildIndex?: number) => void; destroy(options?: IDestroyOptions | boolean): void; - } - export class ParticleBuffer { - + class ParticleBuffer { constructor(gl: WebGLRenderingContext, properties: any, dynamicPropertyFlags: any[], size: number); gl: WebGLRenderingContext; @@ -2521,16 +2330,14 @@ declare namespace PIXI { dynamicData: any; destroy(): void; - } - export interface IParticleRendererProperty { + interface IParticleRendererProperty { attribute: number; size: number; - uploadFunction: (children: PIXI.DisplayObject[], startIndex: number, amount: number, array: number[], stride: number, offset: number) => void; + uploadFunction(children: PIXI.DisplayObject[], startIndex: number, amount: number, array: number[], stride: number, offset: number): void; offset: number; } - export class ParticleRenderer extends ObjectRenderer { - + class ParticleRenderer extends ObjectRenderer { constructor(renderer: WebGLRenderer); shader: glCore.GLShader; @@ -2548,26 +2355,18 @@ declare namespace PIXI { destroy(): void; indices: Uint16Array; - } - export interface IParticleShader extends glCore.GLShader { } - + interface IParticleShader extends glCore.GLShader { } } ////////////////////////////////////////////////////////////////////////////// ////////////////////////////PREPARE/////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - export namespace prepare { - - interface AddHook { - (item: any, queue: any[]): boolean; - } - interface UploadHook { - (prepare: UploadHookSource, item: any): boolean; - } - export abstract class BasePrepare{ - + namespace prepare { + type AddHook = (item: any, queue: any[]) => boolean; + type UploadHook = (prepare: UploadHookSource, item: any) => boolean; + abstract class BasePrepare{ constructor(renderer: SystemRenderer); limiter: CountLimiter | TimeLimiter; @@ -2575,7 +2374,7 @@ declare namespace PIXI { protected uploadHookHelper: UploadHookSource; protected queue: any[]; protected addHooks: AddHook[]; - protected uploadHooks: UploadHook[]; + protected uploadHooks: Array>; protected completes: Function[]; protected ticking: boolean; protected delayedTick: () => void; @@ -2586,38 +2385,28 @@ declare namespace PIXI { register(addHook?: AddHook, uploadHook?: UploadHook): this; add(item: PIXI.DisplayObject | PIXI.Container | PIXI.BaseTexture | PIXI.Texture | PIXI.Graphics | PIXI.Text | any): this; destroy(): void; - } - export class CanvasPrepare extends BasePrepare { - + class CanvasPrepare extends BasePrepare { constructor(renderer: CanvasRenderer); protected canvas: HTMLCanvasElement; protected ctx: CanvasRenderingContext2D; - } - export class WebGLPrepare extends BasePrepare { - + class WebGLPrepare extends BasePrepare { constructor(renderer: WebGLRenderer); - } - export class CountLimiter { - + class CountLimiter { constructor(maxItemsPerFrame: number); protected maxItemsPerFrame: number; protected itemsLeft: number; - } - export class TimeLimiter { - + class TimeLimiter { constructor(maxMilliseconds: number); protected maxMilliseconds: number; protected frameStart: number; - } - } ////////////////////////////////////////////////////////////////////////////// @@ -2626,9 +2415,8 @@ declare namespace PIXI { // pixi-gl-core https://github.com/pixijs/pixi-gl-core // sharedArrayBuffer as a type is not available yet. // need to fully define what an `Attrib` is. - export namespace glCore { - - export interface IContextOptions { + namespace glCore { + interface IContextOptions { /** * Boolean that indicates if the canvas contains an alpha buffer. */ @@ -2658,10 +2446,9 @@ declare namespace PIXI { */ failIfMajorPerformanceCaveat?: boolean; } - export function createContext(view: HTMLCanvasElement, options?: IContextOptions): WebGLRenderingContext; - export function setVertexAttribArrays(gl: WebGLRenderingContext, attribs: IAttrib[], state?: WebGLState): WebGLRenderingContext | undefined; - export class GLBuffer { - + function createContext(view: HTMLCanvasElement, options?: IContextOptions): WebGLRenderingContext; + function setVertexAttribArrays(gl: WebGLRenderingContext, attribs: IAttrib[], state?: WebGLState): WebGLRenderingContext | undefined; + class GLBuffer { constructor(gl: WebGLRenderingContext, type: number, data: ArrayBuffer | ArrayBufferView | any, drawType: number); protected _updateID?: number; @@ -2679,10 +2466,8 @@ declare namespace PIXI { static create(gl: WebGLRenderingContext, type: number, data: ArrayBuffer | ArrayBufferView | any, drawType: number): GLBuffer; destroy(): void; - } - export class GLFramebuffer { - + class GLFramebuffer { constructor(gl: WebGLRenderingContext, width: number, height: number); gl: WebGLRenderingContext; @@ -2702,10 +2487,8 @@ declare namespace PIXI { static createRGBA(gl: WebGLRenderingContext, width: number, height: number, data: ArrayBuffer | ArrayBufferView | any): GLFramebuffer; static createFloat32(gl: WebGLRenderingContext, width: number, height: number, data: ArrayBuffer | ArrayBufferView | any): GLFramebuffer; - } - export class GLShader { - + class GLShader { constructor(gl: WebGLRenderingContext, vertexSrc: string | string[], fragmentSrc: string | string[], precision: string, attributeLocations: { [key: string]: number }); gl: WebGLRenderingContext; @@ -2716,10 +2499,8 @@ declare namespace PIXI { bind(): void; destroy(): void; - } - export class GLTexture { - + class GLTexture { constructor(gl: WebGLRenderingContext, width?: number, height?: number, format?: number, type?: number); gl: WebGLRenderingContext; @@ -2747,10 +2528,8 @@ declare namespace PIXI { static fromSource(gl: WebGLRenderingContext, source: HTMLImageElement | ImageData | HTMLVideoElement | HTMLCanvasElement, premultipleAlpha?: boolean): GLTexture; static fromData(gl: WebGLRenderingContext, data: number[], width: number, height: number): GLTexture; - } - export interface IAttrib { - + interface IAttrib { attribute: { location: boolean; size: number; @@ -2759,25 +2538,21 @@ declare namespace PIXI { stride: number; start: number; buffer: ArrayBuffer; - } - export interface IWebGLRenderingContextAttribute { - + interface IWebGLRenderingContextAttribute { buffer: WebGLBuffer; attribute: any; type: number; normalized: boolean; stride: number; start: number; - } - export interface IAttribState { + interface IAttribState { tempAttribState: IAttrib[]; attribState: IAttrib[]; } - export class VertexArrayObject { - + class VertexArrayObject { static FORCE_NATIVE: boolean; constructor(gl: WebGLRenderingContext, state: WebGLState); @@ -2798,66 +2573,63 @@ declare namespace PIXI { clear(): VertexArrayObject; draw(type: number, size: number, start: number): VertexArrayObject; destroy(): void; - } - } ////////////////////////////////////////////////////////////////////////////// ///////////////////////////////UTILS////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - export interface IDecomposedDataUri { + interface IDecomposedDataUri { mediaType: string; subType: string; encoding: string; data: any; } - export namespace utils { - - export function uid(): number; - export function hex2rgb(hex: number, out?: number[]): number[]; - export function hex2string(hex: number): string; - export function rgb2hex(rgb: Number[]): number; - export function canUseNewCanvasBlendModes(): boolean; - export function getResolutionOfUrl(url: string, defaultValue?: number): number; - export function getSvgSize(svgString: string): any; - export function decomposeDataUri(dataUri: string): IDecomposedDataUri | void; - export function getUrlFileExtension(url: string): string | void; - export function sayHello(type: string): void; - export function skipHello(): void; - export function isWebGLSupported(): boolean; - export function sign(n: number): number; - export function removeItems(arr: T[], startIdx: number, removeCount: number): void; - export const TextureCache: any; - export const BaseTextureCache: any; + namespace utils { + function uid(): number; + function hex2rgb(hex: number, out?: number[]): number[]; + function hex2string(hex: number): string; + function rgb2hex(rgb: Number[]): number; + function canUseNewCanvasBlendModes(): boolean; + function getResolutionOfUrl(url: string, defaultValue?: number): number; + function getSvgSize(svgString: string): any; + function decomposeDataUri(dataUri: string): IDecomposedDataUri | void; + function getUrlFileExtension(url: string): string | void; + function sayHello(type: string): void; + function skipHello(): void; + function isWebGLSupported(): boolean; + function sign(n: number): number; + function removeItems(arr: T[], startIdx: number, removeCount: number): void; + const TextureCache: any; + const BaseTextureCache: any; // https://github.com/kaimallea/isMobile - export namespace isMobile { - export const apple: { + namespace isMobile { + const apple: { phone: boolean; ipod: boolean; tablet: boolean; device: boolean; }; - export const android: { + const android: { phone: boolean; tablet: boolean; device: boolean; }; - export const amazon: { + const amazon: { phone: boolean; tablet: boolean; device: boolean; }; - export const windows: { + const windows: { phone: boolean; tablet: boolean; device: boolean; }; - export const seven_inch: boolean; - export const other: { + const seven_inch: boolean; + const other: { blackberry10: boolean; blackberry: boolean; opera: boolean; @@ -2865,14 +2637,13 @@ declare namespace PIXI { chrome: boolean; device: boolean; }; - export const any: boolean; - export const phone: boolean; - export const tablet: boolean; + const any: boolean; + const phone: boolean; + const tablet: boolean; } // https://github.com/primus/eventemitter3 - export class EventEmitter { - + class EventEmitter { listeners(event: string, exists?: boolean): Function[]; emit(event: string, ...args: any[]): boolean; on(event: string, fn: Function, context?: any): this; @@ -2883,9 +2654,7 @@ declare namespace PIXI { off(event: string, fn: Function, context?: any, once?: boolean): this; addListener(event: string, fn: Function, context?: any): this; - } - } ////////////////////////////////////////////////////////////////////////////// @@ -2893,7 +2662,6 @@ declare namespace PIXI { ////////////////////////////////////////////////////////////////////////////// // not sure how to handle blendmodes scalemodes basetexturecache namespace core { - /** * @class * @private @@ -3095,11 +2863,9 @@ declare namespace PIXI { * @deprecated since version 4.2.0 */ type DEFAULT_RENDER_OPTIONS = number; - } - export namespace extras { - + namespace extras { /** * @class * @name MovieClip @@ -3108,13 +2874,11 @@ declare namespace PIXI { * @deprecated since version 4.2.0 */ type MovieClip = extras.AnimatedSprite; - } - } declare namespace pixi { - export const gl: typeof PIXI.glCore; + const gl: typeof PIXI.glCore; } declare module "pixi.js" { diff --git a/types/pixi.js/pixi.js-tests.ts b/types/pixi.js/pixi.js-tests.ts index 8cea83df3f..72325504da 100644 --- a/types/pixi.js/pixi.js-tests.ts +++ b/types/pixi.js/pixi.js-tests.ts @@ -1,13 +1,10 @@ namespace basics { - export class Basics { - private app: PIXI.Application; private bunny: PIXI.Sprite; constructor() { - this.app = new PIXI.Application(800, 600, { backgroundColor: 0x1099bb }); document.body.appendChild(this.app.view); @@ -20,19 +17,15 @@ namespace basics { this.app.ticker.add((delta: number): void => { this.bunny.rotation += 0.1 / delta; }); - } - } export class Click { - private app: PIXI.Application; private sprite: PIXI.Sprite; constructor() { - this.app = new PIXI.Application(800, 600, { backgroundColor: 0x1099bb }); document.body.appendChild(this.app.view); @@ -48,33 +41,28 @@ namespace basics { this.sprite.scale.y *= 1.25; }); this.app.stage.addChild(this.sprite); - } } export class ContainerPivot { - private app: PIXI.Application; private container: PIXI.Container; constructor() { - this.app = new PIXI.Application(800, 600, { backgroundColor: 0x1099bb }); document.body.appendChild(this.app.view); this.container = new PIXI.Container(); this.app.stage.addChild(this.container); - let texture = PIXI.Texture.fromImage("../../_assets/basics/bunny.png"); + const texture = PIXI.Texture.fromImage("../../_assets/basics/bunny.png"); for (let i = 0; i < 25; i++) { - - let bunny = new PIXI.Sprite(texture); + const bunny = new PIXI.Sprite(texture); bunny.anchor.set(0.5); bunny.x = (i % 5) * 40; bunny.y = Math.floor(i / 5) * 40; this.container.addChild(bunny); - } this.container.x = this.app.renderer.width / 2; @@ -86,43 +74,36 @@ namespace basics { this.app.ticker.add((delta: number): void => { this.container.rotation -= 0.01 / delta; }); - } } export class Container { - private app: PIXI.Application; private container: PIXI.Container; constructor() { - this.app = new PIXI.Application(800, 600, { backgroundColor: 0x1099bb }); document.body.appendChild(this.app.view); this.container = new PIXI.Container(); this.app.stage.addChild(this.container); - let texture = PIXI.Texture.fromImage("../../_assets/basics/bunny.png"); + const texture = PIXI.Texture.fromImage("../../_assets/basics/bunny.png"); for (let i = 0; i < 25; i++) { - - let bunny = new PIXI.Sprite(texture); + const bunny = new PIXI.Sprite(texture); bunny.anchor.set(0.5); bunny.x = (i % 5) * 40; bunny.y = Math.floor(i / 5) * 40; this.container.addChild(bunny); - } this.container.x = this.app.renderer.width / 2; this.container.y = this.app.renderer.height / 2; - } } export class CustomizedFilter extends PIXI.Filter { - constructor(fragmentSource: string) { super(null, fragmentSource, { customUniform: { @@ -131,16 +112,13 @@ namespace basics { } }); } - } export class CustomFilter { - private app: PIXI.Application; private background: PIXI.Sprite; private filter: CustomizedFilter; constructor() { - this.app = new PIXI.Application(800, 600, { backgroundColor: 0x1099bb }); document.body.appendChild(this.app.view); @@ -152,9 +130,7 @@ namespace basics { this.app.stop(); PIXI.loader.add("shader", "_assets/basics/shader.frag") - .load((loader: PIXI.loaders.Loader, resource: any): void => { - this.filter = new PIXI.Filter(null, resource.shader.data); this.background.filters = [this.filter]; this.app.start(); @@ -162,23 +138,19 @@ namespace basics { this.app.ticker.add((delta: number) => { this.filter.uniforms.customUniform += 0.04 / delta; }); - }); - } } export class Graphics { - private app: PIXI.Application; private graphics: PIXI.Graphics; constructor() { - this.app = new PIXI.Application(800, 600, { antialias: true }); document.body.appendChild(this.app.view); - let graphics = new PIXI.Graphics(); + const graphics = new PIXI.Graphics(); // set a fill and line style graphics.beginFill(0xFF3300); @@ -215,32 +187,30 @@ namespace basics { } export class RenderTexture { - private app: PIXI.Application; private container: PIXI.Container; private renderTexture: PIXI.RenderTexture; private sprite: PIXI.Sprite; constructor() { - this.app = new PIXI.Application(800, 600, { backgroundColor: 0x1099bb }); document.body.appendChild(this.app.view); this.container = new PIXI.Container(); this.app.stage.addChild(this.container); - let texture = PIXI.Texture.fromImage("required/assets/basics/bunny.png"); + const texture = PIXI.Texture.fromImage("required/assets/basics/bunny.png"); for (let i = 0; i < 25; i++) { - let bunny = new PIXI.Sprite(texture); + const bunny = new PIXI.Sprite(texture); bunny.x = (i % 5) * 30; bunny.y = Math.floor(i / 5) * 30; bunny.rotation = Math.random() * (Math.PI * 2); this.container.addChild(bunny); } - let brt = new PIXI.BaseRenderTexture(300, 300, PIXI.SCALE_MODES.LINEAR, 1); - let rt = new PIXI.RenderTexture(brt); + const brt = new PIXI.BaseRenderTexture(300, 300, PIXI.SCALE_MODES.LINEAR, 1); + const rt = new PIXI.RenderTexture(brt); this.sprite = new PIXI.Sprite(rt); this.sprite.x = 450; @@ -253,29 +223,23 @@ namespace basics { this.app.ticker.add((delta: number) => { this.app.renderer.render(this.container, rt); }); - } } export class SpriteSheet { - private app: PIXI.Application; private anim: PIXI.extras.AnimatedSprite; constructor() { - PIXI.loader .add("required/assets/basics/fighter.json") .load((loader: PIXI.loaders.Loader, resource: any) => { - - let frames = []; + const frames = []; for (let i = 0; i < 30; i++) { - - let val = i < 10 ? "0" + i : i; + const val = i < 10 ? "0" + i : i; frames.push(PIXI.Texture.fromFrame("rollSequence00" + val + ".png")); - } this.anim = new PIXI.extras.AnimatedSprite(frames); @@ -291,20 +255,16 @@ namespace basics { this.app.ticker.add((deltaTime: number) => { this.anim.rotation += 0.01; }); - }); } - } export class Text { - private app: PIXI.Application; private basicText: PIXI.Text; private richText: PIXI.Text; constructor() { - this.app = new PIXI.Application(800, 600, { backgroundColor: 0x1099bb }); document.body.appendChild(this.app.view); @@ -313,7 +273,7 @@ namespace basics { this.basicText.y = 90; this.app.stage.addChild(this.basicText); - let style = new PIXI.TextStyle({ + const style = new PIXI.TextStyle({ fontFamily: "Arial", fontSize: 36, fontStyle: "italic", @@ -334,13 +294,10 @@ namespace basics { this.richText.x = 30; this.richText.y = 180; this.app.stage.addChild(this.richText); - } - } export class TexturedMesh { - private app: PIXI.Application; private count: number; private points: PIXI.Point[]; @@ -348,8 +305,7 @@ namespace basics { private graphics: PIXI.Graphics; constructor() { - - let ropeLength = 918 / 20; + const ropeLength = 918 / 20; for (let i = 0; i < 25; i++) { this.points.push(new PIXI.Point(i * ropeLength, 0)); @@ -367,7 +323,6 @@ namespace basics { // start animating this.app.ticker.add((deltaTime: number) => { - this.count += 0.1; // make the snake @@ -376,13 +331,10 @@ namespace basics { this.points[i].x = i * ropeLength + Math.cos((i * 0.3) + this.count) * 20; } this.renderPoints(); - }); - } private renderPoints(): void { - this.graphics.clear(); this.graphics.lineStyle(2, 0xffc2c2); this.graphics.moveTo(this.points[0].x, this.points[0].y); @@ -396,23 +348,19 @@ namespace basics { this.graphics.drawCircle(this.points[i].x, this.points[i].y, 10); this.graphics.endFill(); } - } - } export class TilingSprite { - private app: PIXI.Application; private tilingSprite: PIXI.extras.TilingSprite; private count: number; constructor() { - this.app = new PIXI.Application(); document.body.appendChild(this.app.view); - let texture = PIXI.Texture.fromImage("required/assets/p2.jpeg"); + const texture = PIXI.Texture.fromImage("required/assets/p2.jpeg"); this.tilingSprite = new PIXI.extras.TilingSprite( texture, @@ -424,28 +372,22 @@ namespace basics { this.count = 0; this.app.ticker.add((deltaTime: number): void => { - this.count += 0.005; this.tilingSprite.tileScale.x = 2 + Math.sin(this.count); this.tilingSprite.tileScale.y = 2 + Math.cos(this.count); this.tilingSprite.tilePosition.x += 1; this.tilingSprite.tilePosition.y += 1; - }); - } - } export class Video { - private app: PIXI.Application; private button: PIXI.Graphics; private videoSprite: PIXI.Sprite; constructor() { - this.app = new PIXI.Application(800, 600, { transparent: true }); document.body.appendChild(this.app.view); @@ -470,28 +412,21 @@ namespace basics { this.app.stage.addChild(this.button); this.button.on("pointertap", (): void => { - this.button.destroy(); - let texture = PIXI.Texture.fromVideo("required/assets/testVideo.mp4"); + const texture = PIXI.Texture.fromVideo("required/assets/testVideo.mp4"); this.videoSprite = new PIXI.Sprite(texture); this.videoSprite.width = this.app.renderer.width; this.videoSprite.height = this.app.renderer.height; this.app.stage.addChild(this.videoSprite); - }); - } - } - } namespace demos { - export class AlphaMask { - private app: PIXI.Application; private bg: PIXI.Container; private cells: PIXI.Sprite; @@ -499,7 +434,6 @@ namespace demos { private target: PIXI.Point; constructor() { - this.app = new PIXI.Application(); this.app.stage.interactive = true; document.body.appendChild(this.app.view); @@ -524,34 +458,25 @@ namespace demos { this.reset(); this.app.ticker.add((deltaTime: number): void => { - this.mask.position.x += (this.target.x - this.mask.x) * 0.1; this.mask.position.y += (this.target.y - this.mask.y) * 0.1; if (Math.abs(this.mask.x - this.target.x) < 1) { this.reset(); } - - }); - } private reset(): void { - this.target.x = Math.floor(Math.random() * 550); this.target.y = Math.floor(Math.random() * 300); - } - } export class AnimatedSpriteDemo { - private app: PIXI.Application; constructor() { - this.app = new PIXI.Application(); this.app.stop(); document.body.appendChild(this.app.view); @@ -559,18 +484,15 @@ namespace demos { PIXI.loader .add("spritesheet", "required/assets/mc.json") .load((): void => { + const explosionTextures: PIXI.Texture[] = []; - let explosionTextures: PIXI.Texture[] = []; - let i: number; - - for (i = 0; i < 26; i++) { - let texture = PIXI.Texture.fromFrame("Explosion_Sequence_A " + (i + 1) + ".png"); + for (let i = 0; i < 26; i++) { + const texture = PIXI.Texture.fromFrame("Explosion_Sequence_A " + (i + 1) + ".png"); explosionTextures.push(texture); } - for (i = 0; i < 50; i++) { - - let explosion = new PIXI.extras.AnimatedSprite(explosionTextures); + for (let i = 0; i < 50; i++) { + const explosion = new PIXI.extras.AnimatedSprite(explosionTextures); explosion.x = Math.random() * this.app.renderer.width; explosion.y = Math.random() * this.app.renderer.height; @@ -582,15 +504,11 @@ namespace demos { } this.app.start(); - }); - } - } export class Batch { - private app: PIXI.Application; private sprites: PIXI.particles.ParticleContainer; private maggots: Dude[]; @@ -598,7 +516,6 @@ namespace demos { private tick: number; constructor() { - this.app = new PIXI.Application(); document.body.appendChild(this.app.view); @@ -613,13 +530,12 @@ namespace demos { this.maggots = []; - let totalSprites = this.app.renderer instanceof PIXI.WebGLRenderer ? 10000 : 100; + const totalSprites = this.app.renderer instanceof PIXI.WebGLRenderer ? 10000 : 100; - let dudeTexture = PIXI.Texture.fromImage("required/assets/tinyMaggot.png"); + const dudeTexture = PIXI.Texture.fromImage("required/assets/tinyMaggot.png"); for (let i = 0; i < totalSprites; i++) { - - let dude = new Dude(dudeTexture); + const dude = new Dude(dudeTexture); dude.tint = Math.random() * 0xE8D4CD; dude.anchor.set(0.5); dude.scale.set(0.8 + Math.random() * 0.3); @@ -632,10 +548,9 @@ namespace demos { this.maggots.push(dude); this.sprites.addChild(dude); - } - let dudeBoundsPadding = 100; + const dudeBoundsPadding = 100; this.dudeBounds = new PIXI.Rectangle( -dudeBoundsPadding, -dudeBoundsPadding, @@ -646,10 +561,7 @@ namespace demos { this.tick = 0; this.app.ticker.add((): void => { - - for (let i = 0; i < this.maggots.length; i++) { - - let dude = this.maggots[i]; + for (const dude of this.maggots) { dude.scale.y = 0.95 + Math.sin(this.tick + dude.offset) * 0.05; dude.direction += dude.turningSpeed * 0.01; dude.x += Math.sin(dude.direction) * (dude.speed * dude.scale.y); @@ -659,28 +571,22 @@ namespace demos { // wrap the maggots if (dude.x < this.dudeBounds.x) { dude.x += this.dudeBounds.width; - } - else if (dude.x > this.dudeBounds.x + this.dudeBounds.width) { + } else if (dude.x > this.dudeBounds.x + this.dudeBounds.width) { dude.x -= this.dudeBounds.width; } if (dude.y < this.dudeBounds.y) { dude.y += this.dudeBounds.height; - } - else if (dude.y > this.dudeBounds.y + this.dudeBounds.height) { + } else if (dude.y > this.dudeBounds.y + this.dudeBounds.height) { dude.y -= this.dudeBounds.height; } } this.tick += 0.1; - }); - } - } export class Dude extends PIXI.Sprite { - direction: number = 0; speed: number = 0; turningSpeed: number = 0; @@ -689,18 +595,15 @@ namespace demos { constructor(texture: PIXI.Texture) { super(texture); } - } export class BlendModes { - private app: PIXI.Application; private background: PIXI.Sprite; private dudeArray: Dude[]; private dudeBounds: PIXI.Rectangle; constructor() { - this.app = new PIXI.Application(); document.body.appendChild(this.app.view); @@ -709,12 +612,11 @@ namespace demos { this.dudeArray = []; - let totalDudes = 20; - let dudeTexture = PIXI.Texture.fromImage("required/assets/flowerTop.png"); + const totalDudes = 20; + const dudeTexture = PIXI.Texture.fromImage("required/assets/flowerTop.png"); for (let i = 0; i < totalDudes; i++) { - - let dude = new Dude(dudeTexture); + const dude = new Dude(dudeTexture); dude.anchor.set(0.5); dude.scale.set(0.8 + Math.random() * 0.3); dude.x = Math.floor(Math.random() * this.app.renderer.width); @@ -726,10 +628,9 @@ namespace demos { this.dudeArray.push(dude); this.app.stage.addChild(dude); - } - let dudeBoundsPadding = 100; + const dudeBoundsPadding = 100; this.dudeBounds = new PIXI.Rectangle( -dudeBoundsPadding, -dudeBoundsPadding, @@ -738,10 +639,7 @@ namespace demos { ); this.app.ticker.add((): void => { - - for (let i = 0; i < this.dudeArray.length; i++) { - - let dude = this.dudeArray[i]; + for (const dude of this.dudeArray) { dude.direction += dude.turningSpeed * 0.01; dude.x += Math.sin(dude.direction) * dude.speed; dude.y += Math.cos(dude.direction) * dude.speed; @@ -750,34 +648,27 @@ namespace demos { // wrap the dudes by testing their bounds... if (dude.x < this.dudeBounds.x) { dude.x += this.dudeBounds.width; - } - else if (dude.x > this.dudeBounds.x + this.dudeBounds.width) { + } else if (dude.x > this.dudeBounds.x + this.dudeBounds.width) { dude.x -= this.dudeBounds.width; } if (dude.y < this.dudeBounds.y) { dude.y += this.dudeBounds.height; - } - else if (dude.y > this.dudeBounds.y + this.dudeBounds.height) { + } else if (dude.y > this.dudeBounds.y + this.dudeBounds.height) { dude.y -= this.dudeBounds.height; } } - }); - } - } export class CacheAsBitmap { - private app: PIXI.Application; private aliens: PIXI.Sprite[]; private count: number; private alienContainer: PIXI.Container; constructor() { - this.app = new PIXI.Application(); this.app.stage.interactive = true; document.body.appendChild(this.app.view); @@ -785,7 +676,7 @@ namespace demos { this.app.stop(); this.aliens = []; - let alienFrames = [ + const alienFrames = [ "eggHead.png", "flowerTop.png", "helmlok.png", @@ -802,12 +693,10 @@ namespace demos { PIXI.loader .add("spritesheet", "required/assets/monsters.json") .load((): void => { - for (let i = 0; i < 100; i++) { + const frameName = alienFrames[i % 4]; - let frameName = alienFrames[i % 4]; - - let alien = PIXI.Sprite.fromFrame(frameName); + const alien = PIXI.Sprite.fromFrame(frameName); alien.tint = Math.random() * 0xFFFFFF; alien.x = Math.random() * 800 - 400; alien.y = Math.random() * 600 - 300; @@ -822,10 +711,9 @@ namespace demos { this.alienContainer.cacheAsBitmap = !this.alienContainer.cacheAsBitmap; }); this.app.ticker.add((): void => { - // let"s rotate the aliens a little bit for (let i = 0; i < 100; i++) { - let alien = this.aliens[i]; + const alien = this.aliens[i]; alien.rotation += 0.1; } @@ -834,27 +722,21 @@ namespace demos { this.alienContainer.scale.x = Math.sin(this.count); this.alienContainer.scale.y = Math.sin(this.count); this.alienContainer.rotation += 0.01; - }); - }); - } - } export class Dragging { - private app: PIXI.Application; private data: PIXI.interaction.InteractionData; private dragging: boolean; constructor() { - this.app = new PIXI.Application(800, 600, { backgroundColor: 0x1099bb }); document.body.appendChild(this.app.view); - let texture = PIXI.Texture.fromImage("required/assets/bunny.png"); + const texture = PIXI.Texture.fromImage("required/assets/bunny.png"); texture.baseTexture.scaleMode = PIXI.SCALE_MODES.NEAREST; for (let i = 0; i < 10; i++) { @@ -864,71 +746,57 @@ namespace demos { Math.floor(Math.random() * this.app.renderer.height) ); } - } private createBunny(texture: PIXI.Texture, x: number, y: number): void { - - let bunny = new PIXI.Sprite(texture); + const bunny = new PIXI.Sprite(texture); bunny.interactive = true; bunny.buttonMode = true; bunny.anchor.set(0.5); bunny.scale.set(3); bunny .on("pointerdown", (event: PIXI.interaction.InteractionEvent): void => { - this.data = event.data; bunny.alpha = 0.5; this.dragging = true; - }) .on("pointerup", (event: PIXI.interaction.InteractionEvent): void => { - this.data = null; bunny.alpha = 0.5; this.dragging = false; - }) .on("pointerupoutside", (event: PIXI.interaction.InteractionEvent): void => { - this.data = null; bunny.alpha = 0.5; this.dragging = false; - }) .on("pointermove", (event: PIXI.interaction.InteractionEvent): void => { - if (this.dragging) { - let newPosition = this.data.getLocalPosition(bunny); + const newPosition = this.data.getLocalPosition(bunny); bunny.x = newPosition.x; bunny.y = newPosition.y; } - }); bunny.x = x; bunny.y = y; this.app.stage.addChild(bunny); - } - } export class GraphicsDemo { - private app: PIXI.Application; private graphics: PIXI.Graphics; private thing: PIXI.Graphics; private count: number; constructor() { - this.app = new PIXI.Application(800, 600, { antialias: true }); this.app.stage.interactive = true; document.body.appendChild(this.app.view); - let graphics = new PIXI.Graphics(); + const graphics = new PIXI.Graphics(); graphics.beginFill(0xFF3300); graphics.lineStyle(10, 0xffd900, 1); @@ -977,7 +845,6 @@ namespace demos { this.count = 0; this.app.stage.on("pointertap", (): void => { - this.graphics.lineStyle(Math.random() * 30, Math.random() * 0xFFFFFF, 1); this.graphics.moveTo(Math.random() * 800, Math.random() * 600); this.graphics.bezierCurveTo( @@ -985,11 +852,9 @@ namespace demos { Math.random() * 800, Math.random() * 600, Math.random() * 800, Math.random() * 600 ); - }); this.app.ticker.add((): void => { - this.count += 0.1; this.thing.clear(); @@ -1003,25 +868,20 @@ namespace demos { this.thing.lineTo(-120 + Math.sin(this.count) * 20, -100 + Math.cos(this.count) * 20); this.thing.rotation = this.count * 0.1; - }); - } - } export class Interactivity { - private app: PIXI.Application; private background: PIXI.Sprite; private buttons: PIXI.Sprite[]; constructor() { - this.app = new PIXI.Application(); document.body.appendChild(this.app.view); - let background = PIXI.Sprite.fromImage("required/assets/button_test_BG.jpg"); + const background = PIXI.Sprite.fromImage("required/assets/button_test_BG.jpg"); background.width = this.app.renderer.width; background.height = this.app.renderer.height; this.background = background; @@ -1029,7 +889,7 @@ namespace demos { this.buttons = []; - let buttonPositions = [ + const buttonPositions = [ 175, 75, 655, 75, 410, 325, @@ -1037,13 +897,12 @@ namespace demos { 685, 445 ]; - let textureButton = PIXI.Texture.fromImage("../../_assets/button.png"); - let textureButtonDown = PIXI.Texture.fromImage("../../_assets/buttonDown.png"); - let textureButtonOver = PIXI.Texture.fromImage("../../_assets/buttonOver.png"); + const textureButton = PIXI.Texture.fromImage("../../_assets/button.png"); + const textureButtonDown = PIXI.Texture.fromImage("../../_assets/buttonDown.png"); + const textureButtonOver = PIXI.Texture.fromImage("../../_assets/buttonOver.png"); for (let i = 0; i < 5; i++) { - - let button = new PIXI.Sprite(textureButton); + const button = new PIXI.Sprite(textureButton); button.anchor.set(0.5); button.x = buttonPositions[i * 2]; button.y = buttonPositions[i * 2 + 1]; @@ -1076,13 +935,10 @@ namespace demos { this.buttons[3].scale.set(0.8); this.buttons[4].scale.set(0.8, 1.2); this.buttons[4].rotation = Math.PI; - } - } export class Masking { - private app: PIXI.Application; private bg: PIXI.Sprite; private container: PIXI.Container; @@ -1095,7 +951,6 @@ namespace demos { private help: PIXI.Text; constructor() { - this.app = new PIXI.Application(800, 600, { antialias: true }); this.app.stage.interactive = true; document.body.appendChild(this.app.view); @@ -1139,14 +994,12 @@ namespace demos { this.app.stage.on("pointertap", (): void => { if (!this.container.mask) { this.container.mask = this.thing; - } - else { + } else { this.container.mask = null; } }); this.app.ticker.add((): void => { - this.bg.rotation += 0.01; this.bgFront.rotation -= 0.01; @@ -1169,16 +1022,11 @@ namespace demos { this.thing.lineTo(-120 + Math.sin(this.count) * 20, -300 + Math.cos(this.count) * 20); this.thing.lineTo(-320 + Math.sin(this.count) * 20, -100 + Math.cos(this.count) * 20); this.thing.rotation = this.count * 0.1; - }); - } - - } export class RenderTextureDemo { - private app: PIXI.Application; private renderTexture: PIXI.RenderTexture; @@ -1193,7 +1041,6 @@ namespace demos { private count: number; constructor() { - this.app = new PIXI.Application(); document.body.appendChild(this.app.view); @@ -1218,7 +1065,7 @@ namespace demos { this.stuffContainer.y = 300; this.app.stage.addChild(this.stuffContainer); - let fruits = [ + const fruits = [ "required/assets/spinObj_01.png", "required/assets/spinObj_02.png", "required/assets/spinObj_03.png", @@ -1232,7 +1079,7 @@ namespace demos { this.items = []; for (let i = 0; i < 20; i++) { - let item = PIXI.Sprite.fromImage(fruits[i % fruits.length]); + const item = PIXI.Sprite.fromImage(fruits[i % fruits.length]); item.x = Math.random() * 400 - 200; item.y = Math.random() * 400 - 200; item.anchor.set(0.5); @@ -1243,15 +1090,13 @@ namespace demos { this.count = 0; this.app.ticker.add((): void => { - - for (let i = 0; i < this.items.length; i++) { - let item = this.items[i]; + for (const item of this.items) { item.rotation += 0.1; } this.count += 0.01; - let temp = this.renderTexture; + const temp = this.renderTexture; this.renderTexture = this.renderTexture2; this.renderTexture2 = temp; @@ -1261,15 +1106,11 @@ namespace demos { this.outputSprite.scale.set(1 + Math.sin(this.count) * 0.2); this.app.renderer.render(this.app.stage, this.renderTexture2, false); - }); - } - } export class StripDemo { - private app: PIXI.Application; private count: number; private points: PIXI.Point[]; @@ -1277,13 +1118,12 @@ namespace demos { private snakeContainer: PIXI.Container; constructor() { - this.app = new PIXI.Application(); document.body.appendChild(this.app.view); this.count = 0; - let ropeLength = 918 / 20; + const ropeLength = 918 / 20; this.points = []; @@ -1308,13 +1148,10 @@ namespace demos { this.points[i].x = i * ropeLength + Math.cos((i * 0.3) + this.count) * 20; } }); - } - } export class TextDemo { - private app: PIXI.Application; private bitmapFontText: PIXI.extras.BitmapText; private background: PIXI.Sprite; @@ -1324,19 +1161,16 @@ namespace demos { private count: number; constructor() { - this.app = new PIXI.Application(); document.body.appendChild(this.app.view); PIXI.loader .add("desyrel", "required/assets/desyrel.xml") .load((): void => { - this.bitmapFontText = new PIXI.extras.BitmapText("bitmap fonts are\n now supported!", { font: "35px Desyrel", align: "right" }); this.bitmapFontText.x = this.app.renderer.width - this.bitmapFontText.textWidth - 20; this.bitmapFontText.y = 20; this.app.stage.addChild(this.bitmapFontText); - }); this.background = PIXI.Sprite.fromImage("required/assets/textDemoBG.jpg"); @@ -1385,20 +1219,15 @@ namespace demos { this.count = 0; this.app.ticker.add((): void => { - this.count += 0.05; this.countingText.text = "COUNT 4Elet: " + Math.floor(this.count); this.spinningText.rotation += 0.03; - }); - } - } export class TextureRotate { - private app: PIXI.Application; private bol: boolean; private texture: PIXI.Texture; @@ -1406,7 +1235,6 @@ namespace demos { private dude: PIXI.Sprite; constructor() { - this.app = new PIXI.Application(); document.body.appendChild(this.app.view); @@ -1417,20 +1245,18 @@ namespace demos { this.texture = resources.flowerTop.texture; this.init(); }); - } private init(): void { - - let textures = [this.texture]; - let D8 = PIXI.GroupD8; + const textures = [this.texture]; + const D8 = PIXI.GroupD8; for (let rotate = 1; rotate < 16; rotate++) { - let h = D8.isSwapWidthHeight(rotate) ? this.texture.frame.width : this.texture.frame.height; - let w = D8.isSwapWidthHeight(rotate) ? this.texture.frame.height : this.texture.frame.width; + const h = D8.isSwapWidthHeight(rotate) ? this.texture.frame.width : this.texture.frame.height; + const w = D8.isSwapWidthHeight(rotate) ? this.texture.frame.height : this.texture.frame.width; - let frame = this.texture.frame; - let crop = new PIXI.Rectangle(this.texture.frame.x, this.texture.frame.y, w, h); - let trim = crop; + const frame = this.texture.frame; + const crop = new PIXI.Rectangle(this.texture.frame.x, this.texture.frame.y, w, h); + const trim = crop; let rotatedTexture: PIXI.Texture; if (rotate % 2 === 0) { rotatedTexture = new PIXI.Texture(this.texture.baseTexture, frame, crop, trim, rotate); @@ -1441,33 +1267,28 @@ namespace demos { textures.push(rotatedTexture); } - let offsetX = this.app.renderer.width / 16 | 0; - let offsetY = this.app.renderer.height / 8 | 0; - let gridW = this.app.renderer.width / 4 | 0; - let gridH = this.app.renderer.height / 5 | 0; + const offsetX = this.app.renderer.width / 16 | 0; + const offsetY = this.app.renderer.height / 8 | 0; + const gridW = this.app.renderer.width / 4 | 0; + const gridH = this.app.renderer.height / 5 | 0; for (let i = 0; i < 16; i++) { - - let dude = new PIXI.Sprite(textures[i < 8 ? i * 2 : (i - 8) * 2 + 1]); + const dude = new PIXI.Sprite(textures[i < 8 ? i * 2 : (i - 8) * 2 + 1]); dude.scale.x = 0.5; dude.scale.y = 0.5; dude.x = offsetX + gridW * (i % 4); dude.y = offsetY + gridH * (i / 4 | 0); this.app.stage.addChild(dude); - let text = new PIXI.Text("rotate = " + dude.texture.rotate, { fontFamily: "Courier New", fontSize: "12px", fill: "white", align: "left" }); + const text = new PIXI.Text("rotate = " + dude.texture.rotate, { fontFamily: "Courier New", fontSize: "12px", fill: "white", align: "left" }); text.x = dude.x; text.y = dude.y - 20; this.app.stage.addChild(text); - } - } - } export class TextureSwap { - private app: PIXI.Application; private bol: boolean; private texture: PIXI.Texture; @@ -1475,7 +1296,6 @@ namespace demos { private dude: PIXI.Sprite; constructor() { - this.app = new PIXI.Application(); document.body.appendChild(this.app.view); @@ -1497,8 +1317,7 @@ namespace demos { this.bol = !this.bol; if (this.bol) { this.dude.texture = this.secondTexture; - } - else { + } else { this.dude.texture = this.texture; } }); @@ -1506,30 +1325,25 @@ namespace demos { this.app.ticker.add((): void => { this.dude.rotation += 0.1; }); - } - } export class Tinting { - private app: PIXI.Application; private aliens: Dude[]; constructor() { - this.app = new PIXI.Application(); document.body.appendChild(this.app.view); this.aliens = []; - let totalDudes = 20; + const totalDudes = 20; - let dudeTexture = PIXI.Texture.fromImage("required/assets/eggHead.png"); + const dudeTexture = PIXI.Texture.fromImage("required/assets/eggHead.png"); for (let i = 0; i < totalDudes; i++) { - - let dude = new Dude(dudeTexture); + const dude = new Dude(dudeTexture); dude.anchor.set(0.5); dude.scale.set(0.8 + Math.random() * 0.3); dude.x = Math.random() * this.app.renderer.width; @@ -1541,20 +1355,16 @@ namespace demos { this.aliens.push(dude); this.app.stage.addChild(dude); - } - let dudeBoundsPadding = 100; - let dudeBounds = new PIXI.Rectangle(-dudeBoundsPadding, + const dudeBoundsPadding = 100; + const dudeBounds = new PIXI.Rectangle(-dudeBoundsPadding, -dudeBoundsPadding, this.app.renderer.width + dudeBoundsPadding * 2, this.app.renderer.height + dudeBoundsPadding * 2); this.app.ticker.add((): void => { - - for (let i = 0; i < this.aliens.length; i++) { - - let dude = this.aliens[i]; + for (const dude of this.aliens) { dude.direction += dude.turningSpeed * 0.01; dude.x += Math.sin(dude.direction) * dude.speed; dude.y += Math.cos(dude.direction) * dude.speed; @@ -1562,31 +1372,25 @@ namespace demos { if (dude.x < dudeBounds.x) { dude.x += dudeBounds.width; - } - else if (dude.x > dudeBounds.x + dudeBounds.width) { + } else if (dude.x > dudeBounds.x + dudeBounds.width) { dude.x -= dudeBounds.width; } if (dude.y < dudeBounds.y) { dude.y += dudeBounds.height; - } - else if (dude.y > dudeBounds.y + dudeBounds.height) { + } else if (dude.y > dudeBounds.y + dudeBounds.height) { dude.y -= dudeBounds.height; } } - }); } - } export class TransparentBackground { - private app: PIXI.Application; private bunny: PIXI.Sprite; constructor() { - this.app = new PIXI.Application(800, 600, { transparent: true }); document.body.appendChild(this.app.view); @@ -1602,17 +1406,12 @@ namespace demos { this.app.ticker.add((): void => { this.bunny.rotation += 0.1; }); - } - } - } namespace filters { - export class BlurFilter { - private app: PIXI.Application; private bg: PIXI.Sprite; private littleDudes: PIXI.Sprite; @@ -1622,7 +1421,6 @@ namespace filters { private count: number; constructor() { - this.app = new PIXI.Application(800, 600); document.body.appendChild(this.app.view); @@ -1650,23 +1448,18 @@ namespace filters { this.count = 0; this.app.ticker.add((): void => { - this.count += 0.005; - let blurAmount = Math.cos(this.count); - let blurAmount2 = Math.sin(this.count); + const blurAmount = Math.cos(this.count); + const blurAmount2 = Math.sin(this.count); this.blurFilter1.blur = 20 * (blurAmount); this.blurFilter2.blur = 20 * (blurAmount2); - }); - } - } export class DisplacementMap { - private app: PIXI.Application; private container: PIXI.Container; private maggots: DisplacementMapDude[]; @@ -1677,7 +1470,6 @@ namespace filters { private count: number; constructor() { - this.app = new PIXI.Application(800, 600); this.app.stage.interactive = true; document.body.appendChild(this.app.view); @@ -1685,8 +1477,8 @@ namespace filters { this.container = new PIXI.Container(); this.app.stage.addChild(this.container); - let padding = 100; - let bounds = new PIXI.Rectangle( + const padding = 100; + const bounds = new PIXI.Rectangle( -padding, -padding, this.app.renderer.width + padding * 2, @@ -1695,8 +1487,7 @@ namespace filters { this.maggots = []; for (let i = 0; i < 20; i++) { - - let maggot = new DisplacementMapDude(); + const maggot = new DisplacementMapDude(); maggot.anchor.set(0.5); this.container.addChild(maggot); @@ -1710,11 +1501,10 @@ namespace filters { maggot.scale.set(1 + Math.random() * 0.3); maggot.original = maggot.scale.clone(); this.maggots.push(maggot); - } this.displacementSprite = PIXI.Sprite.fromImage("required/assets/displace.png"); - let displacementFilter = new PIXI.filters.DisplacementFilter(this.displacementSprite); + const displacementFilter = new PIXI.filters.DisplacementFilter(this.displacementSprite); this.app.stage.addChild(this.displacementSprite); this.container.filters = [displacementFilter]; @@ -1740,13 +1530,9 @@ namespace filters { .on("touchmove", this.onPointerMove); this.app.ticker.add((): void => { - this.count += 0.05; - for (let i = 0; i < this.maggots.length; i++) { - - let maggot = this.maggots[i]; - + for (const maggot of this.maggots) { maggot.direction += maggot.turnSpeed * 0.01; maggot.x += Math.sin(maggot.direction) * maggot.speed; maggot.y += Math.cos(maggot.direction) * maggot.speed; @@ -1756,51 +1542,39 @@ namespace filters { if (maggot.x < bounds.x) { maggot.x += bounds.width; - } - else if (maggot.x > bounds.x + bounds.width) { + } else if (maggot.x > bounds.x + bounds.width) { maggot.x -= bounds.width; } if (maggot.y < bounds.y) { maggot.y += bounds.height; - } - else if (maggot.y > bounds.y + bounds.height) { + } else if (maggot.y > bounds.y + bounds.height) { maggot.y -= bounds.height; } } - }); - } private onPointerMove = (eventData: PIXI.interaction.InteractionEvent): void => { - this.ring.visible = true; this.displacementSprite.x = eventData.data.global.x - 100; this.displacementSprite.y = eventData.data.global.y - this.displacementSprite.height / 2; this.ring.x = eventData.data.global.x - 25; this.ring.y = eventData.data.global.y; - } - } export class DisplacementMapDude extends PIXI.Sprite { - direction: number = 0; speed: number = 0; turnSpeed: number = 0; original: PIXI.Point = new PIXI.Point(); constructor() { - super(PIXI.Texture.fromImage("../../_assets/maggot.png")); - } - } export class Filter { - private app: PIXI.Application; private bg: PIXI.Sprite; private filter: PIXI.filters.ColorMatrixFilter; @@ -1814,7 +1588,6 @@ namespace filters { private help: PIXI.Text; constructor() { - this.app = new PIXI.Application(); this.app.stage.interactive = true; document.body.appendChild(this.app.view); @@ -1868,7 +1641,6 @@ namespace filters { this.app.stage.addChild(this.help); this.app.ticker.add((delta: number): void => { - this.bg.rotation += 0.01; this.bgFront.rotation -= 0.01; this.light1.rotation += 0.02; @@ -1879,7 +1651,7 @@ namespace filters { this.count += 0.1; - let matrix = this.filter.matrix; + const matrix = this.filter.matrix; matrix[1] = Math.sin(this.count) * 3; matrix[2] = Math.cos(this.count); @@ -1887,11 +1659,7 @@ namespace filters { matrix[4] = Math.sin(this.count / 3) * 2; matrix[5] = Math.sin(this.count / 2); matrix[6] = Math.sin(this.count / 4); - }); - } - } - -} \ No newline at end of file +} diff --git a/types/pixi.js/tslint.json b/types/pixi.js/tslint.json index 1c78047f30..6fa0ddab84 100644 --- a/types/pixi.js/tslint.json +++ b/types/pixi.js/tslint.json @@ -1,98 +1,13 @@ { - "jsRules": { - "class-name": true, - "comment-format": [ - true, - "check-space" - ], - "indent": [ - true, - "spaces" - ], - "no-duplicate-variable": true, - "no-eval": true, - "no-trailing-whitespace": true, - "no-unsafe-finally": true, - "one-line": [ - true, - "check-open-brace", - "check-whitespace" - ], - "quotemark": [ - true, - "double" - ], - "semicolon": [ - true, - "always" - ], - "triple-equals": [ - true, - "allow-null-check" - ], - "variable-name": [ - true, - "ban-keywords" - ], - "whitespace": [ - true, - "check-branch", - "check-decl", - "check-operator", - "check-separator", - "check-type" - ] - }, + "extends": "../tslint.json", "rules": { + "forbidden-types": false, + "interface-name": false, + "no-single-declare-module": false, + "unified-signatures": false, + "class-name": true, - "comment-format": [ - true, - "check-space" - ], - "indent": [ - true, - "spaces" - ], - "no-eval": true, - "no-internal-module": true, - "no-trailing-whitespace": true, - "no-unsafe-finally": true, - "no-var-keyword": true, - "one-line": [ - true, - "check-open-brace", - "check-whitespace" - ], - "quotemark": [ - true, - "double" - ], - "semicolon": [ - true, - "always" - ], - "triple-equals": [ - true, - "allow-null-check" - ], - "typedef-whitespace": [ - true, - { - "call-signature": "nospace", - "index-signature": "nospace", - "parameter": "nospace", - "property-declaration": "nospace", - "variable-declaration": "nospace" - } - ], - "variable-name": false, - "whitespace": [ - true, - "check-branch", - "check-decl", - "check-operator", - "check-separator", - "check-type" - ] + "indent": [true, "spaces"], + "quotemark": [true, "double"] } } \ No newline at end of file