Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
Prozi committed Nov 6, 2024
1 parent a8449fe commit 3904680
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
20 changes: 12 additions & 8 deletions dist/stats-gl.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Texture, WebGLRenderer } from 'pixi.js';
import { type Texture, type WebGLRenderer } from 'pixi.js';
import BaseHooks from './hooks/BaseHooks';
import { Panel } from './stats-panel';
import { Stats } from './stats';
export { Texture, WebGLRenderer };
export type PIXIGlTextureSystem = {
_glTextures: Record<string, {
gl: WebGLRenderingContext;
texture: Texture;
}>;
};
export { type Texture, type WebGLRenderer };
export interface PIXIGlTexture {
gl: WebGLRenderingContext;
texture: Texture;
}
export type PIXIGlTextureArray = PIXIGlTexture[];
export type PIXIGlTextureRecord = Record<string, PIXIGlTexture>;
export interface PIXIRendererGlTexture {
managedTextures?: PIXIGlTextureArray;
_glTextures?: PIXIGlTextureRecord;
}
export declare class StatsJSAdapter {
hook: PIXIHooks;
stats: Stats;
Expand Down
2 changes: 1 addition & 1 deletion dist/stats-gl.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions dist/stats-gl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/stats-gl.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pixi-stats",
"version": "3.1.0",
"version": "3.1.1",
"description": "a 2024 version of stats.js + gstats",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
31 changes: 21 additions & 10 deletions src/stats-gl.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { Texture, WebGLRenderer } from 'pixi.js';
import { type Texture, type WebGLRenderer } from 'pixi.js';

import BaseHooks from './hooks/BaseHooks';
import { Panel } from './stats-panel';
import { Stats } from './stats';

export { Texture, WebGLRenderer };
export { type Texture, type WebGLRenderer };

export interface PIXIGlTexture {
gl: WebGLRenderingContext;
texture: Texture;
}

export type PIXIGlTextureArray = PIXIGlTexture[];

export type PIXIGlTextureSystem = {
_glTextures: Record<string, { gl: WebGLRenderingContext; texture: Texture }>;
};
export type PIXIGlTextureRecord = Record<string, PIXIGlTexture>;

export interface PIXIRendererGlTexture {
// pixi v6
managedTextures?: PIXIGlTextureArray;
// pixi v8
_glTextures?: PIXIGlTextureRecord;
}

export class StatsJSAdapter {
hook: PIXIHooks;
Expand Down Expand Up @@ -72,14 +82,15 @@ export class PIXIHooks extends BaseHooks {
if (renderer.gl) {
this.attach(renderer.gl);

const texture = renderer.texture as unknown as PIXIRendererGlTexture;

// pixi v6 compatibility
const glTextures = ((renderer.texture as any)._glTextures ||
renderer.texture.managedTextures) as unknown as PIXIGlTextureSystem;
const glTextures = texture._glTextures || texture.managedTextures;

// pixi v6 compatibility
const glTexturesArray = Array.isArray(glTextures)
? glTextures
: Object.values(glTextures);
: Object.values(glTextures as PIXIGlTextureRecord);

if (!glTexturesArray || !this.texturehook) {
console.error('[PIXI Hooks] !glTextures || !this.texturehook');
Expand Down

0 comments on commit 3904680

Please sign in to comment.