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
37.16k stars 7.1k forks source link

type issue of registering postFxPipeline #6854

Closed rexrainbow closed 2 months ago

rexrainbow commented 4 months 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 4 months 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 4 months ago

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

photonstorm commented 2 months ago

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.