ShaderParticleEngine icon indicating copy to clipboard operation
ShaderParticleEngine copied to clipboard

typescript definition

Open jppresents opened this issue 10 years ago • 8 comments

hi,

I am using typescript to create my game. (Typescript compiles down to javascript and can use typescript definitions to use pure javascript libs such as three.js or the ShaderParticleEngine.)

For three.js there is a definition available at definitelyTyped on github (they gather definitions for libs that don't provide them themself).

I made a minimal ShaderParticle.d.ts definition file, which enables use of groups and emitters in typescript.

It's only a few lines, would you be interested to host it in this project?

(It's ok if you are not, I'll then look into getting it into definitelyTyped - but I have not yet looked into their policies regarding size of projects or how to get definitions there.)

If you would just like to include it, here is the file: http://jppresents.net/static/files/ShaderParticles.d.ts

jppresents avatar Jan 31 '15 13:01 jppresents

I think it's a good idea, and one that would sit well with a pull-req I got a while back (IIRC) about adding package support (AMD/require/browserify-kinda stuff).

Could you link me to the definitelyTyped entry for Three.js?

squarefeet avatar Jan 31 '15 13:01 squarefeet

Sure, here it is: https://github.com/borisyankov/DefinitelyTyped/tree/master/threejs

jppresents avatar Jan 31 '15 13:01 jppresents

Nice one, cheers. I'll take a peek.

squarefeet avatar Jan 31 '15 13:01 squarefeet

Ha, that's so foreign to me. If you're up for making a draft version of a definition for this lib, that would be super handy. I've not used TypeScript very much at all, so I'd be best deferring to you with regards to that.

squarefeet avatar Jan 31 '15 13:01 squarefeet

The linked file above (http://jppresents.net/static/files/ShaderParticles.d.ts) is actually enough to get up and running with your lib in typescript.

This way typescript knows which classes ShaderParticles offers and what their functions and datatypes are.

Typescript to create group / emitter with this definition looks like this:

    this.particles= new SPE.Group({
        texture: THREE.ImageUtils.loadTexture('models/particle.png'),
        maxAge: 0.5
    });

    this.emitter = new SPE.Emitter({
        type: 'cube'
        ...
    });

I am not sure if or how browserify/require use typescript definitions.

To clarify: I think if you put the linked ShaderParticles.d.ts file into the repository then typescript-people can directly start using the lib, no more work required by you or me.

jppresents avatar Jan 31 '15 14:01 jppresents

Okay, just noticed when continuing with my game: all the properties of emitters (and possible groups) will need to be defined in the definition too. (Just listed with their correct types.)

All the ones, that you are supposed to be able to change after the creation of the emitter. (So they can be accessed on the emitter object in typescript.)

If you tell me where in the repo the file is supposed to go, I will submit a pull request when I got it done. Phaser (another lib I like to use) has them simply in a directory called typescript. (Linked as an example: https://github.com/photonstorm/phaser/tree/master/typescript )

jppresents avatar Jan 31 '15 14:01 jppresents

I'm so glad you're doing this - I'd be lost in documentation right about now ;)

A new subfolder on master's root would be great... thanks again for doing this.

squarefeet avatar Jan 31 '15 14:01 squarefeet

The link above for the typescript file (http://jppresents.net/static/files/ShaderParticles.d.ts) doesnt work any more, any chance you've got it around any more and can submit a pull request?

Thanks.

zynga-jpetersen avatar Oct 06 '17 21:10 zynga-jpetersen