phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.88k stars 7.08k forks source link

type issue of registering postFxPipeline #6854

Open rexrainbow opened 1 month ago

rexrainbow commented 1 month ago

Version

Description

Test code registers a post fx pipeline in game config.

import 'phaser';

class TestPostFX extends Phaser.Renderer.WebGL.Pipelines.PostFXPipeline {
}

class Demo extends Phaser.Scene {
    constructor() {
        super({
            key: 'examples'
        })
    }
}

var config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    width: 800,
    height: 600,
    scene: Demo,
    pipeline: { TestPostFX }
};

var game = new Phaser.Game(config);

Typescript report a type bug :

Argument of type '{ type: number; parent: string; width: number; height: number; scene: typeof Demo; pipeline: { TestPostFX: typeof TestPostFX; }; }' is not assignable to parameter of type 'GameConfig'.
  Types of property 'pipeline' are incompatible.
    Type '{ TestPostFX: typeof TestPostFX; }' is missing the following properties from type 'PipelineConfig': name, pipelinets(2345)

It seems that there has type incompatible in game config's pipeline parameter.

zekeatchan commented 1 month ago

Hi @rexrainbow.

Instead of: pipeline: { TestPostFX }

Try this: pipeline: TestPostFX

The pipeline property requires either:

  1. Phaser.Types.Core.PipelineConfig object that requires these properties:

    • a name {string}
    • a pipeline {Phaser.Renderer.WebGL.WebGLPipeline}

    or:

  2. a Phaser.Renderer.WebGL.WebGLPipeline class.

With pipeline: { TestPostFX } it assumes you are passing an object to the pipeline property and not a Phaser.Renderer.WebGL.WebGLPipeline type as what is intended.

Let me know if that helps.

rexrainbow commented 1 month ago

That pipeline parameter could register multiple WebGLPipeline classes, so that it might be a list or a dictionary.