Giter Site home page Giter Site logo

phaser-list-view-typings's Introduction

Phaser List View Typings

TypeScript typings file for mattcolman/phaser-list-view plugin.

Installation

To install with Typings (recommended):

typings install phaser-list-view=github:drewsilcock/phaser-list-view-plugin/index.d.ts#{COMMIT HASH HERE} --global --save

Replace {COMMIT HASH HERE} with the commit of the Typings file you want to use. By doing this, you "pin" down your Typings so that if (or when) I update this index.d.ts file, your Typings won't change and mess your code up without your intervention.

Usage

I am currently using a bit of a nasty hack to get this actually working in TypeScript, which is the following:

declare global {
    interface Window {
        PhaserListView: {
            DirectionalScroller: DirectionalScrollerWrapper,
            ListView: ListViewWrapper,
            Scroller: ScrollerWrapper,
            SwipeCarousel: SwipeCarouselWrapper,
            WheelScroller: WheelScrollerWrapper,
        };
    }
}

export interface DirectionalScrollerWrapper {
    new (): DirectionalScroller;
}

export interface ListViewWrapper {
    new (game: Phaser.Game, parent: PIXI.DisplayObject,
         bounds: Phaser.Rectangle, options: ListViewOptions): ListView;
}

export interface ScrollerWrapper {
    new (game: Phaser.Game, clickObject: any,
         maskLimits: any, options: ScrollerOptions): Scroller;
}

export interface SwipeCarouselWrapper {
    new (game: Phaser.Game, parent: PIXI.DisplayObject,
         bounds: Phaser.Rectangle, options: SwipeCarouselOptions): SwipeCarousel;
}

export interface WheelScrollerWrapper {
    new (game: Phaser.Game, clickObject: PIXI.DisplayObject,
         options: WheelScrollerOptions): WheelScroller;
}

This is then used in a TypeScript file as follows:

// Utilises ES6-style object destructured assignment.
const {
    DirectionalScroller,
    ListView,
    Scroller,
    SwipeCarousel,
    WheelScroller,
} = window.PhaserListView; // If you don't need any of these, you can just leave them out of the `const { ... }`.

...

const listView = new ListView(game, parent, bounds, options);

If anyone has a nicer way of doing this, I'd very much like to hear it! Just open an issue.

phaser-list-view-typings's People

Stargazers

 avatar

Watchers

 avatar

Forkers

devshengyu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.