angelozerr / tern-phaser

A Tern plugin for Phaser
http://phaser.io/
12 stars 6 forks source link

Completion for image #3

Open angelozerr opened 9 years ago

angelozerr commented 9 years ago

In the sample http://phaser.io/examples/v2/animation/animation-events:

game.load.image('lazur', 'assets/pics/thorn_lazur.png');
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);

It should be cool to have completion for image like:

game.load.image('lazur', 'as // Here Ctrl+Space show a list of image

@boniatillo-com is there other methods which uses images?

PhaserEditor2D commented 9 years ago

yes, there is also atlas, tilemap, etc... take a look to the Phaser.Loader methods. In phaser you load images but also audio, json files, xml files, font files, etc... but I guess it is out of the scope of tern.

angelozerr commented 9 years ago

but I guess it is out of the scope of tern.

Why?

You could have completion for those kind files too, no?

PhaserEditor2D commented 9 years ago

Well, I said it because I thought that compute the set of paths is a concern of the client implementation. For example, the file path can be relative to the index.html of the project (but only the client -editor- knows how the project structure is). But well, the reality is that I know very little about tern :)

angelozerr commented 9 years ago

I had done that for Angular templateUrl https://github.com/angelozerr/angularjs-eclipse/wiki/New-and-Noteworthy-1.0.0#templateurl and it works too for any edito (except Web Browser)r:)

The basic idea is to configure a base url. The tern plugin uses this base url and use node.js to loop for files.

PhaserEditor2D commented 9 years ago

Perfect!

PhaserEditor2D commented 9 years ago

Just to understand it better, I guess that in the tern spec there is a way to say that a var is a string with a filename of extension .png, .jpg... Is it?

angelozerr commented 9 years ago

I guess that in the tern spec there is a way to say that a var is a string with a filename of extension .png, .jpg... Is it?

It's a little complex than that. tern gives you the capability to override "standard" completion, find type at. The basic idea is to override tern completion, check if completion is thrown inside game.load.image("", " completion is executed here) and after you compute the result of completion (in this case you use node.js to loop for a lis of files and you filter it with JS)

Tern gives you too the capability in the JSON Type Definition to call a custom tern function which is usefull to create custom type. For instance for node require function must returns a custom type according the given string:

var f = require("fs")
// here f has JavaScript file system type.

See https://github.com/marijnh/tern/blob/master/plugin/commonjs.js#L84

In other words, you can manage anything with tern. I have for instance managed completion for HTML elements ids for query selector (document.querySelector). See https://github.com/angelozerr/tern-browser-extension

PhaserEditor2D commented 9 years ago

Very good.